Spaces:
Sleeping
Sleeping
added the integrated routes ✅✅
Browse files
app.py
CHANGED
|
@@ -1,11 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# Load Hugging Face pipelines
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
# Function to process user input
|
| 11 |
def ai_doctor_interaction(user_input, chat_history=[]):
|
|
@@ -34,6 +45,19 @@ def ai_doctor_interaction(user_input, chat_history=[]):
|
|
| 34 |
chat_history.append(("AI Doctor", response))
|
| 35 |
return chat_history, chat_history
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# Gradio interface
|
| 38 |
with gr.Blocks() as demo:
|
| 39 |
gr.Markdown("<h1 style='text-align: center;'>AI Doctor Avatar</h1>")
|
|
@@ -61,5 +85,10 @@ with gr.Blocks() as demo:
|
|
| 61 |
submit_button.click(ai_doctor_interaction, inputs=[user_input, chatbot], outputs=[chatbot, chatbot])
|
| 62 |
clear_button.click(lambda: [], inputs=[], outputs=[chatbot])
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
# Launch the Gradio app
|
| 65 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
from urllib.parse import parse_qs, urlparse
|
| 4 |
+
|
| 5 |
+
# Backend API endpoints
|
| 6 |
+
BACKEND_BASE_URL = "http://127.0.0.1:5000" # Local development # Flask backend URL
|
| 7 |
+
COMPLETE_APPOINTMENT_ENDPOINT = f"{BACKEND_BASE_URL}/complete_appointment"
|
| 8 |
+
|
| 9 |
+
# Function to extract `appointment_id` from query parameters
|
| 10 |
+
def get_appointment_id():
|
| 11 |
+
query_params = parse_qs(urlparse(gr.Request().url).query)
|
| 12 |
+
return query_params.get("appointment_id", ["Unknown"])[0]
|
| 13 |
|
| 14 |
# Load Hugging Face pipelines
|
| 15 |
+
from transformers import pipeline
|
| 16 |
+
ner_pipeline = pipeline("ner", model="dslim/bert-base-NER") # Named Entity Recognition
|
| 17 |
+
sentiment_pipeline = pipeline("sentiment-analysis") # Sentiment Analysis
|
| 18 |
+
summarization_pipeline = pipeline("summarization", model="facebook/bart-large-cnn") # Summarization
|
| 19 |
+
conversation_pipeline = pipeline("text-generation", model="microsoft/DialoGPT-medium") # Conversational AI
|
| 20 |
|
| 21 |
# Function to process user input
|
| 22 |
def ai_doctor_interaction(user_input, chat_history=[]):
|
|
|
|
| 45 |
chat_history.append(("AI Doctor", response))
|
| 46 |
return chat_history, chat_history
|
| 47 |
|
| 48 |
+
# Function to handle "End Call" button
|
| 49 |
+
def end_call():
|
| 50 |
+
appointment_id = get_appointment_id()
|
| 51 |
+
if appointment_id == "Unknown":
|
| 52 |
+
return "Error: Appointment ID not found. Please try again."
|
| 53 |
+
|
| 54 |
+
# Send a request to the backend to mark the appointment as completed
|
| 55 |
+
response = requests.post(COMPLETE_APPOINTMENT_ENDPOINT, json={"appointment_id": appointment_id})
|
| 56 |
+
if response.status_code == 200:
|
| 57 |
+
return "Appointment marked as completed. Redirecting to the doctors' page..."
|
| 58 |
+
else:
|
| 59 |
+
return f"Error: {response.json().get('message', 'Failed to complete the appointment')}"
|
| 60 |
+
|
| 61 |
# Gradio interface
|
| 62 |
with gr.Blocks() as demo:
|
| 63 |
gr.Markdown("<h1 style='text-align: center;'>AI Doctor Avatar</h1>")
|
|
|
|
| 85 |
submit_button.click(ai_doctor_interaction, inputs=[user_input, chatbot], outputs=[chatbot, chatbot])
|
| 86 |
clear_button.click(lambda: [], inputs=[], outputs=[chatbot])
|
| 87 |
|
| 88 |
+
# Add "End Call" button
|
| 89 |
+
end_call_button = gr.Button("End Call", variant="stop")
|
| 90 |
+
end_call_message = gr.Textbox(label="End Call Status", interactive=False)
|
| 91 |
+
end_call_button.click(end_call, outputs=[end_call_message])
|
| 92 |
+
|
| 93 |
# Launch the Gradio app
|
| 94 |
demo.launch()
|