gpaasch commited on
Commit
d6d864a
·
1 Parent(s): 2901e96

problems resolved

Browse files
Files changed (1) hide show
  1. src/app.py +23 -35
src/app.py CHANGED
@@ -13,77 +13,65 @@ or, if you have enough info, output a final JSON with fields:
13
  """
14
 
15
  def process_speech(new_transcript, history):
16
- # Skip if no new transcript
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]],
30
  "confidences": [0.8],
31
  "follow_up": "Is the cough productive or dry?"
32
  }
33
 
34
- # Append exchange to history
35
  history.append({"role": "user", "content": new_transcript})
36
  history.append({"role": "assistant", "content": json.dumps(formatted_response, indent=2)})
37
 
38
  except Exception as e:
39
- error_response = {
40
- "error": str(e),
41
- "status": "error"
42
- }
43
  history.append({"role": "user", "content": new_transcript})
44
  history.append({"role": "assistant", "content": json.dumps(error_response, indent=2)})
45
 
46
  return history
47
 
48
  # Build Gradio interface
49
- demo = gr.Blocks()
50
- with demo:
51
- gr.Markdown("# Symptom to ICD-10 Code Lookup (Audio Input)")
52
  chatbot = gr.Chatbot(
53
  label="Conversation",
54
- type="messages" # Use the new message format
 
55
  )
56
 
57
- # Updated Audio component configuration
58
- audio = gr.Audio(
59
- type="text",
60
- sources=["microphone"], # Changed from source to sources
61
- streaming=True
62
  )
63
 
64
- # Add MCP-specific metadata
65
- demo.config = {
66
- "mcp": {
67
- "title": "Medical Symptom to ICD-10 Code Assistant",
68
- "description": "Convert spoken medical symptoms to ICD-10 codes",
69
- "version": "1.0.0",
70
- "capabilities": {
71
- "speech_input": True,
72
- "streaming": True
73
- }
74
  }
75
  }
76
 
77
- audio.stream(
78
- process_speech,
79
- inputs=[audio, chatbot],
 
80
  outputs=chatbot,
81
  show_progress="hidden"
82
  )
83
 
84
  if __name__ == "__main__":
85
  demo.launch(
86
- server_name="0.0.0.0",
87
- server_port=7860,
88
  mcp_server=True
89
  )
 
13
  """
14
 
15
  def process_speech(new_transcript, history):
 
16
  if not new_transcript:
17
  return history
18
 
19
  try:
 
 
 
 
20
  response = symptom_index.as_query_engine().query(new_transcript)
21
 
 
22
  formatted_response = {
23
  "diagnoses": [str(response).split(":")[0]],
24
  "confidences": [0.8],
25
  "follow_up": "Is the cough productive or dry?"
26
  }
27
 
 
28
  history.append({"role": "user", "content": new_transcript})
29
  history.append({"role": "assistant", "content": json.dumps(formatted_response, indent=2)})
30
 
31
  except Exception as e:
32
+ error_response = {"error": str(e), "status": "error"}
 
 
 
33
  history.append({"role": "user", "content": new_transcript})
34
  history.append({"role": "assistant", "content": json.dumps(error_response, indent=2)})
35
 
36
  return history
37
 
38
  # Build Gradio interface
39
+ with gr.Blocks() as demo:
40
+ gr.Markdown("# Symptom to ICD-10 Code Lookup")
41
+
42
  chatbot = gr.Chatbot(
43
  label="Conversation",
44
+ type="messages",
45
+ height=400
46
  )
47
 
48
+ microphone = gr.Microphone(
49
+ streaming=True,
50
+ type="filepath" # Return transcriptions as strings
 
 
51
  )
52
 
53
+ # MCP metadata (store in a separate variable, not as an attribute of demo)
54
+ mcp_metadata = {
55
+ "title": "Medical Symptom to ICD-10 Code Assistant",
56
+ "description": "Convert spoken symptoms to ICD-10 codes",
57
+ "version": "1.0.0",
58
+ "capabilities": {
59
+ "speech_input": True,
60
+ "streaming": True
 
 
61
  }
62
  }
63
 
64
+ # Connect the streaming microphone to the chat
65
+ microphone.stream(
66
+ fn=process_speech,
67
+ inputs=[microphone, chatbot],
68
  outputs=chatbot,
69
  show_progress="hidden"
70
  )
71
 
72
  if __name__ == "__main__":
73
  demo.launch(
74
+ server_name="0.0.0.0",
75
+ server_port=7860,
76
  mcp_server=True
77
  )