| import gradio as gr |
| import csv |
| import os |
|
|
| FILE = "consultations.csv" |
|
|
| def init_file(): |
| if not os.path.exists(FILE): |
| with open(FILE, 'w', newline='') as file: |
| writer = csv.writer(file) |
| writer.writerow(["ID", "Doctor", "Patient", "Notes"]) |
|
|
| def write_data(doctor, patient, notes): |
| 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, doctor, patient, notes]) |
| return f"✅ Consultation #{idx} saved." |
|
|
| def gradio_interface(): |
| init_file() |
| with gr.Blocks() as demo: |
| gr.Markdown("## 💬 Add Consultation") |
| doc = gr.Textbox(label="Doctor") |
| pat = gr.Textbox(label="Patient") |
| note = gr.Textbox(label="Notes") |
| result = gr.Textbox(label="Result") |
| gr.Button("Save").click(fn=write_data, inputs=[doc, pat, note], outputs=result) |
| return demo |