Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -47,17 +47,13 @@ def respond(
|
|
47 |
|
48 |
# Decode the response and return it
|
49 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
50 |
-
return response
|
51 |
|
52 |
-
|
53 |
-
"""
|
54 |
-
Convert the response text to speech using Google Text-to-Speech.
|
55 |
-
Args:
|
56 |
-
- response: Text response from the model to be converted to speech.
|
57 |
-
"""
|
58 |
tts = gTTS(text=response, lang='en')
|
59 |
-
|
60 |
-
|
|
|
|
|
61 |
|
62 |
# Build the Gradio Interface
|
63 |
demo = gr.Interface(
|
@@ -67,7 +63,7 @@ demo = gr.Interface(
|
|
67 |
],
|
68 |
outputs=[
|
69 |
gr.Textbox(label="Chatbot Response"),
|
70 |
-
gr.Audio(
|
71 |
],
|
72 |
title="Farming Assistant Chatbot",
|
73 |
description="Ask questions about farming, crop management, pest control, soil conditions, and best agricultural practices."
|
|
|
47 |
|
48 |
# Decode the response and return it
|
49 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
50 |
|
51 |
+
# Convert the response to speech and save as an audio file
|
|
|
|
|
|
|
|
|
|
|
52 |
tts = gTTS(text=response, lang='en')
|
53 |
+
audio_path = "response.mp3"
|
54 |
+
tts.save(audio_path)
|
55 |
+
|
56 |
+
return response, audio_path
|
57 |
|
58 |
# Build the Gradio Interface
|
59 |
demo = gr.Interface(
|
|
|
63 |
],
|
64 |
outputs=[
|
65 |
gr.Textbox(label="Chatbot Response"),
|
66 |
+
gr.Audio(label="Audio Response") # Expect audio as well as text output
|
67 |
],
|
68 |
title="Farming Assistant Chatbot",
|
69 |
description="Ask questions about farming, crop management, pest control, soil conditions, and best agricultural practices."
|