simondh commited on
Commit
3aa5a3f
·
1 Parent(s): 69e1e94

improve layout

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -58,6 +58,10 @@ def update_api_key(api_key):
58
 
59
  def process_file(file, text_columns, categories, classifier_type, show_explanations):
60
  """Process the uploaded file and classify text data"""
 
 
 
 
61
  try:
62
  # Load data from file
63
  if isinstance(file, str):
@@ -358,14 +362,19 @@ with gr.Blocks(title="Text Classification System") as demo:
358
 
359
  # Function to show results after processing
360
  def show_results(df, validation_report):
 
361
  if df is None:
362
- return gr.Row(visible=False), gr.File(visible=False), gr.File(visible=False), gr.Dataframe(visible=False)
 
 
 
 
363
 
364
  # Export to both formats
365
  csv_path = export_results(df, "csv")
366
  excel_path = export_results(df, "excel")
367
 
368
- return gr.Row(visible=True), gr.File(value=csv_path, visible=True), gr.File(value=excel_path, visible=True), gr.Dataframe(value=df, visible=True)
369
 
370
  # Function to suggest a new category
371
  def suggest_new_category(file, current_categories, text_columns):
@@ -540,13 +549,17 @@ with gr.Blocks(title="Text Classification System") as demo:
540
  )
541
 
542
  process_button.click(
 
 
 
 
543
  process_file,
544
  inputs=[file_input, text_column, categories, classifier_type, show_explanations],
545
  outputs=[results_df, validation_output]
546
  ).then(
547
  show_results,
548
  inputs=[results_df, validation_output],
549
- outputs=[results_row, csv_download, excel_download, results_df]
550
  ).then(
551
  visualize_results,
552
  inputs=[results_df, text_column],
 
58
 
59
  def process_file(file, text_columns, categories, classifier_type, show_explanations):
60
  """Process the uploaded file and classify text data"""
61
+ # Initialize result_df and validation_report
62
+ result_df = None
63
+ validation_report = None
64
+
65
  try:
66
  # Load data from file
67
  if isinstance(file, str):
 
362
 
363
  # Function to show results after processing
364
  def show_results(df, validation_report):
365
+ """Show the results after processing"""
366
  if df is None:
367
+ return gr.Row(visible=False), gr.File(visible=False), gr.File(visible=False), gr.Dataframe(visible=False), gr.Dataframe(visible=False)
368
+
369
+ # Sort by category if it exists
370
+ if "Category" in df.columns:
371
+ df = df.sort_values("Category")
372
 
373
  # Export to both formats
374
  csv_path = export_results(df, "csv")
375
  excel_path = export_results(df, "excel")
376
 
377
+ return gr.Row(visible=True), gr.File(value=csv_path, visible=True), gr.File(value=excel_path, visible=True), gr.Dataframe(value=df, visible=True), gr.Dataframe(value=df, visible=True)
378
 
379
  # Function to suggest a new category
380
  def suggest_new_category(file, current_categories, text_columns):
 
549
  )
550
 
551
  process_button.click(
552
+ lambda: gr.Dataframe(visible=True),
553
+ inputs=[],
554
+ outputs=[results_df]
555
+ ).then(
556
  process_file,
557
  inputs=[file_input, text_column, categories, classifier_type, show_explanations],
558
  outputs=[results_df, validation_output]
559
  ).then(
560
  show_results,
561
  inputs=[results_df, validation_output],
562
+ outputs=[results_row, csv_download, excel_download, results_df, original_df]
563
  ).then(
564
  visualize_results,
565
  inputs=[results_df, text_column],