Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,8 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
CSV_FILE =
|
| 7 |
|
| 8 |
# Initialize the CSV file if it does not exist
|
| 9 |
if not os.path.exists(CSV_FILE):
|
|
@@ -26,16 +26,9 @@ def register_patient(name, age, phone):
|
|
| 26 |
# Save updated data
|
| 27 |
with open(CSV_FILE, 'w') as file:
|
| 28 |
df.to_csv(file, index=False)
|
| 29 |
-
file.flush()
|
| 30 |
-
os.fsync(file.fileno()) # Force writing to disk
|
| 31 |
-
|
| 32 |
-
# Additional logging to check if write was successful
|
| 33 |
-
print(f"Data successfully written to {CSV_FILE}")
|
| 34 |
|
| 35 |
return f"Patient {name} with ID {new_id} registered successfully!"
|
| 36 |
except Exception as e:
|
| 37 |
-
# Return error message and print stack trace for debugging
|
| 38 |
-
print(f"An error occurred: {e}")
|
| 39 |
return f"An error occurred: {e}"
|
| 40 |
|
| 41 |
# Define Gradio interface
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Use /tmp directory for Hugging Face Spaces
|
| 6 |
+
CSV_FILE = "/tmp/patients.csv"
|
| 7 |
|
| 8 |
# Initialize the CSV file if it does not exist
|
| 9 |
if not os.path.exists(CSV_FILE):
|
|
|
|
| 26 |
# Save updated data
|
| 27 |
with open(CSV_FILE, 'w') as file:
|
| 28 |
df.to_csv(file, index=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
return f"Patient {name} with ID {new_id} registered successfully!"
|
| 31 |
except Exception as e:
|
|
|
|
|
|
|
| 32 |
return f"An error occurred: {e}"
|
| 33 |
|
| 34 |
# Define Gradio interface
|