Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -112,7 +112,7 @@ def fetch_x_post(x_url, model_name, pos_words, neg_words, intensity, custom_mode
|
|
112 |
sample_text = "Sample X post from " + x_url
|
113 |
return analyze_sentiment(sample_text, model_name, pos_words, neg_words, intensity, custom_model_path, source="X post")
|
114 |
|
115 |
-
# Generate timeline
|
116 |
def generate_timeline():
|
117 |
if not sentiment_scores:
|
118 |
return None
|
@@ -128,20 +128,18 @@ def generate_timeline():
|
|
128 |
buf = io.BytesIO()
|
129 |
plt.savefig(buf, format="png")
|
130 |
buf.seek(0)
|
131 |
-
img_str = "data:image/png;base64," + base64.b64encode(buf.getvalue()).decode()
|
132 |
plt.close()
|
133 |
-
return
|
134 |
|
135 |
-
# Generate word cloud
|
136 |
def generate_wordcloud(text):
|
137 |
wordcloud = WordCloud(width=400, height=200, background_color="white").generate(text)
|
138 |
buf = io.BytesIO()
|
139 |
wordcloud.to_image().save(buf, format="PNG")
|
140 |
buf.seek(0)
|
141 |
-
|
142 |
-
return img_str
|
143 |
|
144 |
-
# Generate QR code
|
145 |
def generate_qr(url):
|
146 |
qr = qrcode.QRCode(version=1, box_size=10, border=4)
|
147 |
qr.add_data(url)
|
@@ -150,8 +148,7 @@ def generate_qr(url):
|
|
150 |
buf = io.BytesIO()
|
151 |
img.save(buf, format="PNG")
|
152 |
buf.seek(0)
|
153 |
-
|
154 |
-
return img_str
|
155 |
|
156 |
# Export history with proper file handling
|
157 |
def export_history():
|
@@ -173,7 +170,7 @@ def toggle_theme(light_mode):
|
|
173 |
|
174 |
# Gradio interface
|
175 |
with gr.Blocks(theme=gr.themes.Monochrome()) as interface:
|
176 |
-
gr.Markdown("#
|
177 |
gr.Markdown("Next-level sentiment analysis with context, comparison, and more!")
|
178 |
|
179 |
with gr.Row():
|
|
|
112 |
sample_text = "Sample X post from " + x_url
|
113 |
return analyze_sentiment(sample_text, model_name, pos_words, neg_words, intensity, custom_model_path, source="X post")
|
114 |
|
115 |
+
# Generate timeline (return BytesIO directly)
|
116 |
def generate_timeline():
|
117 |
if not sentiment_scores:
|
118 |
return None
|
|
|
128 |
buf = io.BytesIO()
|
129 |
plt.savefig(buf, format="png")
|
130 |
buf.seek(0)
|
|
|
131 |
plt.close()
|
132 |
+
return buf # Return the BytesIO object instead of base64 string
|
133 |
|
134 |
+
# Generate word cloud (return BytesIO directly)
|
135 |
def generate_wordcloud(text):
|
136 |
wordcloud = WordCloud(width=400, height=200, background_color="white").generate(text)
|
137 |
buf = io.BytesIO()
|
138 |
wordcloud.to_image().save(buf, format="PNG")
|
139 |
buf.seek(0)
|
140 |
+
return buf # Return the BytesIO object instead of base64 string
|
|
|
141 |
|
142 |
+
# Generate QR code (return BytesIO directly)
|
143 |
def generate_qr(url):
|
144 |
qr = qrcode.QRCode(version=1, box_size=10, border=4)
|
145 |
qr.add_data(url)
|
|
|
148 |
buf = io.BytesIO()
|
149 |
img.save(buf, format="PNG")
|
150 |
buf.seek(0)
|
151 |
+
return buf # Return the BytesIO object instead of base64 string
|
|
|
152 |
|
153 |
# Export history with proper file handling
|
154 |
def export_history():
|
|
|
170 |
|
171 |
# Gradio interface
|
172 |
with gr.Blocks(theme=gr.themes.Monochrome()) as interface:
|
173 |
+
gr.Markdown("# Sentify")
|
174 |
gr.Markdown("Next-level sentiment analysis with context, comparison, and more!")
|
175 |
|
176 |
with gr.Row():
|