Spaces:
Runtime error
Runtime error
Update app.py
Browse files124 unmodified lines125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159354 unmodified lines514515516517518519520521522124 unmodified lines'Mauritania': [21.0079, -10.9408]}def create_topic_map(summaries):"""Create an interactive map showing topic distribution"""coordinates = get_country_coordinates()# Create base map centered on Arab worldm = folium.Map(location=[25.0, 30.0], zoom_start=4)for summary in summaries:country = summary['country']if country in coordinates:# Get top topictop_topic = summary['top_topics'][0]['topic'] if summary['top_topics'] else "No topics"top_emotion = summary['top_emotions'][0]['emotion'] if summary['top_emotions'] else "No emotion"# Create popup contentpopup_content = f"""<b>{country}</b><br>Top Topic: {top_topic}<br>Main Emotion: {top_emotion}<br>Total Poems: {summary['total_poems']}"""# Add markerfolium.CircleMarker(location=coordinates[country],radius=10,popup=folium.Popup(popup_content, max_width=300),color='red',fill=True).add_to(m)return m354 unmodified linesst.write(f"• Topic {row['Topic']}: {topic_name} ({row['Count']} poems)")with tab3:st.subheader("Topic Distribution Map")topic_map = create_topic_map(summaries)# Display the mapst.components.v1.html(topic_map._repr_html_(), height=600)except Exception as e:124 unmodified lines125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176354 unmodified lines531532533534535536537538124 unmodified lines'Mauritania': [21.0079, -10.9408]}def create_topic_map(summaries):coordinates = get_country_coordinates()m = folium.Map(location=[25.0, 30.0], zoom_start=4)# Color mapping for sentimentssentiment_colors = {'Positive': 'green','Negative': 'red','Neutral': 'blue'}for summary in summaries:country_en = COUNTRY_MAPPING.get(summary['country'])if country_en and country_en in coordinates:# Get dominant sentimentdominant_emotion = summary['top_emotions'][0]['emotion'] if summary['top_emotions'] else "Neutral"circle_color = sentiment_colors.get(dominant_emotion, 'gray')# Create popup contentpopup_content = f"""<b>{country_en}</b><br><b>Sentiment Distribution:</b><br>{'<br>'.join(f"• {e['emotion']}: {e['count']}" for e in summary['top_emotions'][:3])}<br><b>Top Topic:</b><br>{summary['top_topics'][0]['topic'] if summary['top_topics'] else 'No topics'}<br>Total Poems: {summary['total_poems']}"""# Add markerfolium.CircleMarker(location=coordinates[country_en],radius=10,popup=folium.Popup(popup_content, max_width=300),color=circle_color,fill=True).add_to(m)# Add legendlegend_html = """<div style="position: fixed; bottom: 50px; left: 50px; z-index: 1000; background-color: white; padding: 10px; border: 2px solid grey; border-radius: 5px"><p><b>Sentiment:</b></p><p><span style="color: green;">●</span> Positive</p><p><span style="color: red;">●</span> Negative</p><p><span style="color: blue;">●</span> Neutral</p></div>"""m.get_root().html.add_child(folium.Element(legend_html))return m354 unmodified linesst.write(f"• Topic {row['Topic']}: {topic_name} ({row['Count']} poems)")with tab3:st.subheader("Topic and Sentiment Distribution Map")topic_map = create_topic_map(summaries)st.components.v1.html(topic_map._repr_html_(), height=600)except Exception as e:
app.py+31-15