Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,10 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Path to CSV file in the root directory of your project
|
| 6 |
CSV_FILE = "patients.csv"
|
|
@@ -8,7 +12,11 @@ CSV_FILE = "patients.csv"
|
|
| 8 |
# Initialize the CSV file if it does not exist
|
| 9 |
if not os.path.exists(CSV_FILE):
|
| 10 |
df = pd.DataFrame(columns=["Patient ID", "Patient Name", "Age", "Phone Number"])
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Function to handle registration
|
| 14 |
def register_patient(name, age, phone):
|
|
@@ -29,8 +37,10 @@ def register_patient(name, age, phone):
|
|
| 29 |
file.flush()
|
| 30 |
os.fsync(file.fileno()) # Ensure data is written to disk
|
| 31 |
|
|
|
|
| 32 |
return f"Patient {name} with ID {new_id} registered successfully!"
|
| 33 |
except Exception as e:
|
|
|
|
| 34 |
return f"An error occurred: {e}"
|
| 35 |
|
| 36 |
# Define Gradio interface
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
+
import logging
|
| 5 |
+
|
| 6 |
+
# Set up logging
|
| 7 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 8 |
|
| 9 |
# Path to CSV file in the root directory of your project
|
| 10 |
CSV_FILE = "patients.csv"
|
|
|
|
| 12 |
# Initialize the CSV file if it does not exist
|
| 13 |
if not os.path.exists(CSV_FILE):
|
| 14 |
df = pd.DataFrame(columns=["Patient ID", "Patient Name", "Age", "Phone Number"])
|
| 15 |
+
try:
|
| 16 |
+
df.to_csv(CSV_FILE, index=False)
|
| 17 |
+
logging.info(f"Created new CSV file at {CSV_FILE}")
|
| 18 |
+
except Exception as e:
|
| 19 |
+
logging.error(f"Failed to create CSV file: {e}")
|
| 20 |
|
| 21 |
# Function to handle registration
|
| 22 |
def register_patient(name, age, phone):
|
|
|
|
| 37 |
file.flush()
|
| 38 |
os.fsync(file.fileno()) # Ensure data is written to disk
|
| 39 |
|
| 40 |
+
logging.info(f"Successfully registered patient {name} with ID {new_id}")
|
| 41 |
return f"Patient {name} with ID {new_id} registered successfully!"
|
| 42 |
except Exception as e:
|
| 43 |
+
logging.error(f"An error occurred while registering patient: {e}")
|
| 44 |
return f"An error occurred: {e}"
|
| 45 |
|
| 46 |
# Define Gradio interface
|