GPU-powered emotion and sentiment analysis service for conversation insights.
- Emotion Detection: 7 emotion categories using j-hartmann/emotion-english-distilroberta-base
- Sentiment Analysis: Positive/negative/neutral using cardiffnlp/twitter-roberta-base-sentiment-latest
- GPU Acceleration: Optimized for NVIDIA L4 GPUs on Cloud Run
- Batch Processing: Efficient batch inference for conversation-level analysis
- Valence/Arousal: Dimensional emotion representation
- Framework: FastAPI
- ML Backend: HuggingFace Transformers + PyTorch
- Deployment: Google Cloud Run with GPU support (us-central1)
- Authentication: API key-based
Analyze a conversation for emotions and sentiment.
Request:
{
"conversation_id": 123,
"messages": [
{"content": "Hello, nice to meet you!"},
{"content": "Great to connect with you too!"}
]
}Response:
{
"conversation_id": 123,
"analysis": {
"emotion": {
"dominant_emotion": "joy",
"emotion_confidence": 0.85,
"emotion_distribution": {...},
"average_valence": 0.7,
"average_arousal": 0.6
},
"sentiment": {
"sentiment_polarity": "positive",
"sentiment_score": 0.75
},
"quality": {
"conversation_quality_score": 0.82,
"engagement_level": "high"
}
},
"status": "success"
}Health check with GPU status.
Warmup endpoint to preload models.
# Install dependencies
pip install -r requirements.txt
# Run locally (CPU mode)
uvicorn app.main:app --reload --port 8000Deploy to Cloud Run with GPU:
# Build and push image
gcloud builds submit --tag us-central1-docker.pkg.dev/PROJECT_ID/semantic-analysis/service:latest
# Deploy with GPU
gcloud run deploy semantic-analysis-service \
--image us-central1-docker.pkg.dev/PROJECT_ID/semantic-analysis/service:latest \
--platform managed \
--region us-central1 \
--gpu 1 \
--gpu-type nvidia-l4 \
--memory 8Gi \
--cpu 4 \
--max-instances 3 \
--min-instances 1 \
--timeout 60 \
--set-env-vars API_KEY=your-api-key- Inference Time: 50-100ms per conversation (GPU)
- Batch Size: 16 messages per batch
- GPU Memory: ~2-3 GB with models loaded
- Cold Start: ~30-45 seconds (model loading)
-
Emotion: j-hartmann/emotion-english-distilroberta-base
- 7 emotions: anger, disgust, fear, joy, neutral, sadness, surprise
-
Sentiment: cardiffnlp/twitter-roberta-base-sentiment-latest
- 3 classes: positive, neutral, negative