RathodHarish commited on
Commit
5cd70e9
·
verified ·
1 Parent(s): 72f3531

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -24
app.py CHANGED
@@ -7,13 +7,8 @@ from datetime import datetime
7
  import soundfile as sf
8
  import torch
9
  from tenacity import retry, stop_after_attempt, wait_fixed
10
- import pyttsx3
11
  from transformers import pipeline
12
 
13
- # Initialize text-to-speech engine
14
- tts_engine = pyttsx3.init()
15
- tts_engine.setProperty('rate', 150)
16
-
17
  # Initialize local models with retry logic
18
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(2))
19
  def load_whisper_model():
@@ -145,10 +140,6 @@ def handle_health_query(query, language="en"):
145
  return "Please provide a valid health query."
146
  # Placeholder for Q&A logic (could integrate a model like BERT for Q&A)
147
  response = f"Response to query '{query}': For accurate health information, consult a healthcare provider."
148
- # Text-to-speech
149
- tts_engine.setProperty('voice', language)
150
- tts_engine.say(response)
151
- tts_engine.runAndWait()
152
  return response
153
 
154
  def analyze_voice(audio_file, language="en"):
@@ -170,8 +161,6 @@ def analyze_voice(audio_file, language="en"):
170
  # Transcribe audio
171
  transcription = transcribe_audio(audio_file, language)
172
  if "Error transcribing" in transcription:
173
- tts_engine.say(transcription)
174
- tts_engine.runAndWait()
175
  return transcription
176
 
177
  # Check for medication-related queries
@@ -179,15 +168,11 @@ def analyze_voice(audio_file, language="en"):
179
  feedback = "Error: This tool does not provide medication or treatment advice. Please describe symptoms only (e.g., 'I have a fever')."
180
  feedback += f"\n\n**Debug Info**: Transcription = '{transcription}', File Hash = {file_hash}"
181
  feedback += "\n**Disclaimer**: This is not a diagnostic tool. Consult a healthcare provider for medical advice."
182
- tts_engine.say(feedback)
183
- tts_engine.runAndWait()
184
  return feedback
185
 
186
  # Analyze symptoms
187
  prediction, score = analyze_symptoms(transcription)
188
  if "Error analyzing" in prediction:
189
- tts_engine.say(prediction)
190
- tts_engine.runAndWait()
191
  return prediction
192
 
193
  # Generate feedback
@@ -199,10 +184,6 @@ def analyze_voice(audio_file, language="en"):
199
  feedback += f"\n\n**Debug Info**: Transcription = '{transcription}', Prediction = {prediction}, Confidence = {score:.4f}, File Hash = {file_hash}"
200
  feedback += "\n**Disclaimer**: This is not a diagnostic tool. Consult a healthcare provider for medical advice."
201
 
202
- # Text-to-speech for feedback
203
- tts_engine.say(feedback)
204
- tts_engine.runAndWait()
205
-
206
  # Clean up temporary audio file
207
  try:
208
  os.remove(audio_file)
@@ -212,10 +193,7 @@ def analyze_voice(audio_file, language="en"):
212
 
213
  return feedback
214
  except Exception as e:
215
- error_msg = f"Error processing audio: {str(e)}"
216
- tts_engine.say(error_msg)
217
- tts_engine.runAndWait()
218
- return error_msg
219
 
220
  # Gradio interface
221
  def create_gradio_interface():
@@ -225,7 +203,8 @@ def create_gradio_interface():
225
  # Health Voice Analyzer
226
  Record or upload a voice sample describing symptoms in English, Spanish, Hindi, or Mandarin (e.g., 'I have a fever').
227
  Ask health questions in the text box below. Supports WAV, 16kHz audio.
228
- **Disclaimer**: This is not a diagnostic tool. Consult a healthcare provider for medical advice.
 
229
  """
230
  )
231
  with gr.Row():
 
7
  import soundfile as sf
8
  import torch
9
  from tenacity import retry, stop_after_attempt, wait_fixed
 
10
  from transformers import pipeline
11
 
 
 
 
 
12
  # Initialize local models with retry logic
13
  @retry(stop=stop_after_attempt(3), wait=wait_fixed(2))
14
  def load_whisper_model():
 
140
  return "Please provide a valid health query."
141
  # Placeholder for Q&A logic (could integrate a model like BERT for Q&A)
142
  response = f"Response to query '{query}': For accurate health information, consult a healthcare provider."
 
 
 
 
143
  return response
144
 
145
  def analyze_voice(audio_file, language="en"):
 
161
  # Transcribe audio
162
  transcription = transcribe_audio(audio_file, language)
163
  if "Error transcribing" in transcription:
 
 
164
  return transcription
165
 
166
  # Check for medication-related queries
 
168
  feedback = "Error: This tool does not provide medication or treatment advice. Please describe symptoms only (e.g., 'I have a fever')."
169
  feedback += f"\n\n**Debug Info**: Transcription = '{transcription}', File Hash = {file_hash}"
170
  feedback += "\n**Disclaimer**: This is not a diagnostic tool. Consult a healthcare provider for medical advice."
 
 
171
  return feedback
172
 
173
  # Analyze symptoms
174
  prediction, score = analyze_symptoms(transcription)
175
  if "Error analyzing" in prediction:
 
 
176
  return prediction
177
 
178
  # Generate feedback
 
184
  feedback += f"\n\n**Debug Info**: Transcription = '{transcription}', Prediction = {prediction}, Confidence = {score:.4f}, File Hash = {file_hash}"
185
  feedback += "\n**Disclaimer**: This is not a diagnostic tool. Consult a healthcare provider for medical advice."
186
 
 
 
 
 
187
  # Clean up temporary audio file
188
  try:
189
  os.remove(audio_file)
 
193
 
194
  return feedback
195
  except Exception as e:
196
+ return f"Error processing audio: {str(e)}"
 
 
 
197
 
198
  # Gradio interface
199
  def create_gradio_interface():
 
203
  # Health Voice Analyzer
204
  Record or upload a voice sample describing symptoms in English, Spanish, Hindi, or Mandarin (e.g., 'I have a fever').
205
  Ask health questions in the text box below. Supports WAV, 16kHz audio.
206
+ **Disclaimer**: This is not a diagnostic tool. Consult a healthcare provider for medical advice.
207
+ **Note**: Text-to-speech is available in the web frontend (Salesforce Sites) using the browser's Web Speech API.
208
  """
209
  )
210
  with gr.Row():