Boltz79's picture
Create app.py
00ae0ce verified
raw
history blame
1.22 kB
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()