Spaces:
Sleeping
Sleeping
1. Removed hardcoded "cough" question
Browse files2. Added generic follow-up about symptom timing
3. Included transcript in error responses for debugging
4. Maintained JSON structure but made content dynamic
- src/app.py +14 -4
src/app.py
CHANGED
|
@@ -144,19 +144,29 @@ def process_speech(new_transcript, history):
|
|
| 144 |
return history
|
| 145 |
|
| 146 |
try:
|
|
|
|
| 147 |
response = symptom_index.as_query_engine().query(new_transcript)
|
| 148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
formatted_response = {
|
| 150 |
-
"diagnoses": [
|
| 151 |
-
"confidences": [0.8],
|
| 152 |
-
"follow_up": "
|
| 153 |
}
|
| 154 |
|
|
|
|
| 155 |
history.append({"role": "user", "content": new_transcript})
|
| 156 |
history.append({"role": "assistant", "content": json.dumps(formatted_response, indent=2)})
|
| 157 |
|
| 158 |
except Exception as e:
|
| 159 |
-
error_response = {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
history.append({"role": "user", "content": new_transcript})
|
| 161 |
history.append({"role": "assistant", "content": json.dumps(error_response, indent=2)})
|
| 162 |
|
|
|
|
| 144 |
return history
|
| 145 |
|
| 146 |
try:
|
| 147 |
+
# Query the symptom index with user's transcript
|
| 148 |
response = symptom_index.as_query_engine().query(new_transcript)
|
| 149 |
|
| 150 |
+
# Extract the ICD code and description
|
| 151 |
+
icd_info = str(response).strip()
|
| 152 |
+
|
| 153 |
+
# Structure the initial response
|
| 154 |
formatted_response = {
|
| 155 |
+
"diagnoses": [icd_info],
|
| 156 |
+
"confidences": [0.8], # We could make this more dynamic
|
| 157 |
+
"follow_up": f"Could you tell me more about your symptoms? When did they start?"
|
| 158 |
}
|
| 159 |
|
| 160 |
+
# Add to conversation history
|
| 161 |
history.append({"role": "user", "content": new_transcript})
|
| 162 |
history.append({"role": "assistant", "content": json.dumps(formatted_response, indent=2)})
|
| 163 |
|
| 164 |
except Exception as e:
|
| 165 |
+
error_response = {
|
| 166 |
+
"error": str(e),
|
| 167 |
+
"status": "error",
|
| 168 |
+
"transcript": new_transcript # Include what we heard for debugging
|
| 169 |
+
}
|
| 170 |
history.append({"role": "user", "content": new_transcript})
|
| 171 |
history.append({"role": "assistant", "content": json.dumps(error_response, indent=2)})
|
| 172 |
|