Spaces:
Running
Running
File size: 1,224 Bytes
00ae0ce |
1 2 3 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 33 34 35 36 37 38 39 |
import gradio as gr
from transformers import pipeline
# Load Whisper for speech-to-text
whisper = pipeline("automatic-speech-recognition", model="openai/whisper-medium")
# Load DistilBERT for sentiment analysis
sentiment_analyzer = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
# Function to process audio and analyze tone
def analyze_call(audio_file):
# Step 1: Transcribe audio to text
transcription = whisper(audio_file)["text"]
# Step 2: Analyze sentiment of the transcription
sentiment_result = sentiment_analyzer(transcription)[0]
return {
"transcription": transcription,
"sentiment": sentiment_result["label"],
"confidence": sentiment_result["score"]
}
# Gradio Interface
interface = gr.Interface(
fn=analyze_call,
inputs=gr.Audio(source="microphone", type="filepath"),
outputs=[
gr.Textbox(label="Transcription"),
gr.Textbox(label="Sentiment"),
gr.Textbox(label="Confidence")
],
live=True, # Enable real-time processing
title="Real-Time Call Analysis",
description="Upload or record audio to analyze tone and sentiment."
)
# Launch the app
interface.launch() |