Spaces:
Sleeping
Sleeping
File size: 5,191 Bytes
5925eac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
import gradio as gr
import os
import json
import pandas as pd
from data_service import DataAssessmentService
from datetime import datetime
import gspread
from oauth2client.service_account import ServiceAccountCredentials
# Initialize service
service = DataAssessmentService(api_key=os.environ.get("OPENAI_API_KEY"))
# Department mapping from abbreviations to full names
DEPARTMENTS = {
"Executive Management": "บริหาร ผอ รอง ผู้ช่วย",
"Education Support": "สนับสนุนการศึกษา",
"Medicine": "MED",
"Cardiology": "Cardio",
"Gastroenterology": "GI",
"Medical Oncology": "Onco MED",
"Hematology": "Hematology",
"Operating Room": "OR",
"Surgery": "Sx",
"Orthopedics": "Ortho",
"Obstetrics and Gynecology": "OBgyne",
"Ophthalmology": "Oph",
"Ear, Nose, and Throat": "ENT",
"Anesthesiology": "Anes",
"Emergency Medicine & EMS": "ER and EMS",
"Pediatrics": "PED",
"Family Medicine & Preventive Medicine": "GP Fammed preventive med",
"Psychiatry": "Psych",
"Physical Medicine & Rehabilitation": "PM&R Physiotherapy",
"Pathology": "Patho",
"Radiology": "Xray",
"Radiation Oncology": "Onco radiology",
"Cyclotron": "Cyclotron",
"Inpatient Department": "IPD",
"Outpatient Department": "OPD",
"Pharmacy": "Pharmacy",
"Dentistry": "dentistry",
"Nutrition": "Nutrition",
"Medical Records": "เวชระเบียน",
"Finance": "การเงิน",
"Other": "Other"
}
# Frequency options
FREQUENCIES = ["One-time request", "Weekly", "Monthly"]
# Urgency options
URGENCY = ["Within a week", "Within a month", "Within a year"]
def save_to_sheet(data):
"""Save request data to Google Sheet"""
# TODO: Implement Google Sheets integration
pass
def process_request(name, employee_id, email, department, other_dept, request_details, frequency, urgency):
# Combine department info
final_department = other_dept if department == "Other" else department
# Current timestamp
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Process the request through GPT
result = service.assess_request(request_details)
# Prepare data for Google Sheets
sheet_data = {
"Timestamp": timestamp,
"Name": name,
"Employee ID": employee_id,
"Email": email,
"Department": final_department,
"Request Details": request_details,
"Frequency": frequency,
"Urgency": urgency,
"System Response": json.dumps(result, ensure_ascii=False)
}
# Save to Google Sheets
save_to_sheet(sheet_data)
# Return formatted result
return result
# Create Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# Hospital Data Request System")
gr.Markdown("Please fill in the following information to request data access.")
with gr.Row():
with gr.Column():
name = gr.Textbox(label="Full Name", placeholder="Enter your full name")
employee_id = gr.Textbox(label="Employee ID", placeholder="Enter your employee ID")
email = gr.Textbox(label="Email", placeholder="Enter your email for contact")
with gr.Row():
with gr.Column():
department = gr.Dropdown(
choices=list(DEPARTMENTS.keys()) + ["Other"],
label="Department",
info="Select your department"
)
other_dept = gr.Textbox(
label="Other Department",
placeholder="Specify your department if not in the list",
visible=False
)
# Show/hide other department textbox
department.change(
fn=lambda x: gr.update(visible=x=="Other"),
inputs=[department],
outputs=[other_dept]
)
with gr.Row():
request_details = gr.Textbox(
label="Request Details",
placeholder="Please describe in detail what data you need, including time period, specific parameters, etc.",
lines=5
)
with gr.Row():
with gr.Column():
frequency = gr.Dropdown(
choices=FREQUENCIES,
label="Request Frequency",
info="How often do you need this data?"
)
urgency = gr.Dropdown(
choices=URGENCY,
label="Urgency Level",
info="How urgent is your request?"
)
submit_btn = gr.Button("Submit Request")
output = gr.JSON(label="Analysis Result")
submit_btn.click(
fn=process_request,
inputs=[name, employee_id, email, department, other_dept,
request_details, frequency, urgency],
outputs=[output]
)
gr.Markdown("""
### Notes:
- Please provide detailed information about the data you need
- All communications will be sent to the provided email
- For urgent requests, please select appropriate urgency level
""")
if __name__ == "__main__":
demo.launch() |