Ginidu2003 commited on
Commit
8ac79b0
Β·
verified Β·
1 Parent(s): fec7c1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -60,10 +60,16 @@ def classify_csv(file):
60
 
61
  output_file = "output.csv"
62
  df.to_csv(output_file, index=False)
63
-
64
- return f"βœ… Success! Classified {len(df)} rows", output_file
 
 
 
 
65
  except Exception as e:
66
- return f"❌ Error: {str(e)}", None
 
 
67
 
68
  # ====================== Q&A FUNCTION ======================
69
  def answer_question(news_content, question):
@@ -89,11 +95,17 @@ with gr.Blocks(title="Daily Mirror News Classifier") as demo:
89
  classify_btn = gr.Button("πŸš€ Classify News", variant="primary")
90
  output_text = gr.Textbox(label="Status")
91
  output_file = gr.File(label="Download output.csv")
 
 
 
 
 
 
92
 
93
  classify_btn.click(
94
  fn=classify_csv,
95
  inputs=file_input,
96
- outputs=[output_text, output_file]
97
  )
98
 
99
  with gr.Tab("❓ Question Answering"):
 
60
 
61
  output_file = "output.csv"
62
  df.to_csv(output_file, index=False)
63
+
64
+ # Count categories
65
+ category_counts = df['class'].value_counts().reset_index()
66
+ category_counts.columns = ["Category", "Count"]
67
+
68
+ return f"βœ… Success! Classified {len(df)} rows", output_file, category_counts
69
  except Exception as e:
70
+ return f"❌ Error: {str(e)}", None, None
71
+
72
+
73
 
74
  # ====================== Q&A FUNCTION ======================
75
  def answer_question(news_content, question):
 
95
  classify_btn = gr.Button("πŸš€ Classify News", variant="primary")
96
  output_text = gr.Textbox(label="Status")
97
  output_file = gr.File(label="Download output.csv")
98
+ bar_chart = gr.BarPlot(
99
+ label="Category Distribution",
100
+ x="Category",
101
+ y="Count",
102
+ vertical=True
103
+ )
104
 
105
  classify_btn.click(
106
  fn=classify_csv,
107
  inputs=file_input,
108
+ outputs=[output_text, output_file,bar_chart]
109
  )
110
 
111
  with gr.Tab("❓ Question Answering"):