Spaces:
Sleeping
Sleeping
Add footer with social links
Browse files- src/app.py +50 -21
src/app.py
CHANGED
|
@@ -264,20 +264,11 @@ with gr.Blocks() as demo:
|
|
| 264 |
1. Click the microphone button and describe your symptoms
|
| 265 |
2. The AI will analyze your description and suggest possible diagnoses
|
| 266 |
3. Answer follow-up questions to refine the diagnosis
|
| 267 |
-
|
| 268 |
-
### Created by:
|
| 269 |
-
Graham Paasch - Medical Coding Professional & Developer
|
| 270 |
-
[GitHub](https://github.com/yourusername) | [LinkedIn](https://linkedin.com/in/yourprofile)
|
| 271 |
""")
|
| 272 |
|
| 273 |
with gr.Row():
|
| 274 |
with gr.Column(scale=2):
|
| 275 |
-
|
| 276 |
-
label="Medical Consultation",
|
| 277 |
-
height=500,
|
| 278 |
-
container=True
|
| 279 |
-
)
|
| 280 |
-
|
| 281 |
with gr.Row():
|
| 282 |
microphone = gr.Microphone(
|
| 283 |
label="Describe your symptoms",
|
|
@@ -285,6 +276,13 @@ with gr.Blocks() as demo:
|
|
| 285 |
type="filepath"
|
| 286 |
)
|
| 287 |
clear_btn = gr.Button("Clear Chat", variant="secondary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
|
| 289 |
with gr.Column(scale=1):
|
| 290 |
with gr.Accordion("Advanced Settings", open=False):
|
|
@@ -310,19 +308,31 @@ with gr.Blocks() as demo:
|
|
| 310 |
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
| 311 |
|
| 312 |
def enhanced_process_speech(audio_path, history, api_key=None, model_tier="small", temp=0.7):
|
| 313 |
-
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
|
| 316 |
try:
|
| 317 |
-
|
| 318 |
-
user_message =
|
| 319 |
-
#
|
| 320 |
-
|
| 321 |
-
#
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
microphone.stream(
|
| 327 |
fn=enhanced_process_speech,
|
| 328 |
inputs=[
|
|
@@ -335,6 +345,25 @@ with gr.Blocks() as demo:
|
|
| 335 |
outputs=chatbot,
|
| 336 |
show_progress="hidden"
|
| 337 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
|
| 339 |
if __name__ == "__main__":
|
| 340 |
demo.launch(
|
|
|
|
| 264 |
1. Click the microphone button and describe your symptoms
|
| 265 |
2. The AI will analyze your description and suggest possible diagnoses
|
| 266 |
3. Answer follow-up questions to refine the diagnosis
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
""")
|
| 268 |
|
| 269 |
with gr.Row():
|
| 270 |
with gr.Column(scale=2):
|
| 271 |
+
# Moved microphone row above chatbot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
with gr.Row():
|
| 273 |
microphone = gr.Microphone(
|
| 274 |
label="Describe your symptoms",
|
|
|
|
| 276 |
type="filepath"
|
| 277 |
)
|
| 278 |
clear_btn = gr.Button("Clear Chat", variant="secondary")
|
| 279 |
+
|
| 280 |
+
chatbot = gr.Chatbot(
|
| 281 |
+
label="Medical Consultation",
|
| 282 |
+
height=500,
|
| 283 |
+
container=True,
|
| 284 |
+
type="messages"
|
| 285 |
+
)
|
| 286 |
|
| 287 |
with gr.Column(scale=1):
|
| 288 |
with gr.Accordion("Advanced Settings", open=False):
|
|
|
|
| 308 |
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
| 309 |
|
| 310 |
def enhanced_process_speech(audio_path, history, api_key=None, model_tier="small", temp=0.7):
|
| 311 |
+
"""Process speech input and return formatted chat messages."""
|
| 312 |
+
if not audio_path:
|
| 313 |
+
return history
|
| 314 |
+
|
| 315 |
+
# First get the raw transcript and response
|
| 316 |
+
transcript = process_speech(audio_path, []) # Start fresh history
|
| 317 |
+
if not transcript or len(transcript) < 2:
|
| 318 |
+
return history + [[audio_path, "I couldn't process that audio. Could you try again?"]]
|
| 319 |
|
| 320 |
try:
|
| 321 |
+
# Get the last assistant response
|
| 322 |
+
user_message = transcript[-2]["content"] # What the user said
|
| 323 |
+
assistant_json = transcript[-1]["content"] # JSON response from assistant
|
| 324 |
+
|
| 325 |
+
# Parse and format the assistant's response
|
| 326 |
+
response_dict = json.loads(assistant_json)
|
| 327 |
+
formatted_response = format_response_for_user(response_dict)
|
| 328 |
+
|
| 329 |
+
# Add the exchange to history in the correct tuple format
|
| 330 |
+
return history + [[user_message, formatted_response]]
|
| 331 |
+
|
| 332 |
+
except Exception as e:
|
| 333 |
+
print(f"Error formatting chat response: {e}")
|
| 334 |
+
return history + [[audio_path, "Sorry, I encountered an error processing your symptoms. Could you try again?"]]
|
| 335 |
+
|
| 336 |
microphone.stream(
|
| 337 |
fn=enhanced_process_speech,
|
| 338 |
inputs=[
|
|
|
|
| 345 |
outputs=chatbot,
|
| 346 |
show_progress="hidden"
|
| 347 |
)
|
| 348 |
+
|
| 349 |
+
# Add footer with social links
|
| 350 |
+
gr.Markdown("""
|
| 351 |
+
---
|
| 352 |
+
### 👋 About the Creator
|
| 353 |
+
|
| 354 |
+
Hi! I'm Graham Paasch, an experienced technology professional!
|
| 355 |
+
|
| 356 |
+
🎥 **Check out my YouTube channel** for more tech content:
|
| 357 |
+
[Subscribe to my channel](https://www.youtube.com/channel/UCg3oUjrSYcqsL9rGk1g_lPQ)
|
| 358 |
+
|
| 359 |
+
💼 **Looking for a skilled developer?**
|
| 360 |
+
I'm currently seeking new opportunities! View my experience and connect on [LinkedIn](https://www.linkedin.com/in/grahampaasch/)
|
| 361 |
+
|
| 362 |
+
⭐ If you found this tool helpful, please consider:
|
| 363 |
+
- Subscribing to my YouTube channel
|
| 364 |
+
- Connecting on LinkedIn
|
| 365 |
+
- Sharing this tool with others in healthcare tech
|
| 366 |
+
""")
|
| 367 |
|
| 368 |
if __name__ == "__main__":
|
| 369 |
demo.launch(
|