Update app.py
Browse files
app.py
CHANGED
|
@@ -77,7 +77,7 @@ def analyze_with_gemini(posts):
|
|
| 77 |
sentiments.append({
|
| 78 |
"Post": post,
|
| 79 |
"Sentiment": label,
|
| 80 |
-
"Confidence": 0.95
|
| 81 |
})
|
| 82 |
except:
|
| 83 |
sentiments.append({
|
|
@@ -92,10 +92,13 @@ def analyze_with_gemini(posts):
|
|
| 92 |
# -----------------------------
|
| 93 |
def run_analysis(hashtag, n_posts, vis_type, use_gemini):
|
| 94 |
posts = generate_fake_posts(hashtag, n_posts)
|
|
|
|
| 95 |
if use_gemini:
|
| 96 |
data = analyze_with_gemini(posts)
|
|
|
|
| 97 |
else:
|
| 98 |
data = analyze_with_hf(posts)
|
|
|
|
| 99 |
|
| 100 |
df = pd.DataFrame(data)
|
| 101 |
|
|
@@ -109,7 +112,8 @@ def run_analysis(hashtag, n_posts, vis_type, use_gemini):
|
|
| 109 |
else:
|
| 110 |
fig = px.scatter(df, x="Sentiment", y="Confidence", title=f"Scatter of Sentiments for {hashtag}")
|
| 111 |
|
| 112 |
-
return df, fig
|
|
|
|
| 113 |
|
| 114 |
# -----------------------------
|
| 115 |
# Gradio UI
|
|
@@ -129,11 +133,12 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="orange", secondary_hue="blue"))
|
|
| 129 |
with gr.Column(scale=2):
|
| 130 |
output_table = gr.Dataframe(headers=["Post", "Sentiment", "Confidence"], wrap=True)
|
| 131 |
output_plot = gr.Plot()
|
|
|
|
| 132 |
|
| 133 |
run_btn.click(
|
| 134 |
fn=run_analysis,
|
| 135 |
inputs=[hashtag, n_posts, vis_type, use_gemini],
|
| 136 |
-
outputs=[output_table, output_plot]
|
| 137 |
)
|
| 138 |
|
| 139 |
# -----------------------------
|
|
|
|
| 77 |
sentiments.append({
|
| 78 |
"Post": post,
|
| 79 |
"Sentiment": label,
|
| 80 |
+
"Confidence": 0.95
|
| 81 |
})
|
| 82 |
except:
|
| 83 |
sentiments.append({
|
|
|
|
| 92 |
# -----------------------------
|
| 93 |
def run_analysis(hashtag, n_posts, vis_type, use_gemini):
|
| 94 |
posts = generate_fake_posts(hashtag, n_posts)
|
| 95 |
+
|
| 96 |
if use_gemini:
|
| 97 |
data = analyze_with_gemini(posts)
|
| 98 |
+
source_info = f"Analyzed with Gemini AI: {len(posts)} posts"
|
| 99 |
else:
|
| 100 |
data = analyze_with_hf(posts)
|
| 101 |
+
source_info = f"Analyzed with Hugging Face Transformers: {len(posts)} posts"
|
| 102 |
|
| 103 |
df = pd.DataFrame(data)
|
| 104 |
|
|
|
|
| 112 |
else:
|
| 113 |
fig = px.scatter(df, x="Sentiment", y="Confidence", title=f"Scatter of Sentiments for {hashtag}")
|
| 114 |
|
| 115 |
+
return df, fig, source_info
|
| 116 |
+
|
| 117 |
|
| 118 |
# -----------------------------
|
| 119 |
# Gradio UI
|
|
|
|
| 133 |
with gr.Column(scale=2):
|
| 134 |
output_table = gr.Dataframe(headers=["Post", "Sentiment", "Confidence"], wrap=True)
|
| 135 |
output_plot = gr.Plot()
|
| 136 |
+
source_label = gr.Label(label="Analysis Source")
|
| 137 |
|
| 138 |
run_btn.click(
|
| 139 |
fn=run_analysis,
|
| 140 |
inputs=[hashtag, n_posts, vis_type, use_gemini],
|
| 141 |
+
outputs=[output_table, output_plot, source_label]
|
| 142 |
)
|
| 143 |
|
| 144 |
# -----------------------------
|