Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
| 180 |
REVERSE_EMOTION_LABELS = {
|
| 181 |
-
'
|
| 182 |
-
'
|
| 183 |
-
'
|
| 184 |
}
|
| 185 |
|
| 186 |
-
# Get dominant sentiment
|
| 187 |
-
dominant_emotion = summary['top_emotions'][0]['emotion'] if summary['top_emotions'] else "
|
| 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,
|