Mendoza33 commited on
Commit
9a81fc4
·
verified ·
1 Parent(s): 0b69947

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Load pre-trained models
5
+ stt_model = pipeline("automatic-speech-recognition", model="openai/whisper-base")
6
+ nlp_model = pipeline("text-generation", model="gpt2")
7
+ tts_model = pipeline("text-to-speech", model="tts-coqui/coqui-tts-en")
8
+
9
+ # Define a function to handle the workflow
10
+ def conversation(audio):
11
+ # Step 1: Convert speech to text
12
+ text = stt_model(audio)["text"]
13
+ # Step 2: Generate a response
14
+ response = nlp_model(text, max_length=50)[0]["generated_text"]
15
+ # Step 3: Convert response text to speech
16
+ audio_response = tts_model(response)
17
+ return text, response, audio_response
18
+
19
+ # Create Gradio Interface
20
+ interface = gr.Interface(
21
+ fn=conversation,
22
+ inputs=gr.Audio(source="microphone", type="filepath"),
23
+ outputs=[
24
+ gr.Textbox(label="Transcription"),
25
+ gr.Textbox(label="AI Response"),
26
+ gr.Audio(label="Generated Speech")
27
+ ]
28
+ )
29
+
30
+ # Launch the app
31
+ interface.launch()