Update app.py
Browse files
app.py
CHANGED
|
@@ -12,20 +12,23 @@ if not os.path.exists(CSV_FILE):
|
|
| 12 |
|
| 13 |
# Function to handle registration
|
| 14 |
def register_patient(name, age, phone):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# Define Gradio interface
|
| 31 |
with gr.Blocks() as demo:
|
|
|
|
| 12 |
|
| 13 |
# Function to handle registration
|
| 14 |
def register_patient(name, age, phone):
|
| 15 |
+
try:
|
| 16 |
+
# Load existing data
|
| 17 |
+
df = pd.read_csv(CSV_FILE)
|
| 18 |
+
|
| 19 |
+
# Generate new patient ID
|
| 20 |
+
new_id = len(df) + 1
|
| 21 |
+
|
| 22 |
+
# Append new patient data
|
| 23 |
+
new_data = pd.DataFrame([[new_id, name, age, phone]], columns=["Patient ID", "Patient Name", "Age", "Phone Number"])
|
| 24 |
+
df = pd.concat([df, new_data], ignore_index=True)
|
| 25 |
+
|
| 26 |
+
# Save updated data
|
| 27 |
+
df.to_csv(CSV_FILE, index=False)
|
| 28 |
+
|
| 29 |
+
return f"Patient {name} with ID {new_id} registered successfully!"
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return f"An error occurred: {e}"
|
| 32 |
|
| 33 |
# Define Gradio interface
|
| 34 |
with gr.Blocks() as demo:
|