trttung1610 commited on
Commit
88f122c
·
1 Parent(s): 56bc79e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -139,6 +139,9 @@ def process_file(docx):
139
  return pie_chart_name, excel_file_path
140
 
141
  def analyze_file(file, sentence):
 
 
 
142
  if file and sentence:
143
  # Both file and sentence inputs are provided
144
  # Process the uploaded file and generate the output files
@@ -156,7 +159,7 @@ def analyze_file(file, sentence):
156
  score_formatted = "{:.2f}".format(score)
157
  output_text += f"{label}: {score_formatted}\n"
158
 
159
- return excel_file_path, pie_chart_name, output_text
160
 
161
  elif sentence:
162
  # Only sentence input is provided
@@ -171,24 +174,28 @@ def analyze_file(file, sentence):
171
  for label, score in zip(label_names, results):
172
  score_formatted = "{:.2f}".format(score)
173
  output_text += f"{label}: {score_formatted}\n"
 
 
 
 
 
 
174
 
175
- return excel_file_path, pie_chart_name, output_text
176
  elif file:
177
  # Only file input is provided
178
  # Process the uploaded file and generate the output files
179
  pie_chart_name, excel_file_path = process_file(file.name)
180
 
181
  # Return the file paths for the pie chart and excel file
182
- return excel_file_path, pie_chart_name, None
183
 
184
  inputs = [
185
- gr.inputs.File(label="Select File Docx (Word) for Analysis"),
186
  gr.inputs.Textbox(label="Enter Text")
187
  ]
188
  outputs = [
189
  gr.outputs.File(label="Analysis Result Excel"),
190
  gr.outputs.Image(type="filepath", label="Analysis Metrics"),
191
- gr.outputs.Textbox(label="Analysis Result")
192
  ]
193
 
194
 
@@ -203,4 +210,4 @@ interface = gr.Interface(
203
 
204
 
205
  if __name__ == "__main__":
206
- interface.launch()
 
139
  return pie_chart_name, excel_file_path
140
 
141
  def analyze_file(file, sentence):
142
+ excel_file_path = None
143
+ pie_chart_name = None
144
+
145
  if file and sentence:
146
  # Both file and sentence inputs are provided
147
  # Process the uploaded file and generate the output files
 
159
  score_formatted = "{:.2f}".format(score)
160
  output_text += f"{label}: {score_formatted}\n"
161
 
162
+ return excel_file_path, pie_chart_name
163
 
164
  elif sentence:
165
  # Only sentence input is provided
 
174
  for label, score in zip(label_names, results):
175
  score_formatted = "{:.2f}".format(score)
176
  output_text += f"{label}: {score_formatted}\n"
177
+
178
+ # Generate the pie chart and excel file
179
+ pie_chart_name = generate_pie_chart(pd.DataFrame([results], columns=['Negative', 'Neutral', 'Positive']))
180
+ excel_file_path = generate_excel_file(pd.DataFrame([results], columns=['Negative', 'Neutral', 'Positive']))
181
+
182
+ return excel_file_path, pie_chart_name
183
 
 
184
  elif file:
185
  # Only file input is provided
186
  # Process the uploaded file and generate the output files
187
  pie_chart_name, excel_file_path = process_file(file.name)
188
 
189
  # Return the file paths for the pie chart and excel file
190
+ return excel_file_path, pie_chart_name
191
 
192
  inputs = [
193
+ gr.inputs.File(label="Select File for Analysis"),
194
  gr.inputs.Textbox(label="Enter Text")
195
  ]
196
  outputs = [
197
  gr.outputs.File(label="Analysis Result Excel"),
198
  gr.outputs.Image(type="filepath", label="Analysis Metrics"),
 
199
  ]
200
 
201
 
 
210
 
211
 
212
  if __name__ == "__main__":
213
+ interface.launch(share=True)