Spaces:
Runtime error
Runtime error
File size: 1,362 Bytes
159db2c e33dc1a 2cf8dcb 159db2c 2cf8dcb e33dc1a 2cf8dcb e33dc1a 2cf8dcb e33dc1a 2cf8dcb |
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
import torch
# Load Whisper model and tokenizer
whisper_model = "openai/whisper-base"
device = "cuda" if torch.cuda.is_available() else "cpu"
asr = pipeline("automatic-speech-recognition", model=whisper_model, device=device)
# Load Sentiment Analysis model
sentiment_model = "cardiffnlp/twitter-roberta-base-sentiment-latest"
sentiment_analyzer = pipeline("sentiment-analysis", model=sentiment_model, device=device)
def transcribe_and_analyze(audio):
# Transcribe audio to text
transcription = asr(audio)["text"]
# Analyze sentiment of the transcription
sentiment = sentiment_analyzer(transcription)[0]
return transcription, sentiment["label"], sentiment["score"]
# Define Gradio interface
interface = gr.Interface(
fn=transcribe_and_analyze,
inputs=gr.Audio(sources=["microphone", "upload"], type="filepath", label="Upload or Record Audio"), # Added upload option
outputs=[
gr.Textbox(label="Transcription"),
gr.Textbox(label="Sentiment"),
gr.Number(label="Confidence Score")
],
title="Real-Time Audio Transcription and Sentiment Analysis - Sumit",
description="This application transcribes audio input and analyzes the sentiment of the transcribed text.",
live=True
)
if __name__ == "__main__":
interface.launch()
|