adeelshuaib commited on
Commit
ad560f7
·
verified ·
1 Parent(s): fcf4c91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -10
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
- def text_to_voice(response):
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
- tts.save("response.mp3")
60
- os.system("start response.mp3") # Use 'open' for macOS, 'xdg-open' for Linux
 
 
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(value="response.mp3", label="Audio Response")
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."