Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,17 +4,24 @@ import gradio as gr
|
|
4 |
# Load pre-trained models
|
5 |
stt_model = pipeline("automatic-speech-recognition", model="openai/whisper-tiny")
|
6 |
nlp_model = pipeline("text-generation", model="sshleifer/tiny-gpt2")
|
7 |
-
tts_model = pipeline("text-to-speech", model="
|
8 |
-
|
9 |
|
10 |
# Define a function to handle the workflow
|
11 |
def conversation(audio):
|
12 |
# Step 1: Convert speech to text
|
13 |
text = stt_model(audio)["text"]
|
14 |
-
|
15 |
-
response
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
audio_response = tts_model(response)
|
|
|
18 |
return text, response, audio_response
|
19 |
|
20 |
# Create Gradio Interface
|
|
|
4 |
# Load pre-trained models
|
5 |
stt_model = pipeline("automatic-speech-recognition", model="openai/whisper-tiny")
|
6 |
nlp_model = pipeline("text-generation", model="sshleifer/tiny-gpt2")
|
7 |
+
tts_model = pipeline("text-to-speech", model="coqui/XTTS-v2")
|
|
|
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 |
+
|
14 |
+
# Step 2: Generate a response (contextual supermarket-related training)
|
15 |
+
if "supermarket" in text.lower():
|
16 |
+
# Simple supermarket-based response; this can be expanded with more specific data
|
17 |
+
response = "Are you looking for something in particular at the supermarket?"
|
18 |
+
else:
|
19 |
+
# Default response generation (using GPT-2 model)
|
20 |
+
response = nlp_model(text, max_length=50)[0]["generated_text"]
|
21 |
+
|
22 |
+
# Step 3: Convert response text to speech using XTTS-v2
|
23 |
audio_response = tts_model(response)
|
24 |
+
|
25 |
return text, response, audio_response
|
26 |
|
27 |
# Create Gradio Interface
|