montassarTester commited on
Commit
4f48e62
·
verified ·
1 Parent(s): 0ff085d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py CHANGED
@@ -78,6 +78,29 @@ def diagnose_image(image):
78
  return result
79
  except Exception as e:
80
  return f"❌ Error during diagnosis: {e}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
  # Build Gradio UI
83
  with gr.Blocks(css="footer {visibility: hidden}") as app:
 
78
  return result
79
  except Exception as e:
80
  return f"❌ Error during diagnosis: {e}"
81
+ def text_to_speech(text):
82
+ if not text.strip():
83
+ return None
84
+ try:
85
+ tts = gTTS(text=text, lang='en')
86
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
87
+ tts.save(temp_file.name)
88
+ return temp_file.name
89
+ except Exception as e:
90
+ print(f"TTS error: {e}")
91
+ return None
92
+
93
+ # Wrap groq_chatbot so it also clears audio on new input
94
+ def chatbot_with_audio(input_text, chat_history):
95
+ chat_history, cleared_msg = groq_chatbot(input_text, chat_history)
96
+ return chat_history, cleared_msg, None # None clears audio player on new chat input
97
+
98
+ def on_tts_click(chat_history):
99
+ if chat_history and chat_history[-1][1]:
100
+ last_response = chat_history[-1][1]
101
+ audio_path = text_to_speech(last_response)
102
+ return audio_path
103
+ return None
104
 
105
  # Build Gradio UI
106
  with gr.Blocks(css="footer {visibility: hidden}") as app: