yougandar SuriRaja commited on
Commit
1ab5b59
·
verified ·
1 Parent(s): 85e6fed

Update app.py (#3)

Browse files

- Update app.py (0bd84ca788d4880c3c6df422b2a06e44cac46110)


Co-authored-by: Suri <SuriRaja@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +27 -48
app.py CHANGED
@@ -1,52 +1,31 @@
1
- import sys
 
2
  import os
3
 
4
- # Add the current directory to the Python path
5
- sys.path.append(os.path.dirname(os.path.abspath(__file__)))
6
-
7
- # Import models
8
- from models.user_model import User
9
- from models.appointment_model import Appointment
10
- from models.prescription_model import Prescription
11
- from models.report_model import Report
12
- from models.medical_history_model import MedicalHistory
13
-
14
- # Define the directory for CSV files
15
- DATA_DIR = 'data'
16
-
17
- # Define paths to each CSV file
18
- USER_CSV = os.path.join(DATA_DIR, 'users.csv')
19
- APPOINTMENT_CSV = os.path.join(DATA_DIR, 'appointments.csv')
20
- PRESCRIPTION_CSV = os.path.join(DATA_DIR, 'prescriptions.csv')
21
- REPORT_CSV = os.path.join(DATA_DIR, 'reports.csv')
22
- MEDICAL_HISTORY_CSV = os.path.join(DATA_DIR, 'medical_history.csv')
23
-
24
- def load_all_data():
25
- # Load data from each model's CSV file
26
- users = User.load_from_csv(USER_CSV)
27
- appointments = Appointment.load_from_csv(APPOINTMENT_CSV)
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
- main()
 
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()