sadickam commited on
Commit
113e28e
·
verified ·
1 Parent(s): 3837303

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -63,7 +63,7 @@ iface1 = gr.Interface(
63
 
64
  This app has two analysis modules summarised below:
65
  - Single-Text-Prediction - Analyses text pasted in a text box and return IEQ prediction.
66
- - Multi-Text-Prediction - Analyses multiple rows of texts in an uploaded CSV file and returns a downloadable CSV file with IEQ prediction for each row of text.
67
 
68
  This app runs on a free server and may therefore not be suitable for analysing large CSV files.
69
  If you need assistance with analysing large CSV, do get in touch using the contact information in the Contact section.
@@ -72,7 +72,7 @@ iface1 = gr.Interface(
72
  <p>We would be happy to receive your feedback regarding this app. If you would also like to collaborate with us to explore some use cases for the model
73
  powering this app, we are happy to hear from you.</p>
74
 
75
- Dr Abdul-Manan Sadick - s.sadick@deakin.edu.au
76
  Dr Giorgia Chinazzo - giorgia.chinazzo@northwestern.edu
77
  ''')
78
 
@@ -189,8 +189,13 @@ def predict_from_csv(file, column_name, progress=gr.Progress()):
189
  fig (plotly.graph_objs.Figure): A histogram showing the frequency of each IEQ label.
190
  output_csv (gr.File): A downloadable CSV file containing the predictions.
191
  """
192
- # Read the CSV file
193
- df_docs = pd.read_csv(file)
 
 
 
 
 
194
 
195
  # Check if the specified column exists
196
  if column_name not in df_docs.columns:
@@ -349,7 +354,7 @@ def predict_from_csv(file, column_name, progress=gr.Progress()):
349
 
350
 
351
  # Define the input component
352
- file_input = gr.File(label="Upload CSV file here", show_label=True, file_types=[".csv"])
353
  column_name_input = gr.Textbox(label="Enter the column name containing the text to be analyzed", show_label=True)
354
 
355
  # Create the Gradio interface
@@ -357,12 +362,12 @@ iface3 = gr.Interface(fn=predict_from_csv,
357
  inputs=[file_input, column_name_input],
358
  outputs=[gr.Plot(label='Frequency of IEQs', show_label=True),
359
  gr.File(label='Download output CSV', show_label=True)],
360
- title="Multi-text Prediction (CVS)",
361
  description='**NOTE:** Please enter the column name containing the text to be analyzed.')
362
 
363
  # Create a tabbed interface
364
  demo = gr.TabbedInterface(interface_list=[iface1, iface2, iface3],
365
- tab_names=["General-App-Info", "Single-Text-Prediction", "Multi-Text-Prediction (CSV)"],
366
  title="Indoor Environmetal Quality (IEQ) Text Classifier App",
367
  theme='soft'
368
  )
 
63
 
64
  This app has two analysis modules summarised below:
65
  - Single-Text-Prediction - Analyses text pasted in a text box and return IEQ prediction.
66
+ - Multi-Text-Prediction - Analyses multiple rows of texts in an uploaded CSV or Excell file and returns a downloadable CSV file with IEQ prediction for each row of text.
67
 
68
  This app runs on a free server and may therefore not be suitable for analysing large CSV files.
69
  If you need assistance with analysing large CSV, do get in touch using the contact information in the Contact section.
 
72
  <p>We would be happy to receive your feedback regarding this app. If you would also like to collaborate with us to explore some use cases for the model
73
  powering this app, we are happy to hear from you.</p>
74
 
75
+ Dr Abdul-Manan Sadick - s.sadick@deakin.edu.au\n
76
  Dr Giorgia Chinazzo - giorgia.chinazzo@northwestern.edu
77
  ''')
78
 
 
189
  fig (plotly.graph_objs.Figure): A histogram showing the frequency of each IEQ label.
190
  output_csv (gr.File): A downloadable CSV file containing the predictions.
191
  """
192
+ # Read the CSV or Excel file
193
+ if file.endswith('.csv'):
194
+ df_docs = pd.read_csv(file)
195
+ elif file.endswith('.xls') or file.endswith('.xlsx'):
196
+ df_docs = pd.read_excel(file)
197
+ else:
198
+ raise gr.Error("Invalid file type. Please upload a CSV or Excel file.")
199
 
200
  # Check if the specified column exists
201
  if column_name not in df_docs.columns:
 
354
 
355
 
356
  # Define the input component
357
+ file_input = gr.File(label="Upload CSV or Excel file here", show_label=True, file_types=[".csv", ".xls", ".xlsx"])
358
  column_name_input = gr.Textbox(label="Enter the column name containing the text to be analyzed", show_label=True)
359
 
360
  # Create the Gradio interface
 
362
  inputs=[file_input, column_name_input],
363
  outputs=[gr.Plot(label='Frequency of IEQs', show_label=True),
364
  gr.File(label='Download output CSV', show_label=True)],
365
+ title="Multi-text Prediction",
366
  description='**NOTE:** Please enter the column name containing the text to be analyzed.')
367
 
368
  # Create a tabbed interface
369
  demo = gr.TabbedInterface(interface_list=[iface1, iface2, iface3],
370
+ tab_names=["General-App-Info", "Single-Text-Prediction", "Multi-Text-Prediction"],
371
  title="Indoor Environmetal Quality (IEQ) Text Classifier App",
372
  theme='soft'
373
  )