Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import
|
| 2 |
import requests
|
| 3 |
import json
|
| 4 |
from datetime import datetime, date
|
|
@@ -19,19 +19,18 @@ TWILIO_ACCOUNT_SID = os.getenv("TWILIO_ACCOUNT_SID")
|
|
| 19 |
TWILIO_AUTH_TOKEN = os.getenv("TWILIO_AUTH_TOKEN")
|
| 20 |
TWILIO_PHONE = os.getenv("TWILIO_PHONE")
|
| 21 |
CALENDLY_API_TOKEN = os.getenv("CALENDLY_API_TOKEN")
|
| 22 |
-
|
| 23 |
-
# Salesforce REST API Configuration
|
| 24 |
SALESFORCE_BASE_URL = os.getenv("SALESFORCE_INSTANCE_URL", "https://your_instance.salesforce.com/services/data/v60.0/")
|
| 25 |
-
SALESFORCE_HEADERS = {
|
| 26 |
-
"Authorization": f"Bearer {SALESFORCE_ACCESS_TOKEN}",
|
| 27 |
-
"Content-Type": "application/json"
|
| 28 |
-
}
|
| 29 |
|
| 30 |
# Validate environment variables
|
| 31 |
if not all([HF_API_TOKEN, SALESFORCE_ACCESS_TOKEN, TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_PHONE, CALENDLY_API_TOKEN]):
|
| 32 |
-
st.error("Missing environment variables. Please configure API tokens in Hugging Face Spaces secrets.")
|
| 33 |
logging.error("Missing environment variables for API integrations.")
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# Hugging Face Client
|
| 37 |
class HuggingFaceClient:
|
|
@@ -158,116 +157,69 @@ class CalendlyClient:
|
|
| 158 |
logging.error(f"Failed to schedule Calendly event: {str(e)}")
|
| 159 |
return None
|
| 160 |
|
| 161 |
-
#
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
.stApp { background-color: #f0f2f6; }
|
| 169 |
-
.stButton>button { background-color: #4CAF50; color: white; border-radius: 5px; }
|
| 170 |
-
.stTextInput>label { font-weight: bold; }
|
| 171 |
-
.sidebar .sidebar-content { background-color: #ffffff; }
|
| 172 |
-
.stDataFrame { border: 1px solid #ddd; border-radius: 5px; }
|
| 173 |
-
</style>
|
| 174 |
-
""", unsafe_allow_html=True)
|
| 175 |
-
|
| 176 |
-
# Initialize clients
|
| 177 |
try:
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
except Exception as e:
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
st.success("Consent recorded successfully!")
|
| 228 |
-
logging.info("Consent recorded.")
|
| 229 |
-
else:
|
| 230 |
-
st.error("Failed to record consent.")
|
| 231 |
-
logging.error("Failed to record consent.")
|
| 232 |
-
else:
|
| 233 |
-
st.error("Patient not found.")
|
| 234 |
-
logging.error(f"Patient not found for phone: {patient_phone}")
|
| 235 |
-
|
| 236 |
-
elif choice == "Follow-up Messaging":
|
| 237 |
-
st.header("Follow-up Messaging")
|
| 238 |
-
with st.form("followup_form", clear_on_submit=True):
|
| 239 |
-
patient_phone = st.text_input("Patient Phone Number", placeholder="+1234567890")
|
| 240 |
-
message_template = st.text_area("Message Template", "How are you feeling today?")
|
| 241 |
-
follow_up_date = st.date_input("Follow-up Date", value=date.today())
|
| 242 |
-
submit = st.form_submit_button("Schedule Follow-up")
|
| 243 |
-
if submit and patient_phone:
|
| 244 |
-
patients = sf_client.query_records(f"SELECT Id, ConsentGiven__c, Language__c FROM Patient__c WHERE Phone__c = '{patient_phone}'")
|
| 245 |
-
if patients and patients[0]["ConsentGiven__c"] == "Approved":
|
| 246 |
-
followup_data = {
|
| 247 |
-
"Patient__c": patients[0]["Id"], "FollowUpDate__c": follow_up_date.isoformat(),
|
| 248 |
-
"MessageTemplate__c": message_template, "Status__c": "Scheduled"
|
| 249 |
-
}
|
| 250 |
-
followup_id = sf_client.create_record("FollowUpPlan__c", followup_data)
|
| 251 |
-
if followup_id:
|
| 252 |
-
if twilio_client.send_message(patient_phone, message_template):
|
| 253 |
-
sf_client.create_record("MessageLog__c", {
|
| 254 |
-
"Patient__c": patients[0]["Id"], "MessageText__c": message_template,
|
| 255 |
-
"Direction__c": "Outbound", "Timestamp__c": datetime.utcnow().isoformat()
|
| 256 |
-
})
|
| 257 |
-
st.success("Follow-up scheduled and message sent!")
|
| 258 |
-
logging.info(f"Follow-up scheduled for patient: {patients[0]['Id']}")
|
| 259 |
-
else:
|
| 260 |
-
st.error("Failed to send message.")
|
| 261 |
-
logging.error("Failed to send Twilio message.")
|
| 262 |
-
else:
|
| 263 |
-
st.error("Failed to schedule follow-up.")
|
| 264 |
-
logging.error("Failed to create FollowUpPlan__c.")
|
| 265 |
-
else:
|
| 266 |
-
st.error("Patient not found or consent not approved.")
|
| 267 |
-
logging.error(f"Consent check failed for phone: {patient_phone}")
|
| 268 |
-
|
| 269 |
-
elif choice == "Risk Dashboard":
|
| 270 |
-
st.header("Risk Analysis Dashboard")
|
| 271 |
symptom_logs = sf_client.query_records("SELECT Patient__c, ResponseText__c, RiskScore__c, Severity__c, Sentiment__c FROM SymptomLog__c")
|
| 272 |
if symptom_logs:
|
| 273 |
df = pd.DataFrame([
|
|
@@ -275,86 +227,156 @@ def main():
|
|
| 275 |
"Risk Score": log["RiskScore__c"], "Severity": log["Severity__c"],
|
| 276 |
"Sentiment": log["Sentiment__c"]} for log in symptom_logs
|
| 277 |
])
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
case_data = {
|
| 285 |
-
"RelatedPatient__c":
|
| 286 |
-
"Description__c": f"High-risk response: {
|
| 287 |
}
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
|
|
|
|
| 359 |
if __name__ == "__main__":
|
| 360 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import json
|
| 4 |
from datetime import datetime, date
|
|
|
|
| 19 |
TWILIO_AUTH_TOKEN = os.getenv("TWILIO_AUTH_TOKEN")
|
| 20 |
TWILIO_PHONE = os.getenv("TWILIO_PHONE")
|
| 21 |
CALENDLY_API_TOKEN = os.getenv("CALENDLY_API_TOKEN")
|
|
|
|
|
|
|
| 22 |
SALESFORCE_BASE_URL = os.getenv("SALESFORCE_INSTANCE_URL", "https://your_instance.salesforce.com/services/data/v60.0/")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# Validate environment variables
|
| 25 |
if not all([HF_API_TOKEN, SALESFORCE_ACCESS_TOKEN, TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_PHONE, CALENDLY_API_TOKEN]):
|
|
|
|
| 26 |
logging.error("Missing environment variables for API integrations.")
|
| 27 |
+
raise ValueError("Missing environment variables. Configure API tokens in Hugging Face Spaces secrets.")
|
| 28 |
+
|
| 29 |
+
# Salesforce REST API Headers
|
| 30 |
+
SALESFORCE_HEADERS = {
|
| 31 |
+
"Authorization": f"Bearer {SALESFORCE_ACCESS_TOKEN}",
|
| 32 |
+
"Content-Type": "application/json"
|
| 33 |
+
}
|
| 34 |
|
| 35 |
# Hugging Face Client
|
| 36 |
class HuggingFaceClient:
|
|
|
|
| 157 |
logging.error(f"Failed to schedule Calendly event: {str(e)}")
|
| 158 |
return None
|
| 159 |
|
| 160 |
+
# Gradio Interface Functions
|
| 161 |
+
hf_client = HuggingFaceClient(HF_API_TOKEN)
|
| 162 |
+
sf_client = SalesforceClient(SALESFORCE_BASE_URL, SALESFORCE_HEADERS)
|
| 163 |
+
twilio_client = TwilioClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_PHONE)
|
| 164 |
+
calendly_client = CalendlyClient(CALENDLY_API_TOKEN)
|
| 165 |
+
|
| 166 |
+
def register_patient(phone, email, language, consent_status):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
try:
|
| 168 |
+
name = f"PAT-{str(uuid.uuid4())[:6]}" # Auto-generated
|
| 169 |
+
patient_data = {
|
| 170 |
+
"Name": name, "Phone__c": phone, "Email__c": email,
|
| 171 |
+
"Language__c": language, "ConsentGiven__c": consent_status
|
| 172 |
+
}
|
| 173 |
+
patient_id = sf_client.create_record("Patient__c", patient_data)
|
| 174 |
+
if patient_id:
|
| 175 |
+
logging.info(f"Registered patient: {name}")
|
| 176 |
+
return f"Patient {name} registered successfully!"
|
| 177 |
+
return "Failed to register patient."
|
| 178 |
except Exception as e:
|
| 179 |
+
logging.error(f"Error registering patient: {str(e)}")
|
| 180 |
+
return f"Error: {str(e)}"
|
| 181 |
+
|
| 182 |
+
def submit_consent(patient_phone, method):
|
| 183 |
+
try:
|
| 184 |
+
patients = sf_client.query_records(f"SELECT Id FROM Patient__c WHERE Phone__c = '{patient_phone}'")
|
| 185 |
+
if patients:
|
| 186 |
+
consent_data = {"Method__c": method, "GivenOn__c": date.today().isoformat()}
|
| 187 |
+
consent_id = sf_client.create_record("Consent__c", consent_data)
|
| 188 |
+
if consent_id:
|
| 189 |
+
logging.info("Consent recorded.")
|
| 190 |
+
return "Consent recorded successfully!"
|
| 191 |
+
return "Failed to record consent."
|
| 192 |
+
return "Patient not found."
|
| 193 |
+
except Exception as e:
|
| 194 |
+
logging.error(f"Error submitting consent: {str(e)}")
|
| 195 |
+
return f"Error: {str(e)}"
|
| 196 |
+
|
| 197 |
+
def schedule_followup(patient_phone, message_template, follow_up_date):
|
| 198 |
+
try:
|
| 199 |
+
patients = sf_client.query_records(f"SELECT Id, ConsentGiven__c, Language__c FROM Patient__c WHERE Phone__c = '{patient_phone}'")
|
| 200 |
+
if patients and patients[0]["ConsentGiven__c"] == "Approved":
|
| 201 |
+
followup_data = {
|
| 202 |
+
"Patient__c": patients[0]["Id"], "FollowUpDate__c": follow_up_date.isoformat(),
|
| 203 |
+
"MessageTemplate__c": message_template, "Status__c": "Scheduled"
|
| 204 |
+
}
|
| 205 |
+
followup_id = sf_client.create_record("FollowUpPlan__c", followup_data)
|
| 206 |
+
if followup_id:
|
| 207 |
+
if twilio_client.send_message(patient_phone, message_template):
|
| 208 |
+
sf_client.create_record("MessageLog__c", {
|
| 209 |
+
"Patient__c": patients[0]["Id"], "MessageText__c": message_template,
|
| 210 |
+
"Direction__c": "Outbound", "Timestamp__c": datetime.utcnow().isoformat()
|
| 211 |
+
})
|
| 212 |
+
logging.info(f"Follow-up scheduled for patient: {patients[0]['Id']}")
|
| 213 |
+
return "Follow-up scheduled and message sent!"
|
| 214 |
+
return "Failed to send message."
|
| 215 |
+
return "Failed to schedule follow-up."
|
| 216 |
+
return "Patient not found or consent not approved."
|
| 217 |
+
except Exception as e:
|
| 218 |
+
logging.error(f"Error scheduling follow-up: {str(e)}")
|
| 219 |
+
return f"Error: {str(e)}"
|
| 220 |
+
|
| 221 |
+
def view_risk_dashboard():
|
| 222 |
+
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
symptom_logs = sf_client.query_records("SELECT Patient__c, ResponseText__c, RiskScore__c, Severity__c, Sentiment__c FROM SymptomLog__c")
|
| 224 |
if symptom_logs:
|
| 225 |
df = pd.DataFrame([
|
|
|
|
| 227 |
"Risk Score": log["RiskScore__c"], "Severity": log["Severity__c"],
|
| 228 |
"Sentiment": log["Sentiment__c"]} for log in symptom_logs
|
| 229 |
])
|
| 230 |
+
high_risk = df[df["Severity"] == "High"]
|
| 231 |
+
return df, high_risk.to_dict('records') if not high_risk.empty else "No high-risk cases."
|
| 232 |
+
return pd.DataFrame(), "No symptom logs available."
|
| 233 |
+
except Exception as e:
|
| 234 |
+
logging.error(f"Error loading risk dashboard: {str(e)}")
|
| 235 |
+
return pd.DataFrame(), f"Error: {str(e)}"
|
| 236 |
+
|
| 237 |
+
def escalate_case(patient_id, response_text):
|
| 238 |
+
try:
|
| 239 |
+
case_data = {
|
| 240 |
+
"RelatedPatient__c": patient_id, "Priority__c": "High",
|
| 241 |
+
"Description__c": f"High-risk response: {response_text}"
|
| 242 |
+
}
|
| 243 |
+
case_id = sf_client.create_record("Case__c", case_data)
|
| 244 |
+
if case_id:
|
| 245 |
+
logging.info(f"Case created for patient: {patient_id}")
|
| 246 |
+
return "Case created successfully!"
|
| 247 |
+
return "Failed to create case."
|
| 248 |
+
except Exception as e:
|
| 249 |
+
logging.error(f"Error escalating case: {str(e)}")
|
| 250 |
+
return f"Error: {str(e)}"
|
| 251 |
+
|
| 252 |
+
def schedule_appointment(patient_email, event_type_uuid):
|
| 253 |
+
try:
|
| 254 |
+
event_time = calendly_client.create_event(patient_email, event_type_uuid)
|
| 255 |
+
if event_time:
|
| 256 |
+
appointment_data = {"DateTime__c": event_time, "Status__c": "Scheduled"}
|
| 257 |
+
appointment_id = sf_client.create_record("Appointment__c", appointment_data)
|
| 258 |
+
if appointment_id:
|
| 259 |
+
logging.info(f"Appointment scheduled for {patient_email}")
|
| 260 |
+
return f"Appointment scheduled for {event_time}!"
|
| 261 |
+
return "Failed to create appointment record."
|
| 262 |
+
return "Failed to schedule appointment."
|
| 263 |
+
except Exception as e:
|
| 264 |
+
logging.error(f"Error scheduling appointment: {str(e)}")
|
| 265 |
+
return f"Error: {str(e)}"
|
| 266 |
+
|
| 267 |
+
def submit_survey(patient_phone, question, answer):
|
| 268 |
+
try:
|
| 269 |
+
patients = sf_client.query_records(f"SELECT Id, Language__c FROM Patient__c WHERE Phone__c = '{patient_phone}'")
|
| 270 |
+
if patients:
|
| 271 |
+
survey_data = {"Question__c": question, "Answer__c": answer}
|
| 272 |
+
survey_id = sf_client.create_record("Survey__c", survey_data)
|
| 273 |
+
if survey_id:
|
| 274 |
+
analysis = hf_client.analyze_response(answer, patients[0]["Language__c"])
|
| 275 |
+
if analysis:
|
| 276 |
+
symptom_data = {
|
| 277 |
+
"Patient__c": patients[0]["Id"], "ResponseText__c": answer,
|
| 278 |
+
"RiskScore__c": analysis["risk_level"], "Severity__c": analysis["severity_score"],
|
| 279 |
+
"Sentiment__c": analysis["sentiment_score"]
|
| 280 |
+
}
|
| 281 |
+
symptom_id = sf_client.create_record("SymptomLog__c", symptom_data)
|
| 282 |
+
if symptom_id and analysis["risk_level"] == "High":
|
| 283 |
case_data = {
|
| 284 |
+
"RelatedPatient__c": patients[0]["Id"], "Priority__c": "High",
|
| 285 |
+
"Description__c": f"High-risk survey response: {answer}"
|
| 286 |
}
|
| 287 |
+
sf_client.create_record("Case__c", case_data)
|
| 288 |
+
logging.info(f"Survey submitted for patient: {patients[0]['Id']}")
|
| 289 |
+
return "Survey submitted and analyzed!"
|
| 290 |
+
return "Failed to analyze survey response."
|
| 291 |
+
return "Failed to submit survey."
|
| 292 |
+
return "Patient not found."
|
| 293 |
+
except Exception as e:
|
| 294 |
+
logging.error(f"Error submitting survey: {str(e)}")
|
| 295 |
+
return f"Error: {str(e)}"
|
| 296 |
+
|
| 297 |
+
# Gradio Interface
|
| 298 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="AI-Powered Patient Follow-up Agent") as demo:
|
| 299 |
+
gr.Markdown("# AI-Powered Patient Follow-up Agent for Clinics")
|
| 300 |
+
|
| 301 |
+
with gr.Tabs():
|
| 302 |
+
with gr.Tab("Patient Registration"):
|
| 303 |
+
phone_input = gr.Textbox(label="Phone Number", placeholder="+1234567890")
|
| 304 |
+
email_input = gr.Textbox(label="Email", placeholder="patient@example.com")
|
| 305 |
+
language_input = gr.Dropdown(["English", "Spanish", "French"], label="Language")
|
| 306 |
+
consent_input = gr.Dropdown(["Approved", "Awaiting", "Denied"], label="Consent Status")
|
| 307 |
+
register_button = gr.Button("Register Patient")
|
| 308 |
+
register_output = gr.Textbox(label="Result")
|
| 309 |
+
register_button.click(
|
| 310 |
+
fn=register_patient,
|
| 311 |
+
inputs=[phone_input, email_input, language_input, consent_input],
|
| 312 |
+
outputs=register_output
|
| 313 |
+
)
|
| 314 |
+
|
| 315 |
+
with gr.Tab("Consent Form"):
|
| 316 |
+
consent_phone_input = gr.Textbox(label="Patient Phone Number", placeholder="+1234567890")
|
| 317 |
+
consent_method_input = gr.Dropdown(["SMS", "Email", "In-Person", "Phone"], label="Consent Method")
|
| 318 |
+
consent_button = gr.Button("Submit Consent")
|
| 319 |
+
consent_output = gr.Textbox(label="Result")
|
| 320 |
+
consent_button.click(
|
| 321 |
+
fn=submit_consent,
|
| 322 |
+
inputs=[consent_phone_input, consent_method_input],
|
| 323 |
+
outputs=consent_output
|
| 324 |
+
)
|
| 325 |
+
|
| 326 |
+
with gr.Tab("Follow-up Messaging"):
|
| 327 |
+
followup_phone_input = gr.Textbox(label="Patient Phone Number", placeholder="+1234567890")
|
| 328 |
+
message_template_input = gr.Textbox(label="Message Template", value="How are you feeling today?")
|
| 329 |
+
followup_date_input = gr.Textbox(label="Follow-up Date (YYYY-MM-DD)", value=date.today().isoformat())
|
| 330 |
+
followup_button = gr.Button("Schedule Follow-up")
|
| 331 |
+
followup_output = gr.Textbox(label="Result")
|
| 332 |
+
followup_button.click(
|
| 333 |
+
fn=schedule_followup,
|
| 334 |
+
inputs=[followup_phone_input, message_template_input, followup_date_input],
|
| 335 |
+
outputs=followup_output
|
| 336 |
+
)
|
| 337 |
+
|
| 338 |
+
with gr.Tab("Risk Dashboard"):
|
| 339 |
+
dashboard_button = gr.Button("Load Dashboard")
|
| 340 |
+
dashboard_table = gr.Dataframe(label="Symptom Logs")
|
| 341 |
+
high_risk_output = gr.Textbox(label="High-Risk Cases")
|
| 342 |
+
dashboard_button.click(
|
| 343 |
+
fn=view_risk_dashboard,
|
| 344 |
+
outputs=[dashboard_table, high_risk_output]
|
| 345 |
+
)
|
| 346 |
+
with gr.Row():
|
| 347 |
+
escalate_id_input = gr.Textbox(label="Patient ID (for escalation)")
|
| 348 |
+
escalate_response_input = gr.Textbox(label="Response Text")
|
| 349 |
+
escalate_button = gr.Button("Submit Case Escalation")
|
| 350 |
+
escalate_output = gr.Textbox(label="Result")
|
| 351 |
+
escalate_button.click(
|
| 352 |
+
fn=escribe_case,
|
| 353 |
+
inputs=[escalate_id_input, escalate_response_input],
|
| 354 |
+
outputs=escalate_output
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
with gr.Tab("Appointment Scheduling"):
|
| 358 |
+
appt_email_input = gr.Textbox(label="Patient Email", placeholder="patient@example.com")
|
| 359 |
+
event_type_input = gr.Textbox(label="Calendly Event Type UUID", placeholder="your_event_type_uuid")
|
| 360 |
+
appt_button = gr.Button("Schedule Appointment")
|
| 361 |
+
appt_output = gr.Textbox(label="Result")
|
| 362 |
+
appt_button.click(
|
| 363 |
+
fn=schedule_appointment,
|
| 364 |
+
inputs=[appt_email_input, event_type_input],
|
| 365 |
+
outputs=appt_output
|
| 366 |
+
)
|
| 367 |
+
|
| 368 |
+
with gr.Tab("Survey"):
|
| 369 |
+
survey_phone_input = gr.Textbox(label="Patient Phone Number", placeholder="+1234567890")
|
| 370 |
+
survey_question_input = gr.Textbox(label="Question", placeholder="How satisfied are you with your visit?")
|
| 371 |
+
survey_answer_input = gr.Textbox(label="Answer", lines=4)
|
| 372 |
+
survey_button = gr.Button("Submit Survey")
|
| 373 |
+
survey_output = gr.Textbox(label="Result")
|
| 374 |
+
survey_button.click(
|
| 375 |
+
fn=submit_survey,
|
| 376 |
+
inputs=[survey_phone_input, survey_question_input, survey_answer_input],
|
| 377 |
+
outputs=survey_output
|
| 378 |
+
)
|
| 379 |
|
| 380 |
+
# Launch Gradio app
|
| 381 |
if __name__ == "__main__":
|
| 382 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|