Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -176,7 +176,32 @@ def fetch_youtube_data(keyword, limit=30):
|
|
| 176 |
return pd.DataFrame()
|
| 177 |
|
| 178 |
# --------------------------
|
| 179 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
# --------------------------
|
| 181 |
|
| 182 |
def prepare_data_for_prediction(data):
|
|
@@ -410,7 +435,10 @@ def main():
|
|
| 410 |
|
| 411 |
st.subheader("๐ Text Visualization")
|
| 412 |
wordcloud_img = f'data:image/png;base64,{generate_wordcloud(user_input)}'
|
| 413 |
-
|
|
|
|
|
|
|
|
|
|
| 414 |
|
| 415 |
else: # Live Data Analysis
|
| 416 |
if not keyword.strip():
|
|
@@ -464,7 +492,10 @@ def main():
|
|
| 464 |
st.subheader("๐ Content Visualization")
|
| 465 |
all_text = " ".join(combined_data['text'])
|
| 466 |
wordcloud_img = f'data:image/png;base64,{generate_wordcloud(all_text)}'
|
| 467 |
-
|
|
|
|
|
|
|
|
|
|
| 468 |
|
| 469 |
# Filter recent data
|
| 470 |
combined_data['date'] = pd.to_datetime(combined_data['date'])
|
|
|
|
| 176 |
return pd.DataFrame()
|
| 177 |
|
| 178 |
# --------------------------
|
| 179 |
+
# Visualization Functions
|
| 180 |
+
# --------------------------
|
| 181 |
+
|
| 182 |
+
def generate_wordcloud(text):
|
| 183 |
+
"""Fast word cloud generation"""
|
| 184 |
+
try:
|
| 185 |
+
if not text.strip():
|
| 186 |
+
return ""
|
| 187 |
+
|
| 188 |
+
wordcloud = WordCloud(
|
| 189 |
+
width=800,
|
| 190 |
+
height=400,
|
| 191 |
+
background_color='white',
|
| 192 |
+
collocations=False, # Faster processing
|
| 193 |
+
stopwords=nltk.corpus.stopwords.words('english')
|
| 194 |
+
).generate(text)
|
| 195 |
+
|
| 196 |
+
img = BytesIO()
|
| 197 |
+
wordcloud.to_image().save(img, format='PNG')
|
| 198 |
+
return base64.b64encode(img.getvalue()).decode()
|
| 199 |
+
except Exception as e:
|
| 200 |
+
st.error(f"Word cloud generation error: {str(e)}")
|
| 201 |
+
return ""
|
| 202 |
+
|
| 203 |
+
# --------------------------
|
| 204 |
+
# Prediction Functions
|
| 205 |
# --------------------------
|
| 206 |
|
| 207 |
def prepare_data_for_prediction(data):
|
|
|
|
| 435 |
|
| 436 |
st.subheader("๐ Text Visualization")
|
| 437 |
wordcloud_img = f'data:image/png;base64,{generate_wordcloud(user_input)}'
|
| 438 |
+
if wordcloud_img:
|
| 439 |
+
st.image(wordcloud_img, use_column_width=True)
|
| 440 |
+
else:
|
| 441 |
+
st.info("No word cloud generated due to insufficient text")
|
| 442 |
|
| 443 |
else: # Live Data Analysis
|
| 444 |
if not keyword.strip():
|
|
|
|
| 492 |
st.subheader("๐ Content Visualization")
|
| 493 |
all_text = " ".join(combined_data['text'])
|
| 494 |
wordcloud_img = f'data:image/png;base64,{generate_wordcloud(all_text)}'
|
| 495 |
+
if wordcloud_img:
|
| 496 |
+
st.image(wordcloud_img, use_column_width=True)
|
| 497 |
+
else:
|
| 498 |
+
st.info("No word cloud generated due to insufficient text")
|
| 499 |
|
| 500 |
# Filter recent data
|
| 501 |
combined_data['date'] = pd.to_datetime(combined_data['date'])
|