| import gradio as gr |
| import csv |
| import os |
|
|
| FILE = "reports.csv" |
|
|
| def init_file(): |
| if not os.path.exists(FILE): |
| with open(FILE, 'w', newline='') as file: |
| writer = csv.writer(file) |
| writer.writerow(["Report ID", "Patient", "Report Type", "Details"]) |
|
|
| def write_report(patient, rtype, details): |
| init_file() |
| with open(FILE, 'r') as file: |
| rows = list(csv.reader(file)) |
| idx = len(rows) |
| with open(FILE, 'a', newline='') as file: |
| writer = csv.writer(file) |
| writer.writerow([idx, patient, rtype, details]) |
| return f"✅ Report #{idx} added for {patient}" |
|
|
| def gradio_interface(): |
| init_file() |
| with gr.Blocks() as demo: |
| gr.Markdown("## 📤 Add Medical Report") |
| pat = gr.Textbox(label="Patient") |
| typ = gr.Textbox(label="Report Type") |
| det = gr.Textbox(label="Details") |
| res = gr.Textbox(label="Result") |
| gr.Button("Upload").click(fn=write_report, inputs=[pat, typ, det], outputs=res) |
| return demo |