Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
-
from fastapi import FastAPI, UploadFile, File
|
| 3 |
-
import tempfile
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
"
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from speech_to_text import SpeechToText
|
| 3 |
+
from sentiment_analysis import SentimentAnalyzer
|
| 4 |
import os
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# Initialize models
|
| 7 |
+
stt = SpeechToText()
|
| 8 |
+
sentiment_analyzer = SentimentAnalyzer()
|
| 9 |
+
|
| 10 |
+
def process_audio(audio_path):
|
| 11 |
+
try:
|
| 12 |
+
# Get transcription
|
| 13 |
+
transcription = stt.transcribe(audio_path)
|
| 14 |
+
|
| 15 |
+
# Analyze sentiment
|
| 16 |
+
sentiment = sentiment_analyzer.analyze(transcription)
|
| 17 |
+
|
| 18 |
+
return {
|
| 19 |
+
"transcription": transcription,
|
| 20 |
+
"sentiment": sentiment
|
| 21 |
+
}
|
| 22 |
+
except Exception as e:
|
| 23 |
+
return {
|
| 24 |
+
"transcription": f"Error: {str(e)}",
|
| 25 |
+
"sentiment": [{"label": "ERROR", "score": 0.0}]
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
# Create Gradio interface
|
| 29 |
+
def create_interface():
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
gr.Markdown("# Voice Intelligence Demo")
|
| 32 |
+
|
| 33 |
+
with gr.Row():
|
| 34 |
+
audio_input = gr.Audio(source="microphone", type="filepath")
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
transcription_output = gr.Textbox(label="Transcription")
|
| 38 |
+
sentiment_output = gr.JSON(label="Sentiment Analysis")
|
| 39 |
+
|
| 40 |
+
audio_input.change(
|
| 41 |
+
fn=process_audio,
|
| 42 |
+
inputs=[audio_input],
|
| 43 |
+
outputs=[transcription_output, sentiment_output]
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
return demo
|
| 47 |
+
|
| 48 |
+
# Launch the app
|
| 49 |
+
if __name__ == "__main__":
|
| 50 |
+
demo = create_interface()
|
| 51 |
+
demo.launch()
|