RathodHarish commited on
Commit
dd19451
·
verified ·
1 Parent(s): 432d77e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -7
app.py CHANGED
@@ -50,16 +50,25 @@ def transcribe_audio(audio_file):
50
  response.raise_for_status()
51
  result = response.json()
52
  transcription = result.get("text", "").strip()
 
53
  if not transcription:
54
- return "Transcription empty. Please provide clear audio describing symptoms."
55
  print(f"Transcription: {transcription}")
56
  return transcription
57
  except requests.exceptions.HTTPError as e:
 
58
  if e.response.status_code == 401:
59
- return "Error transcribing audio: Unauthorized. Please check HF_TOKEN in Space secrets at https://huggingface.co/spaces/your-username/HealthVoiceAnalyzer/settings."
60
- return f"Error transcribing audio: {str(e)}"
 
 
 
 
 
61
  except Exception as e:
62
- return f"Error transcribing audio: {str(e)}"
 
 
63
 
64
  def analyze_symptoms(text):
65
  """Analyze symptoms using Symptom-2-Disease API."""
@@ -70,6 +79,7 @@ def analyze_symptoms(text):
70
  response = requests.post(SYMPTOM_API_URL, headers=HEADERS, json=payload)
71
  response.raise_for_status()
72
  result = response.json()
 
73
  if result and isinstance(result, list) and len(result) > 0:
74
  prediction = result[0][0]["label"]
75
  score = result[0][0]["score"]
@@ -77,11 +87,19 @@ def analyze_symptoms(text):
77
  return prediction, score
78
  return "No health condition predicted", 0.0
79
  except requests.exceptions.HTTPError as e:
 
80
  if e.response.status_code == 401:
81
- return "Error analyzing symptoms: Unauthorized. Please check HF_TOKEN in Space secrets at https://huggingface.co/spaces/your-username/HealthVoiceAnalyzer/settings.", 0.0
82
- return f"Error analyzing symptoms: {str(e)}", 0.0
 
 
 
 
 
83
  except Exception as e:
84
- return f"Error analyzing symptoms: {str(e)}", 0.0
 
 
85
 
86
  def analyze_voice(audio_file):
87
  """Analyze voice for health indicators."""
 
50
  response.raise_for_status()
51
  result = response.json()
52
  transcription = result.get("text", "").strip()
53
+ print(f"Whisper API response: {result}")
54
  if not transcription:
55
+ return "Transcription empty. Please provide clear audio describing symptoms in English."
56
  print(f"Transcription: {transcription}")
57
  return transcription
58
  except requests.exceptions.HTTPError as e:
59
+ error_msg = f"Error transcribing audio: {str(e)}"
60
  if e.response.status_code == 401:
61
+ error_msg = (
62
+ "Error transcribing audio: Unauthorized. Please check HF_TOKEN in Space secrets at "
63
+ "https://huggingface.co/spaces/your-username/HealthVoiceAnalyzer/settings. "
64
+ "Ensure token has Inference API access (get at https://huggingface.co/settings/tokens)."
65
+ )
66
+ print(error_msg)
67
+ return error_msg
68
  except Exception as e:
69
+ error_msg = f"Error transcribing audio: {str(e)}"
70
+ print(error_msg)
71
+ return error_msg
72
 
73
  def analyze_symptoms(text):
74
  """Analyze symptoms using Symptom-2-Disease API."""
 
79
  response = requests.post(SYMPTOM_API_URL, headers=HEADERS, json=payload)
80
  response.raise_for_status()
81
  result = response.json()
82
+ print(f"Symptom API response: {result}")
83
  if result and isinstance(result, list) and len(result) > 0:
84
  prediction = result[0][0]["label"]
85
  score = result[0][0]["score"]
 
87
  return prediction, score
88
  return "No health condition predicted", 0.0
89
  except requests.exceptions.HTTPError as e:
90
+ error_msg = f"Error analyzing symptoms: {str(e)}"
91
  if e.response.status_code == 401:
92
+ error_msg = (
93
+ "Error analyzing symptoms: Unauthorized. Please check HF_TOKEN in Space secrets at "
94
+ "https://huggingface.co/spaces/your-username/HealthVoiceAnalyzer/settings. "
95
+ "Ensure token has Inference API access (get at https://huggingface.co/settings/tokens)."
96
+ )
97
+ print(error_msg)
98
+ return error_msg, 0.0
99
  except Exception as e:
100
+ error_msg = f"Error analyzing symptoms: {str(e)}"
101
+ print(error_msg)
102
+ return error_msg, 0.0
103
 
104
  def analyze_voice(audio_file):
105
  """Analyze voice for health indicators."""