Spaces:
Sleeping
Sleeping
the api has changed in recent version of gradio
Browse files- src/app.py +19 -10
src/app.py
CHANGED
|
@@ -26,21 +26,22 @@ def process_speech(new_transcript, history):
|
|
| 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(
|
|
|
|
| 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(
|
|
|
|
| 44 |
|
| 45 |
return history
|
| 46 |
|
|
@@ -48,8 +49,17 @@ def process_speech(new_transcript, history):
|
|
| 48 |
demo = gr.Blocks()
|
| 49 |
with demo:
|
| 50 |
gr.Markdown("# Symptom to ICD-10 Code Lookup (Audio Input)")
|
| 51 |
-
chatbot = gr.Chatbot(
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# Add MCP-specific metadata
|
| 55 |
demo.config = {
|
|
@@ -75,6 +85,5 @@ if __name__ == "__main__":
|
|
| 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 |
)
|
|
|
|
| 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 |
|
|
|
|
| 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 = {
|
|
|
|
| 85 |
demo.launch(
|
| 86 |
server_name="0.0.0.0",
|
| 87 |
server_port=7860,
|
| 88 |
+
mcp_server=True
|
|
|
|
| 89 |
)
|