Mark0047 commited on
Commit
2327692
·
verified ·
1 Parent(s): d989938

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the Hugging Face model
5
+ emotion_classifier = pipeline("text-classification", model="SamLowe/roberta-base-go_emotions", return_all_scores=True)
6
+
7
+ # Define a function to process the transcribed text with the emotion model
8
+ def transcribe_and_analyze(audio):
9
+ # Load Whisper for transcription
10
+ whisper = gr.load("models/openai/whisper-large-v3-turbo")
11
+ transcription = whisper(audio) # Transcribe audio
12
+ # Analyze emotions in the transcribed text
13
+ emotions = emotion_classifier(transcription["text"])
14
+ return transcription["text"], emotions
15
+
16
+ # Create Gradio interface
17
+ interface = gr.Interface(
18
+ fn=transcribe_and_analyze,
19
+ inputs=gr.Audio(source="microphone", type="filepath"), # Accept audio input
20
+ outputs=[
21
+ gr.Textbox(label="Transcription"), # Show the transcription
22
+ gr.JSON(label="Emotion Analysis") # Show the emotion analysis
23
+ ],
24
+ title="Audio to Emotion Analysis"
25
+ )
26
+
27
+ # Launch the Gradio app
28
+ interface.launch()