RathodHarish commited on
Commit
0a29a93
·
verified ·
1 Parent(s): 39e885a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -12,14 +12,14 @@ def upload_csv(file):
12
  try:
13
  # Check if a file was actually uploaded
14
  if file is None:
15
- return (["All"], ["All"]), "No file uploaded. Please upload a CSV file."
16
 
17
  # Read the CSV file
18
  df = pd.read_csv(file.name)
19
 
20
  # Check if the DataFrame is empty
21
  if df.empty:
22
- return (["All"], ["All"]), "The uploaded CSV file is empty."
23
 
24
  # Define required columns
25
  required_columns = {'DeviceID', 'Lab', 'Type', 'Timestamp', 'Status', 'UsageCount'}
@@ -27,16 +27,16 @@ def upload_csv(file):
27
  # Check if all required columns are present
28
  if not required_columns.issubset(df.columns):
29
  missing_cols = required_columns - set(df.columns)
30
- return (["All"], ["All"]), f"CSV is missing required columns: {', '.join(missing_cols)}"
31
 
32
  # Extract unique values for dropdowns
33
  labs = ['All'] + sorted(df['Lab'].dropna().unique().tolist())
34
  types = ['All'] + sorted(df['Type'].dropna().unique().tolist())
35
 
36
- return (labs, types), ""
37
  except Exception as e:
38
  # Handle any other errors (e.g., file not readable, invalid CSV format)
39
- return (["All"], ["All"]), f"Failed to load CSV: {str(e)}"
40
 
41
  def filter_and_plot(selected_lab, selected_type):
42
  global df
@@ -124,8 +124,8 @@ with gr.Blocks() as demo:
124
  download_btn = gr.Button("Download PDF Summary")
125
  error_box = gr.Textbox(label="Status/Error Message", visible=True, interactive=False)
126
 
127
- # Connect the components
128
- csv_input.change(fn=upload_csv, inputs=csv_input, outputs=[(lab_dropdown, type_dropdown), error_box])
129
  lab_dropdown.change(fn=filter_and_plot, inputs=[lab_dropdown, type_dropdown], outputs=plot_output)
130
  type_dropdown.change(fn=filter_and_plot, inputs=[lab_dropdown, type_dropdown], outputs=plot_output)
131
  download_btn.click(fn=download_pdf, inputs=[lab_dropdown, type_dropdown], outputs=gr.File(label="Download PDF"))
 
12
  try:
13
  # Check if a file was actually uploaded
14
  if file is None:
15
+ return ["All"], ["All"], "No file uploaded. Please upload a CSV file."
16
 
17
  # Read the CSV file
18
  df = pd.read_csv(file.name)
19
 
20
  # Check if the DataFrame is empty
21
  if df.empty:
22
+ return ["All"], ["All"], "The uploaded CSV file is empty."
23
 
24
  # Define required columns
25
  required_columns = {'DeviceID', 'Lab', 'Type', 'Timestamp', 'Status', 'UsageCount'}
 
27
  # Check if all required columns are present
28
  if not required_columns.issubset(df.columns):
29
  missing_cols = required_columns - set(df.columns)
30
+ return ["All"], ["All"], f"CSV is missing required columns: {', '.join(missing_cols)}"
31
 
32
  # Extract unique values for dropdowns
33
  labs = ['All'] + sorted(df['Lab'].dropna().unique().tolist())
34
  types = ['All'] + sorted(df['Type'].dropna().unique().tolist())
35
 
36
+ return labs, types, ""
37
  except Exception as e:
38
  # Handle any other errors (e.g., file not readable, invalid CSV format)
39
+ return ["All"], ["All"], f"Failed to load CSV: {str(e)}"
40
 
41
  def filter_and_plot(selected_lab, selected_type):
42
  global df
 
124
  download_btn = gr.Button("Download PDF Summary")
125
  error_box = gr.Textbox(label="Status/Error Message", visible=True, interactive=False)
126
 
127
+ # Connect the components - Fixed the outputs argument
128
+ csv_input.change(fn=upload_csv, inputs=csv_input, outputs=[lab_dropdown, type_dropdown, error_box])
129
  lab_dropdown.change(fn=filter_and_plot, inputs=[lab_dropdown, type_dropdown], outputs=plot_output)
130
  type_dropdown.change(fn=filter_and_plot, inputs=[lab_dropdown, type_dropdown], outputs=plot_output)
131
  download_btn.click(fn=download_pdf, inputs=[lab_dropdown, type_dropdown], outputs=gr.File(label="Download PDF"))