Spaces:
Runtime error
Runtime error
from flask import Flask, render_template, jsonify | |
app = Flask(__name__) | |
# Replace with your AssemblyAI API key | |
ASSEMBLYAI_API_KEY = "67883cd71f0d4a58a27a34e058f0d924" | |
# URL of the file to transcribe | |
FILE_URL = "/content/call.mp3" | |
# You can also transcribe a local file by passing in a file path | |
# FILE_URL = './path/to/file.mp3' | |
def analyze(): | |
# Transcribe audio to text | |
transcriber = aai.Transcriber(api_key=ASSEMBLYAI_API_KEY) | |
transcript = transcriber.transcribe(FILE_URL) | |
text = transcript.text | |
# Perform sentiment analysis | |
sentiment_analyzer = pipeline("sentiment-analysis") | |
sentiment = sentiment_analyzer(text) | |
# Perform emotion analysis | |
emotion_analyzer = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", return_all_scores=True) | |
emotions = emotion_analyzer(text) | |
# Format results | |
result = { | |
"transcript": text, | |
"sentiment": { | |
"score": sentiment[0]['score'], | |
"label": sentiment[0]['label'] | |
}, | |
"emotion": [{ | |
"label": emotion['label'], | |
"score": emotion['score'] | |
} for emotion in emotions[0]] | |
} | |
return render_template('analyze.html', result=result) | |
if __name__ == '__main__': | |
app.run(debug=True) | |