gpaasch commited on
Commit
daa3242
·
1 Parent(s): a487eb3

1. Added a professional header and instructions

Browse files

2. Implemented user-friendly response formatting
3. Added advanced settings panel for API keys and model configuration
4. Improved chat interface with bubbles and better formatting
5. Added optional text-to-speech capability (commented out but ready to use)
6. Added clear chat button
7. Improved overall layout and theme

Files changed (2) hide show
  1. requirements.txt +1 -0
  2. src/app.py +107 -16
requirements.txt CHANGED
@@ -25,3 +25,4 @@ requests # For MCP endpoint testing
25
  ffmpeg-python
26
 
27
  psutil # For system resource detection
 
 
25
  ffmpeg-python
26
 
27
  psutil # For system resource detection
28
+ gtts==2.3.1
src/app.py CHANGED
@@ -10,6 +10,9 @@ import json
10
  import psutil
11
  from typing import Tuple, Dict
12
  import torch
 
 
 
13
 
14
  # Model options mapped to their requirements
15
  MODEL_OPTIONS = {
@@ -196,25 +199,113 @@ def process_speech(new_transcript, history):
196
 
197
  return history
198
 
199
- # Build Gradio interface
200
- with gr.Blocks() as demo:
201
- gr.Markdown("# Symptom to ICD-10 Code Lookup")
202
-
203
- chatbot = gr.Chatbot(
204
- label="Conversation",
205
- type="messages",
206
- height=400
207
- )
 
 
 
 
208
 
209
- microphone = gr.Microphone(
210
- streaming=True,
211
- type="filepath" # Use 'filepath' to get the path to the recorded audio file
212
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
 
214
- # Connect the streaming microphone to the chat
215
  microphone.stream(
216
- fn=process_speech,
217
- inputs=[microphone, chatbot],
 
 
 
 
 
 
218
  outputs=chatbot,
219
  show_progress="hidden"
220
  )
 
10
  import psutil
11
  from typing import Tuple, Dict
12
  import torch
13
+ from gtts import gTTS
14
+ import io
15
+ import base64
16
 
17
  # Model options mapped to their requirements
18
  MODEL_OPTIONS = {
 
199
 
200
  return history
201
 
202
+ def text_to_speech(text):
203
+ """Convert text to speech and return audio HTML element."""
204
+ tts = gTTS(text=text, lang='en')
205
+ audio_fp = io.BytesIO()
206
+ tts.write_to_fp(audio_fp)
207
+ audio_b64 = base64.b64encode(audio_fp.getvalue()).decode()
208
+ return f'<audio src="data:audio/mp3;base64,{audio_b64}" autoplay></audio>'
209
+
210
+ def format_response_for_user(response_dict):
211
+ """Convert JSON response to user-friendly format."""
212
+ diagnoses = response_dict.get("diagnoses", [])
213
+ confidences = response_dict.get("confidences", [])
214
+ follow_up = response_dict.get("follow_up", "")
215
 
216
+ message = ""
217
+ if diagnoses and confidences:
218
+ for d, c in zip(diagnoses, confidences):
219
+ conf_percent = int(c * 100)
220
+ message += f"Possible diagnosis ({conf_percent}% confidence): {d}\n"
221
+
222
+ if follow_up:
223
+ message += f"\n{follow_up}"
224
+
225
+ return message
226
+
227
+ # Build enhanced Gradio interface
228
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
229
+ gr.Markdown("""
230
+ # 🏥 Medical Symptom to ICD-10 Code Assistant
231
+
232
+ ## About
233
+ This application is part of the Agents+MCP Hackathon. It helps medical professionals
234
+ and patients understand potential diagnoses based on described symptoms.
235
+
236
+ ### How it works:
237
+ 1. Click the microphone button and describe your symptoms
238
+ 2. The AI will analyze your description and suggest possible diagnoses
239
+ 3. Answer follow-up questions to refine the diagnosis
240
+
241
+ ### Created by:
242
+ Graham Paasch - Medical Coding Professional & Developer
243
+ [GitHub](https://github.com/yourusername) | [LinkedIn](https://linkedin.com/in/yourprofile)
244
+ """)
245
+
246
+ with gr.Row():
247
+ with gr.Column(scale=2):
248
+ chatbot = gr.Chatbot(
249
+ label="Medical Consultation",
250
+ height=500,
251
+ container=True,
252
+ bubble=True
253
+ )
254
+
255
+ with gr.Row():
256
+ microphone = gr.Microphone(
257
+ label="Describe your symptoms",
258
+ streaming=True,
259
+ type="filepath"
260
+ )
261
+ clear_btn = gr.Button("Clear Chat", variant="secondary")
262
+
263
+ with gr.Column(scale=1):
264
+ with gr.Accordion("Advanced Settings", open=False):
265
+ api_key = gr.Textbox(
266
+ label="OpenAI API Key (optional)",
267
+ type="password",
268
+ placeholder="sk-..."
269
+ )
270
+ model_selector = gr.Dropdown(
271
+ choices=list(MODEL_OPTIONS.keys()),
272
+ label="Model Tier",
273
+ value="small",
274
+ interactive=True
275
+ )
276
+ temperature = gr.Slider(
277
+ minimum=0.1,
278
+ maximum=1.0,
279
+ value=0.7,
280
+ label="Temperature"
281
+ )
282
+
283
+ # Event handlers
284
+ clear_btn.click(lambda: None, None, chatbot, queue=False)
285
+
286
+ def enhanced_process_speech(audio_path, history, api_key=None, model_tier="small", temp=0.7):
287
+ transcript = process_speech(audio_path, history)
288
+ last_response = transcript[-1]["content"] if transcript else ""
289
+
290
+ try:
291
+ response_dict = json.loads(last_response)
292
+ user_message = format_response_for_user(response_dict)
293
+ # Optionally generate speech
294
+ # audio_html = text_to_speech(user_message)
295
+ # return transcript + [{"role": "assistant", "content": audio_html}]
296
+ return transcript
297
+ except:
298
+ return transcript
299
 
 
300
  microphone.stream(
301
+ fn=enhanced_process_speech,
302
+ inputs=[
303
+ microphone,
304
+ chatbot,
305
+ api_key,
306
+ model_selector,
307
+ temperature
308
+ ],
309
  outputs=chatbot,
310
  show_progress="hidden"
311
  )