gpaasch commited on
Commit
d74007c
·
1 Parent(s): ed04336

include MCP-specific configurations

Browse files
Files changed (1) hide show
  1. src/app.py +40 -16
src/app.py CHANGED
@@ -17,21 +17,31 @@ def process_speech(new_transcript, history):
17
  if not new_transcript:
18
  return history
19
 
20
- # Build conversation context
21
- context = "\n".join([f"{role}: {msg}" for role, msg in history])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- # Query symptom index for relevant codes
24
- response = symptom_index.as_query_engine().query(new_transcript)
25
-
26
- # Format response as structured JSON
27
- formatted_response = {
28
- "diagnoses": [str(response).split(":")[0]], # Extract ICD code
29
- "confidences": [0.8], # Add confidence scoring
30
- "follow_up": "Is the cough productive or dry?" # Add interactive questioning
31
- }
32
-
33
- # Append exchange to history
34
- history.append((new_transcript, json.dumps(formatted_response, indent=2)))
35
  return history
36
 
37
  # Build Gradio interface
@@ -39,7 +49,20 @@ demo = gr.Blocks()
39
  with demo:
40
  gr.Markdown("# Symptom to ICD-10 Code Lookup (Audio Input)")
41
  chatbot = gr.Chatbot(label="Conversation")
42
- audio = gr.Audio(type="filepath", streaming=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  audio.stream(
45
  process_speech,
@@ -52,5 +75,6 @@ if __name__ == "__main__":
52
  demo.launch(
53
  server_name="0.0.0.0",
54
  server_port=7860,
55
- mcp_server=True
 
56
  )
 
17
  if not new_transcript:
18
  return history
19
 
20
+ try:
21
+ # Build conversation context
22
+ context = "\n".join([f"{role}: {msg}" for role, msg in history])
23
+
24
+ # Query symptom index for relevant codes
25
+ response = symptom_index.as_query_engine().query(new_transcript)
26
+
27
+ # Format response as structured JSON
28
+ formatted_response = {
29
+ "diagnoses": [str(response).split(":")[0]], # Extract ICD code
30
+ "confidences": [0.8], # Add confidence scoring
31
+ "follow_up": "Is the cough productive or dry?" # Add interactive questioning
32
+ }
33
+
34
+ # Append exchange to history
35
+ history.append((new_transcript, json.dumps(formatted_response, indent=2)))
36
+
37
+ except Exception as e:
38
+ # Handle errors gracefully for MCP clients
39
+ error_response = {
40
+ "error": str(e),
41
+ "status": "error"
42
+ }
43
+ history.append((new_transcript, json.dumps(error_response, indent=2)))
44
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  return history
46
 
47
  # Build Gradio interface
 
49
  with demo:
50
  gr.Markdown("# Symptom to ICD-10 Code Lookup (Audio Input)")
51
  chatbot = gr.Chatbot(label="Conversation")
52
+ audio = gr.Audio(source="microphone", type="text", streaming=True)
53
+
54
+ # Add MCP-specific metadata
55
+ demo.config = {
56
+ "mcp": {
57
+ "title": "Medical Symptom to ICD-10 Code Assistant",
58
+ "description": "Convert spoken medical symptoms to ICD-10 codes",
59
+ "version": "1.0.0",
60
+ "capabilities": {
61
+ "speech_input": True,
62
+ "streaming": True
63
+ }
64
+ }
65
+ }
66
 
67
  audio.stream(
68
  process_speech,
 
75
  demo.launch(
76
  server_name="0.0.0.0",
77
  server_port=7860,
78
+ mcp_server=True,
79
+ mcp_polling_interval=1000 # 1 second polling interval
80
  )