varshakolanu commited on
Commit
8e8e369
·
verified ·
1 Parent(s): 65b1b4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +218 -196
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import streamlit as st
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
- st.stop()
 
 
 
 
 
 
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
- # Streamlit App
162
- def main():
163
- st.set_page_config(page_title="AI-Powered Patient Follow-up Agent", layout="wide", initial_sidebar_state="expanded")
164
-
165
- # Custom CSS for attractive UI
166
- st.markdown("""
167
- <style>
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
- hf_client = HuggingFaceClient(HF_API_TOKEN)
179
- sf_client = SalesforceClient(SALESFORCE_BASE_URL, SALESFORCE_HEADERS)
180
- twilio_client = TwilioClient(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_PHONE)
181
- calendly_client = CalendlyClient(CALENDLY_API_TOKEN)
 
 
 
 
 
 
182
  except Exception as e:
183
- st.error(f"Failed to initialize clients: {str(e)}")
184
- logging.error(f"Client initialization failed: {str(e)}")
185
- st.stop()
186
-
187
- # Sidebar navigation
188
- pages = ["Patient Registration", "Consent Form", "Follow-up Messaging", "Risk Dashboard",
189
- "Appointment Scheduling", "Survey"]
190
- choice = st.sidebar.selectbox("Navigate", pages, key="nav_select")
191
-
192
- if choice == "Patient Registration":
193
- st.header("Patient Registration")
194
- with st.form("patient_form", clear_on_submit=True):
195
- name = f"PAT-{str(uuid.uuid4())[:6]}" # Auto-generated
196
- st.write(f"Patient ID: {name}")
197
- phone = st.text_input("Phone Number", placeholder="+1234567890")
198
- email = st.text_input("Email", placeholder="patient@example.com")
199
- language = st.selectbox("Language", ["English", "Spanish", "French"], key="patient_lang")
200
- consent_status = st.selectbox("Consent Status", ["Approved", "Awaiting", "Denied"], key="patient_consent")
201
- submit = st.form_submit_button("Register Patient")
202
- if submit and phone and email:
203
- patient_data = {
204
- "Name": name, "Phone__c": phone, "Email__c": email,
205
- "Language__c": language, "ConsentGiven__c": consent_status
206
- }
207
- patient_id = sf_client.create_record("Patient__c", patient_data)
208
- if patient_id:
209
- st.success(f"Patient {name} registered successfully!")
210
- logging.info(f"Registered patient: {name}")
211
- else:
212
- st.error("Failed to register patient.")
213
- logging.error("Failed to register patient.")
214
-
215
- elif choice == "Consent Form":
216
- st.header("Consent Form")
217
- with st.form("consent_form", clear_on_submit=True):
218
- patient_phone = st.text_input("Patient Phone Number", placeholder="+1234567890")
219
- method = st.selectbox("Consent Method", ["SMS", "Email", "In-Person", "Phone"], key="consent_method")
220
- submit = st.form_submit_button("Submit Consent")
221
- if submit and patient_phone:
222
- patients = sf_client.query_records(f"SELECT Id FROM Patient__c WHERE Phone__c = '{patient_phone}'")
223
- if patients:
224
- consent_data = {"Method__c": method, "GivenOn__c": date.today().isoformat()}
225
- consent_id = sf_client.create_record("Consent__c", consent_data)
226
- if consent_id:
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
- st.dataframe(df, use_container_width=True)
279
- st.bar_chart(df.groupby("Severity__c").size())
280
- for log in symptom_logs:
281
- if log["Severity__c"] == "High":
282
- st.warning(f"High Risk: Patient {log['Patient__c']} - {log['ResponseText__c']}")
283
- if st.button(f"Escalate Case for Patient {log['Patient__c']}", key=f"escalate_{log['Patient__c']}"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  case_data = {
285
- "RelatedPatient__c": log["Patient__c"], "Priority__c": "High",
286
- "Description__c": f"High-risk response: {log['ResponseText__c']}"
287
  }
288
- case_id = sf_client.create_record("Case__c", case_data)
289
- if case_id:
290
- st.success("Case created!")
291
- logging.info(f"Case created for patient: {log['Patient__c']}")
292
- else:
293
- st.error("Failed to create case.")
294
- logging.error("Failed to create Case__c.")
295
- else:
296
- st.info("No symptom logs available.")
297
- logging.info("No symptom logs found for dashboard.")
298
-
299
- elif choice == "Appointment Scheduling":
300
- st.header("Schedule Appointment")
301
- with st.form("appointment_form", clear_on_submit=True):
302
- patient_email = st.text_input("Patient Email", placeholder="patient@example.com")
303
- event_type_uuid = st.text_input("Calendly Event Type UUID", placeholder="your_event_type_uuid")
304
- submit = st.form_submit_button("Schedule Appointment")
305
- if submit and patient_email and event_type_uuid:
306
- event_time = calendly_client.create_event(patient_email, event_type_uuid)
307
- if event_time:
308
- appointment_data = {"DateTime__c": event_time, "Status__c": "Scheduled"}
309
- appointment_id = sf_client.create_record("Appointment__c", appointment_data)
310
- if appointment_id:
311
- st.success(f"Appointment scheduled for {event_time}!")
312
- logging.info(f"Appointment scheduled for {patient_email}")
313
- else:
314
- st.error("Failed to create appointment record.")
315
- logging.error("Failed to create Appointment__c.")
316
- else:
317
- st.error("Failed to schedule appointment.")
318
- logging.error("Failed to schedule Calendly event.")
319
-
320
- elif choice == "Survey":
321
- st.header("Patient Survey")
322
- with st.form("survey_form", clear_on_submit=True):
323
- patient_phone = st.text_input("Patient Phone Number", placeholder="+1234567890")
324
- question = st.text_input("Question", placeholder="How satisfied are you with your visit?")
325
- answer = st.text_area("Answer")
326
- submit = st.form_submit_button("Submit Survey")
327
- if submit and patient_phone and question and answer:
328
- patients = sf_client.query_records(f"SELECT Id, Language__c FROM Patient__c WHERE Phone__c = '{patient_phone}'")
329
- if patients:
330
- survey_data = {"Question__c": question, "Answer__c": answer}
331
- survey_id = sf_client.create_record("Survey__c", survey_data)
332
- if survey_id:
333
- analysis = hf_client.analyze_response(answer, patients[0]["Language__c"])
334
- if analysis:
335
- symptom_data = {
336
- "Patient__c": patients[0]["Id"], "ResponseText__c": answer,
337
- "RiskScore__c": analysis["risk_level"], "Severity__c": analysis["severity_score"],
338
- "Sentiment__c": analysis["sentiment_score"]
339
- }
340
- symptom_id = sf_client.create_record("SymptomLog__c", symptom_data)
341
- if symptom_id and analysis["risk_level"] == "High":
342
- case_data = {
343
- "RelatedPatient__c": patients[0]["Id"], "Priority__c": "High",
344
- "Description__c": f"High-risk survey response: {answer}"
345
- }
346
- sf_client.create_record("Case__c", case_data)
347
- st.success("Survey submitted and analyzed!")
348
- logging.info(f"Survey submitted for patient: {patients[0]['Id']}")
349
- else:
350
- st.error("Failed to analyze survey response.")
351
- logging.error("Failed to analyze survey response.")
352
- else:
353
- st.error("Failed to submit survey.")
354
- logging.error("Failed to create Survey__c.")
355
- else:
356
- st.error("Patient not found.")
357
- logging.error(f"Patient not found for phone: {patient_phone}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
 
 
359
  if __name__ == "__main__":
360
- main()
 
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)