Spaces:
Runtime error
Runtime error
Update app.py
Browse files175 unmodified lines176177178179179180181182183184185186187188189190191192193194195196197198199200201202203204205206207227 unmodified lines43543643743841343944044144244344447 unmodified lines492493494495467496497498499500501175 unmodified lines return pd.DataFrame()
# --------------------------# Prediction Functions (Rewritten to Fix Error)# Visualization Functions# --------------------------
def generate_wordcloud(text): """Fast word cloud generation""" try: if not text.strip(): return "" wordcloud = WordCloud( width=800, height=400, background_color='white', collocations=False, # Faster processing stopwords=nltk.corpus.stopwords.words('english') ).generate(text) img = BytesIO() wordcloud.to_image().save(img, format='PNG') return base64.b64encode(img.getvalue()).decode() except Exception as e: st.error(f"Word cloud generation error: {str(e)}") return ""
# --------------------------# Prediction Functions# --------------------------
def prepare_data_for_prediction(data):227 unmodified lines st.subheader("📊 Text Visualization") wordcloud_img = f'data:image/png;base64,{generate_wordcloud(user_input)}' if wordcloud_img: st.image(wordcloud_img, use_column_width=True) st.image(wordcloud_img, use_column_width=True) else: st.info("No word cloud generated due to insufficient text") else: # Live Data Analysis if not keyword.strip():47 unmodified lines st.subheader("📊 Content Visualization") all_text = " ".join(combined_data['text']) wordcloud_img = f'data:image/png;base64,{generate_wordcloud(all_text)}' if wordcloud_img: st.image(wordcloud_img, use_column_width=True) st.image(wordcloud_img, use_column_width=True) else: st.info("No word cloud generated due to insufficient text") # Filter recent data combined_data['date'] = pd.to_datetime(combined_data['date'])app.py+34-3