kambris commited on
Commit
1ba39e4
·
verified ·
1 Parent(s): 506a6c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -32
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
- # Create a base map centered on the Arab world
99
- m = folium.Map(location=[25, 45], zoom_start=4)
100
-
101
- # Convert country names to coordinates
102
- cc = coco.CountryConverter()
103
-
104
- for summary in summaries:
105
- try:
106
- # Get country coordinates
107
- country_iso = cc.convert(names=[summary['country']], to='ISO2')
108
- country_data = cc.convert(names=[summary['country']], to='name_short')
109
-
110
- # Create popup content with theme information
111
- popup_content = f"""
112
- <h4>{summary['country']}</h4>
113
- <b>Top Themes:</b><br>
114
- {'<br>'.join([f"• {topic['topic']}: {topic['count']}"
115
- for topic in summary['top_topics'][:5]])}
116
- """
117
-
118
- # Add marker for each country
119
- folium.CircleMarker(
120
- location=[cc.convert(country_iso, to='latitude')[0],
121
- cc.convert(country_iso, to='longitude')[0]],
122
- radius=20,
123
- popup=folium.Popup(popup_content, max_width=300),
124
- color='red',
125
- fill=True,
126
- fill_opacity=0.7
127
- ).add_to(m)
128
-
129
- return m
 
 
 
 
 
 
 
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."""