Spaces:
Sleeping
Sleeping
update app.py gtts
Browse files
app.py
CHANGED
|
@@ -100,15 +100,20 @@ with gr.Blocks(css="footer {visibility: hidden}") as app:
|
|
| 100 |
chatbot = gr.Chatbot(height=400)
|
| 101 |
msg = gr.Textbox(placeholder="Ask a question about agriculture...", label="Your Question")
|
| 102 |
clear = gr.Button("🗑 Clear Chat")
|
|
|
|
|
|
|
| 103 |
chat_history_state = gr.State([])
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
gr.Markdown("---")
|
| 109 |
gr.Markdown("### ℹ️ About this Application")
|
| 110 |
gr.Markdown("This AI-powered tool helps diagnose plant diseases and provides treatment recommendations. It also includes a chatbot for general agricultural queries.")
|
| 111 |
|
| 112 |
-
# Launch Gradio app
|
| 113 |
if __name__ == "__main__":
|
| 114 |
app.launch(share=True)
|
|
|
|
| 100 |
chatbot = gr.Chatbot(height=400)
|
| 101 |
msg = gr.Textbox(placeholder="Ask a question about agriculture...", label="Your Question")
|
| 102 |
clear = gr.Button("🗑 Clear Chat")
|
| 103 |
+
tts_button = gr.Button("🔊 Text-to-Speech")
|
| 104 |
+
audio_player = gr.Audio(label="Response Audio", interactive=False)
|
| 105 |
chat_history_state = gr.State([])
|
| 106 |
|
| 107 |
+
# Submit user question, clear audio on new question
|
| 108 |
+
msg.submit(fn=chatbot_with_audio, inputs=[msg, chat_history_state], outputs=[chatbot, msg, audio_player])
|
| 109 |
+
clear.click(lambda: ([], "", None), None, [chatbot, msg, audio_player], queue=False)
|
| 110 |
+
|
| 111 |
+
# TTS button plays latest chatbot response
|
| 112 |
+
tts_button.click(fn=on_tts_click, inputs=chat_history_state, outputs=audio_player)
|
| 113 |
|
| 114 |
gr.Markdown("---")
|
| 115 |
gr.Markdown("### ℹ️ About this Application")
|
| 116 |
gr.Markdown("This AI-powered tool helps diagnose plant diseases and provides treatment recommendations. It also includes a chatbot for general agricultural queries.")
|
| 117 |
|
|
|
|
| 118 |
if __name__ == "__main__":
|
| 119 |
app.launch(share=True)
|