Spaces:
Sleeping
Sleeping
# app.py | |
import gradio as gr | |
import os | |
from data_service import DataAssessmentService | |
import json | |
# Initialize service | |
service = DataAssessmentService(api_key=os.environ.get("OPENAI_API_KEY")) | |
def process_request(request_text: str) -> str: | |
"""Process the data request and return formatted results""" | |
try: | |
result = service.assess_request(request_text) | |
return json.dumps(result, indent=2) | |
except Exception as e: | |
return json.dumps({ | |
"status": "error", | |
"message": str(e) | |
}, indent=2) | |
demo_text = """Example requests: | |
1. "Show me OPD patients from January 2024, including their diagnoses and waiting times" | |
2. "Get all emergency surgeries from last month with their durations and costs" | |
3. "List top 100 diagnoses from pediatric clinic in 2023" | |
""" | |
# Create Gradio interface | |
with gr.Blocks() as demo: | |
gr.Markdown("# Hospital Data Assessment Service") | |
gr.Markdown("Enter your data request in English to find available reports and data sources.") | |
with gr.Row(): | |
request_input = gr.Textbox( | |
label="Data Request", | |
placeholder="Example: I need information about OPD patients who visited in January 2024, including their diagnoses and treating doctors", | |
lines=3 | |
) | |
with gr.Row(): | |
submit_btn = gr.Button("Analyze Request") | |
clear_btn = gr.Button("Clear") | |
with gr.Row(): | |
output = gr.Textbox( | |
label="Analysis Result", | |
lines=10, | |
show_copy_button=True | |
) | |
with gr.Accordion("Example Requests", open=False): | |
gr.Markdown(demo_text) | |
submit_btn.click( | |
fn=process_request, | |
inputs=[request_input], | |
outputs=[output] | |
) | |
clear_btn.click( | |
fn=lambda: (None, None), | |
inputs=[], | |
outputs=[request_input, output] | |
) | |
gr.Markdown(""" | |
### Notes: | |
- Please provide specific date ranges when requesting data | |
- The system will check availability across OPD, IPD, OR, and other hospital systems | |
- Results will show which reports are immediately available and which need additional processing | |
""") | |
if __name__ == "__main__": | |
demo.launch() |