Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load Whisper for speech-to-text
|
| 5 |
+
whisper = pipeline("automatic-speech-recognition", model="openai/whisper-medium")
|
| 6 |
+
|
| 7 |
+
# Load DistilBERT for sentiment analysis
|
| 8 |
+
sentiment_analyzer = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 9 |
+
|
| 10 |
+
# Function to process audio and analyze tone
|
| 11 |
+
def analyze_call(audio_file):
|
| 12 |
+
# Step 1: Transcribe audio to text
|
| 13 |
+
transcription = whisper(audio_file)["text"]
|
| 14 |
+
|
| 15 |
+
# Step 2: Analyze sentiment of the transcription
|
| 16 |
+
sentiment_result = sentiment_analyzer(transcription)[0]
|
| 17 |
+
|
| 18 |
+
return {
|
| 19 |
+
"transcription": transcription,
|
| 20 |
+
"sentiment": sentiment_result["label"],
|
| 21 |
+
"confidence": sentiment_result["score"]
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
# Gradio Interface
|
| 25 |
+
interface = gr.Interface(
|
| 26 |
+
fn=analyze_call,
|
| 27 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
| 28 |
+
outputs=[
|
| 29 |
+
gr.Textbox(label="Transcription"),
|
| 30 |
+
gr.Textbox(label="Sentiment"),
|
| 31 |
+
gr.Textbox(label="Confidence")
|
| 32 |
+
],
|
| 33 |
+
live=True, # Enable real-time processing
|
| 34 |
+
title="Real-Time Call Analysis",
|
| 35 |
+
description="Upload or record audio to analyze tone and sentiment."
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
# Launch the app
|
| 39 |
+
interface.launch()
|