kambris commited on
Commit
c63ad9d
ยท
verified ยท
1 Parent(s): 81e4873

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -38,7 +38,7 @@ ARABIC_STOP_WORDS = {
38
  'ู…ู†ุฐ', 'ู†ูุณ', 'ุญูŠุซ', 'ู‡ู†ุงูƒ', 'ุฌุฏุง', 'ุฐุงุช', 'ุถู…ู†', 'ุงู†ู‡', 'ู„ุฏู‰',
39
  'ุนู„ูŠู‡', 'ู…ุซู„', 'ุฃู…ุง', 'ู„ุฏูŠ', 'ููŠู‡', 'ูƒู„ู…', 'ู„ูƒู†', 'ุงูŠุถุง', 'ู„ุงุฒู…',
40
  'ูŠุฌุจ', 'ุตุงุฑ', 'ุตุงุฑุช', 'ุถุฏ', 'ูŠุง', 'ู„ุง', 'ุงู…ุง',
41
- 'ุจู‡ุง', 'ุงู†', 'ุจู‡', 'ุงู„ูŠ', 'ู„ู…ุง', 'ุงู†ุง', 'ุงู„ูŠูƒ', 'ู„ูŠ', 'ู„ูƒ','ุงุฐุง','ุจู„ุง','ุงูˆ','ู„ุฏูŠูƒ','ู„ุฏูŠู‡', 'ู‚ู„ุช',
42
 
43
  # Middle group prefixed with "ูˆ"
44
  'ูˆุซู…', 'ูˆุฃูˆ', 'ูˆู„', 'ูˆุจ', 'ูˆูƒ', 'ูˆู„ู„', 'ูˆุงู„',
@@ -163,6 +163,9 @@ def get_country_coordinates():
163
  'Mauritania': [21.0079, -10.9408]
164
  }
165
  def create_topic_map(summaries):
 
 
 
166
  coordinates = get_country_coordinates()
167
  m = folium.Map(location=[27.0, 42.0], zoom_start=5)
168
 
@@ -176,18 +179,21 @@ def create_topic_map(summaries):
176
  for summary in summaries:
177
  country_en = COUNTRY_MAPPING.get(summary['country'])
178
  if country_en and country_en in coordinates:
179
- # Mapping emotions back to their original labels
180
  REVERSE_EMOTION_LABELS = {
181
- 'Negative': 'LABEL_0',
182
- 'Positive': 'LABEL_1',
183
- 'Neutral': 'LABEL_2'
184
  }
185
 
186
- # Get dominant sentiment and map it back to original label
187
- dominant_emotion = summary['top_emotions'][0]['emotion'] if summary['top_emotions'] else "Neutral"
188
  dominant_label = REVERSE_EMOTION_LABELS.get(dominant_emotion, 'LABEL_2')
189
  circle_color = sentiment_colors.get(dominant_label, 'gray')
190
 
 
 
 
191
  # Create popup content
192
  popup_content = f"""
193
  <b>{country_en}</b><br>
@@ -206,7 +212,7 @@ def create_topic_map(summaries):
206
  color=circle_color,
207
  fill=True
208
  ).add_to(m)
209
-
210
  # Add legend
211
  legend_html = """
212
  <div style="position: fixed; bottom: 50px; left: 50px; z-index: 1000; background-color: white; padding: 10px; border: 2px solid grey; border-radius: 5px">
@@ -220,6 +226,7 @@ def create_topic_map(summaries):
220
 
221
  return m
222
 
 
223
  def create_arabic_wordcloud(text, title):
224
  wordcloud = WordCloud(
225
  width=1200,
 
38
  'ู…ู†ุฐ', 'ู†ูุณ', 'ุญูŠุซ', 'ู‡ู†ุงูƒ', 'ุฌุฏุง', 'ุฐุงุช', 'ุถู…ู†', 'ุงู†ู‡', 'ู„ุฏู‰',
39
  'ุนู„ูŠู‡', 'ู…ุซู„', 'ุฃู…ุง', 'ู„ุฏูŠ', 'ููŠู‡', 'ูƒู„ู…', 'ู„ูƒู†', 'ุงูŠุถุง', 'ู„ุงุฒู…',
40
  'ูŠุฌุจ', 'ุตุงุฑ', 'ุตุงุฑุช', 'ุถุฏ', 'ูŠุง', 'ู„ุง', 'ุงู…ุง',
41
+ 'ุจู‡ุง', 'ุงู†', 'ุจู‡', 'ุงู„ูŠ', 'ู„ู…ุง', 'ุงู†ุง', 'ุงู„ูŠูƒ', 'ู„ูŠ', 'ู„ูƒ','ุงุฐุง','ุจู„ุง','ุงูˆ','ู„ุฏูŠูƒ','ู„ุฏูŠู‡','ุงู†ูŠ','ูƒู†ุช','ู„ูŠุณ','ุงูŠู‡ุง', 'ู‚ู„ุช',
42
 
43
  # Middle group prefixed with "ูˆ"
44
  'ูˆุซู…', 'ูˆุฃูˆ', 'ูˆู„', 'ูˆุจ', 'ูˆูƒ', 'ูˆู„ู„', 'ูˆุงู„',
 
163
  'Mauritania': [21.0079, -10.9408]
164
  }
165
  def create_topic_map(summaries):
166
+ # Debug print to check incoming data
167
+ print("DEBUG - First summary emotions:", summaries[0]['top_emotions'])
168
+
169
  coordinates = get_country_coordinates()
170
  m = folium.Map(location=[27.0, 42.0], zoom_start=5)
171
 
 
179
  for summary in summaries:
180
  country_en = COUNTRY_MAPPING.get(summary['country'])
181
  if country_en and country_en in coordinates:
182
+ # Direct label mapping (no conversion needed)
183
  REVERSE_EMOTION_LABELS = {
184
+ 'LABEL_0': 'LABEL_0',
185
+ 'LABEL_1': 'LABEL_1',
186
+ 'LABEL_2': 'LABEL_2'
187
  }
188
 
189
+ # Get dominant sentiment
190
+ dominant_emotion = summary['top_emotions'][0]['emotion'] if summary['top_emotions'] else "LABEL_2"
191
  dominant_label = REVERSE_EMOTION_LABELS.get(dominant_emotion, 'LABEL_2')
192
  circle_color = sentiment_colors.get(dominant_label, 'gray')
193
 
194
+ # Debug print
195
+ print(f"DEBUG - Country: {country_en}, Emotion: {dominant_emotion}, Label: {dominant_label}, Color: {circle_color}")
196
+
197
  # Create popup content
198
  popup_content = f"""
199
  <b>{country_en}</b><br>
 
212
  color=circle_color,
213
  fill=True
214
  ).add_to(m)
215
+
216
  # Add legend
217
  legend_html = """
218
  <div style="position: fixed; bottom: 50px; left: 50px; z-index: 1000; background-color: white; padding: 10px; border: 2px solid grey; border-radius: 5px">
 
226
 
227
  return m
228
 
229
+
230
  def create_arabic_wordcloud(text, title):
231
  wordcloud = WordCloud(
232
  width=1200,