Spaces:
Runtime error
Runtime error
Update app.py
#3
by SuriRaja - opened
app.py
CHANGED
|
@@ -1,52 +1,31 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
import os
|
| 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 |
-
prescriptions = Prescription.load_from_csv(PRESCRIPTION_CSV)
|
| 29 |
-
reports = Report.load_from_csv(REPORT_CSV)
|
| 30 |
-
medical_history = MedicalHistory.load_from_csv(MEDICAL_HISTORY_CSV)
|
| 31 |
-
|
| 32 |
-
# Print out the loaded data for verification
|
| 33 |
-
print(f"Loaded {len(users)} users.")
|
| 34 |
-
print(f"Loaded {len(appointments)} appointments.")
|
| 35 |
-
print(f"Loaded {len(prescriptions)} prescriptions.")
|
| 36 |
-
print(f"Loaded {len(reports)} reports.")
|
| 37 |
-
print(f"Loaded {len(medical_history)} medical history records.")
|
| 38 |
-
|
| 39 |
-
# Return all the data for further processing
|
| 40 |
-
return users, appointments, prescriptions, reports, medical_history
|
| 41 |
-
|
| 42 |
-
def main():
|
| 43 |
-
print("Initializing MediConsult App...")
|
| 44 |
-
|
| 45 |
-
# Load all data from CSV files
|
| 46 |
-
users, appointments, prescriptions, reports, medical_history = load_all_data()
|
| 47 |
-
|
| 48 |
-
# Additional logic to handle the application workflow
|
| 49 |
-
# For example, managing user authentication, processing appointment requests, etc.
|
| 50 |
|
| 51 |
if __name__ == "__main__":
|
| 52 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Define the upload directory relative to the app's location
|
| 6 |
+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 7 |
+
UPLOAD_DIR = BASE_DIR
|
| 8 |
+
|
| 9 |
+
def upload_file(file):
|
| 10 |
+
try:
|
| 11 |
+
# Save the uploaded file to the base directory
|
| 12 |
+
file_path = os.path.join(UPLOAD_DIR, file.name)
|
| 13 |
+
with open(file_path, "wb") as f:
|
| 14 |
+
f.write(file.read())
|
| 15 |
+
|
| 16 |
+
# Read the CSV file and return the first few rows as a preview
|
| 17 |
+
df = pd.read_csv(file_path)
|
| 18 |
+
return df.head().to_html()
|
| 19 |
+
except Exception as e:
|
| 20 |
+
return str(e)
|
| 21 |
+
|
| 22 |
+
iface = gr.Interface(
|
| 23 |
+
fn=upload_file,
|
| 24 |
+
inputs=gr.inputs.File(label="Upload CSV File"),
|
| 25 |
+
outputs="html",
|
| 26 |
+
title="CSV File Uploader",
|
| 27 |
+
description="Upload a CSV file and preview the first few rows."
|
| 28 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
+
iface.launch()
|