Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -95,38 +95,45 @@ def get_cached_embeddings(text, tokenizer, model):
|
|
95 |
|
96 |
def create_theme_map(summaries, topic_model):
|
97 |
"""Create an interactive map showing theme distributions across countries"""
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
def split_text(text, max_length=512):
|
132 |
"""Split text into chunks of maximum token length while preserving word boundaries."""
|
|
|
95 |
|
96 |
def create_theme_map(summaries, topic_model):
|
97 |
"""Create an interactive map showing theme distributions across countries"""
|
98 |
+
try:
|
99 |
+
# Create a base map centered on the Arab world
|
100 |
+
m = folium.Map(location=[25, 45], zoom_start=4)
|
101 |
+
|
102 |
+
# Convert country names to coordinates
|
103 |
+
cc = coco.CountryConverter()
|
104 |
+
|
105 |
+
for summary in summaries:
|
106 |
+
try:
|
107 |
+
# Get country coordinates
|
108 |
+
country_iso = cc.convert(names=[summary['country']], to='ISO2')
|
109 |
+
country_data = cc.convert(names=[summary['country']], to='name_short')
|
110 |
+
|
111 |
+
# Create popup content with theme information
|
112 |
+
popup_content = f"""
|
113 |
+
<h4>{summary['country']}</h4>
|
114 |
+
<b>Top Themes:</b><br>
|
115 |
+
{'<br>'.join([f"• {topic['topic']}: {topic['count']}"
|
116 |
+
for topic in summary['top_topics'][:5]])}
|
117 |
+
"""
|
118 |
+
|
119 |
+
# Add marker for each country
|
120 |
+
folium.CircleMarker(
|
121 |
+
location=[cc.convert(country_iso, to='latitude')[0],
|
122 |
+
cc.convert(country_iso, to='longitude')[0]],
|
123 |
+
radius=20,
|
124 |
+
popup=folium.Popup(popup_content, max_width=300),
|
125 |
+
color='red',
|
126 |
+
fill=True,
|
127 |
+
fill_opacity=0.7
|
128 |
+
).add_to(m)
|
129 |
+
except Exception as e:
|
130 |
+
st.warning(f"Could not process {summary['country']}: {str(e)}")
|
131 |
+
continue
|
132 |
+
|
133 |
+
return m
|
134 |
+
except Exception as e:
|
135 |
+
st.error(f"Error creating map: {str(e)}")
|
136 |
+
return None
|
137 |
|
138 |
def split_text(text, max_length=512):
|
139 |
"""Split text into chunks of maximum token length while preserving word boundaries."""
|