Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"):
|