yougandar commited on
Commit
3869fcc
·
verified ·
1 Parent(s): 5e695c0

Update add_reports.py

Browse files
Files changed (1) hide show
  1. add_reports.py +5 -6
add_reports.py CHANGED
@@ -21,7 +21,7 @@ def load_patient_data():
21
  return pd.DataFrame(columns=["Patient ID", "Patient Name", "Age", "Gender", "Contact Number"])
22
  except pd.errors.ParserError as e:
23
  print(f"Error parsing the CSV file: {e}")
24
- return pd.DataFrame(columns(["Patient ID", "Patient Name", "Age", "Gender", "Contact Number"]))
25
  except ValueError as e:
26
  print(f"Error with CSV columns: {e}")
27
  return pd.DataFrame(columns=["Patient ID", "Patient Name", "Age", "Gender", "Contact Number"])
@@ -71,15 +71,14 @@ def handle_file_upload(patient_id, file):
71
  return "Error: No file uploaded"
72
 
73
  # Use the original file name
74
- original_filename = file.name # Gradio provides the original file name through the file object
75
  sanitized_filename = original_filename.replace(" ", "_").lower() # Sanitize file name for file system
76
  file_name = f"report_{patient_id}_{sanitized_filename}"
77
  file_path = f"reports/{file_name}"
78
  os.makedirs(os.path.dirname(file_path), exist_ok=True)
79
 
80
- # Write the binary content to the file
81
- with open(file_path, "wb") as f:
82
- f.write(file.read()) # Write the binary content to the file
83
 
84
  # Load existing reports data
85
  reports_df = load_reports_data()
@@ -121,7 +120,7 @@ def gradio_interface():
121
  )
122
 
123
  # File upload for report
124
- file_upload = gr.File(label="Upload Report (PDF or JPG)", type="file")
125
 
126
  # Button to submit the report
127
  submit_button = gr.Button("Submit")
 
21
  return pd.DataFrame(columns=["Patient ID", "Patient Name", "Age", "Gender", "Contact Number"])
22
  except pd.errors.ParserError as e:
23
  print(f"Error parsing the CSV file: {e}")
24
+ return pd.DataFrame(columns=["Patient ID", "Patient Name", "Age", "Gender", "Contact Number"])
25
  except ValueError as e:
26
  print(f"Error with CSV columns: {e}")
27
  return pd.DataFrame(columns=["Patient ID", "Patient Name", "Age", "Gender", "Contact Number"])
 
71
  return "Error: No file uploaded"
72
 
73
  # Use the original file name
74
+ original_filename = os.path.basename(file) # Get the base name of the uploaded file
75
  sanitized_filename = original_filename.replace(" ", "_").lower() # Sanitize file name for file system
76
  file_name = f"report_{patient_id}_{sanitized_filename}"
77
  file_path = f"reports/{file_name}"
78
  os.makedirs(os.path.dirname(file_path), exist_ok=True)
79
 
80
+ # Copy the uploaded file to the destination path
81
+ os.rename(file, file_path)
 
82
 
83
  # Load existing reports data
84
  reports_df = load_reports_data()
 
120
  )
121
 
122
  # File upload for report
123
+ file_upload = gr.File(label="Upload Report (PDF or JPG)", type="filepath")
124
 
125
  # Button to submit the report
126
  submit_button = gr.Button("Submit")