Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,53 +1,47 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
from
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
gr.
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
title="E-Consultation Sentiment Analysis",
|
| 49 |
-
description="Enter a comment/suggestion. The system predicts sentiment, generates a summary, and visualizes keywords."
|
| 50 |
-
)
|
| 51 |
-
|
| 52 |
-
if __name__ == "__main__":
|
| 53 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from pipeline import process_comment
|
| 4 |
+
|
| 5 |
+
def analyze_single(text):
|
| 6 |
+
sentiment, summary, wc_img = process_comment(text)
|
| 7 |
+
result = f"**Label:** {sentiment['label']} | **Score:** {sentiment['score']:.2f}"
|
| 8 |
+
return result, summary, wc_img
|
| 9 |
+
|
| 10 |
+
def analyze_batch(file):
|
| 11 |
+
df = pd.read_csv(file.name)
|
| 12 |
+
results = []
|
| 13 |
+
summaries = []
|
| 14 |
+
combined_text = ""
|
| 15 |
+
|
| 16 |
+
for comment in df["comment"]:
|
| 17 |
+
sentiment, summary, _ = process_comment(comment)
|
| 18 |
+
results.append(f"{sentiment['label']} ({sentiment['score']:.2f})")
|
| 19 |
+
summaries.append(summary)
|
| 20 |
+
combined_text += " " + comment
|
| 21 |
+
|
| 22 |
+
# Generate one big word cloud for all comments
|
| 23 |
+
_, _, wc_img = process_comment(combined_text)
|
| 24 |
+
|
| 25 |
+
df["Sentiment"] = results
|
| 26 |
+
df["Summary"] = summaries
|
| 27 |
+
|
| 28 |
+
return df, wc_img
|
| 29 |
+
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
gr.Markdown("# 🏛️ E-Consultation Sentiment Analysis\nAnalyze stakeholder comments with AI.")
|
| 32 |
+
|
| 33 |
+
with gr.Tab("Single Comment"):
|
| 34 |
+
inp = gr.Textbox(lines=5, placeholder="Enter stakeholder comment...")
|
| 35 |
+
out1 = gr.Textbox(label="Sentiment")
|
| 36 |
+
out2 = gr.Textbox(label="Summary")
|
| 37 |
+
out3 = gr.Image(label="Word Cloud")
|
| 38 |
+
btn = gr.Button("Analyze")
|
| 39 |
+
btn.click(analyze_single, inputs=inp, outputs=[out1, out2, out3])
|
| 40 |
+
|
| 41 |
+
with gr.Tab("Batch Upload (CSV)"):
|
| 42 |
+
file_in = gr.File(label="Upload CSV with 'comment' column", type="file")
|
| 43 |
+
df_out = gr.Dataframe(label="Analysis Results")
|
| 44 |
+
wc_out = gr.Image(label="Word Cloud")
|
| 45 |
+
file_in.change(analyze_batch, inputs=file_in, outputs=[df_out, wc_out])
|
| 46 |
+
|
| 47 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|