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()