File size: 1,534 Bytes
1d15d90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
966379a
 
 
 
 
 
01d35e5
966379a
 
 
 
 
 
1d15d90
 
 
 
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
import gradio as gr
import csv
import os

# Define the path for the CSV file where registration data will be stored
csv_file_path = "registered_patients.csv"

# Create the CSV file if it doesn't exist and add the headers
if not os.path.exists(csv_file_path):
    with open(csv_file_path, mode='w', newline='') as file:
        writer = csv.writer(file)
        writer.writerow(["Patient Name", "Age", "Contact Number"])

# Function to handle the registration and store the data into the CSV file
def register_patient(patient_name, age, contact_number):
    # Open the CSV file in append mode and write the new patient data
    with open(csv_file_path, mode='a', newline='') as file:
        writer = csv.writer(file)
        writer.writerow([patient_name, age, contact_number])
    return f"Patient {patient_name} registered successfully!"

# Define the Gradio interface using the updated components
with gr.Blocks() as interface:
    gr.Markdown("## Patient Registration")
    
    with gr.Row():
        patient_name = gr.Textbox(label="Patient Name", placeholder="Enter patient name")
        age = gr.Number(label="Age")  # Removed 'placeholder' argument
        contact_number = gr.Textbox(label="Contact Number", placeholder="Enter contact number")
    
    output = gr.Textbox(label="Registration Status")
    
    register_button = gr.Button("Register")
    register_button.click(register_patient, inputs=[patient_name, age, contact_number], outputs=output)

# Launch the app
if __name__ == "__main__":
    interface.launch()