Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -24,10 +24,8 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
24 |
font_path = os.path.join(current_dir, "ArabicR2013-J25x.ttf")
|
25 |
|
26 |
ARABIC_STOP_WORDS = {
|
27 |
-
# First group
|
28 |
'ูู', 'ู
ู', 'ุฅูู', 'ุนูู', 'ุนูู', 'ุนู', 'ู
ุน', 'ุฎูุงู', 'ุญุชู', 'ุญุชู', 'ุฅุฐุง',
|
29 |
|
30 |
-
# Middle group
|
31 |
'ุซู
', 'ุฃู', 'ู', 'ู', 'ุจ', 'ู', 'ูู', 'ุงู', 'ูุฐุง',
|
32 |
'ูุฐู', 'ุฐูู', 'ุชูู', 'ูุคูุงุก', 'ูู
', 'ูู', 'ูู', 'ูู','ููุง', 'ูุญู',
|
33 |
'ุงูุช', 'ุงูุชู
', 'ูุงู', 'ูุงูุช', 'ูููู', 'ุชููู', 'ุงู', 'ูู',
|
@@ -40,7 +38,6 @@ ARABIC_STOP_WORDS = {
|
|
40 |
'ูุฌุจ', 'ุตุงุฑ', 'ุตุงุฑุช', 'ุถุฏ', 'ูุง', 'ูุง', 'ุงู
ุง',
|
41 |
'ุจูุง', 'ุงู', 'ุจู', 'ุงูู', 'ูู
ุง', 'ุงูุง', 'ุงููู', 'ูู', 'ูู','ุงุฐุง','ุจูุง','ุงู','ูุฏูู','ูุฏูู','ุงูู','ููุช','ููุณ','ุงููุง', 'ููุช',
|
42 |
|
43 |
-
# Middle group prefixed with "ู"
|
44 |
'ูุซู
', 'ูุฃู', 'ูู', 'ูุจ', 'ูู', 'ููู', 'ูุงู',
|
45 |
'ููุฐุง', 'ููุฐู', 'ูุฐูู', 'ูุชูู', 'ููุคูุงุก', 'ููู
', 'ููู', 'ููู', 'ููู', 'ููุญู',
|
46 |
'ูุงูุช', 'ูุงูุชู
', 'ููุงู', 'ููุงูุช', 'ููููู', 'ูุชููู', 'ูุงู', 'ููู',
|
@@ -53,7 +50,6 @@ ARABIC_STOP_WORDS = {
|
|
53 |
'ููุฌุจ', 'ูุตุงุฑ', 'ูุตุงุฑุช', 'ูุถุฏ', 'ููุง', 'ููุง', 'ูุงู
ุง',
|
54 |
'ูุจูุง', 'ูุงู', 'ูุจู', 'ูุงูู', 'ููู
ุง', 'ูุงูุง', 'ูุงููู', 'ููู', 'ููู', 'ูููุช',
|
55 |
|
56 |
-
# Last group
|
57 |
'ููู', 'ูู
ู', 'ูุนูู', 'ูุนูู', 'ูุนู', 'ูู
ุน', 'ูุญุชู', 'ูุฅุฐุง',
|
58 |
'ููุฐุง', 'ููุฐู', 'ูุฐูู', 'ูุชูู', 'ููู', 'ููู', 'ููุญู',
|
59 |
'ููุงู', 'ููุงูุช', 'ููู', 'ูุจุนุถ', 'ูุญูู', 'ูุนูุฏ', 'ููุฏ',
|
@@ -61,11 +57,9 @@ ARABIC_STOP_WORDS = {
|
|
61 |
'ูุจูู', 'ููุจู', 'ูุจุนุฏ', 'ููู', 'ูููุง', 'ูููุงู', 'ูุงูู',
|
62 |
'ู
ูู','ุงูุง','ูููุง','ููุง','ููู
','ููู','ุนููู','ู
ููุง','ูู
ุง','ููู
','ููู','ูุงูู','ูู','ููู','ุจู','ูุญู','ูู','ุณูู','ููุง','ููุง','ู
ุนุง','ููู
ุง','ูุฅุฐุง','ู
ูู','ุนูู','ุฅุฐ','ูู
','ุจู','ูููุง','ููุฐุง','ููู
','ููุฏู', 'ูุนููู', 'ูู
ุซู',
|
63 |
|
64 |
-
# Arabic numbers
|
65 |
'ูุงุญุฏ', 'ุงุซูุงู', 'ุซูุงุซุฉ', 'ุฃุฑุจุนุฉ', 'ุฎู
ุณุฉ', 'ุณุชุฉ', 'ุณุจุนุฉ',
|
66 |
'ุซู
ุงููุฉ', 'ุชุณุนุฉ', 'ุนุดุฑุฉ',
|
67 |
|
68 |
-
# Arabic ordinals
|
69 |
'ุงูุฃูู', 'ุงูุซุงูู', 'ุงูุซุงูุซ', 'ุงูุฑุงุจุน', 'ุงูุฎุงู
ุณ', 'ุงูุณุงุฏุณ',
|
70 |
'ุงูุณุงุจุน', 'ุงูุซุงู
ู', 'ุงูุชุงุณุน', 'ุงูุนุงุดุฑ'
|
71 |
}
|
@@ -169,7 +163,6 @@ def create_topic_map(summaries):
|
|
169 |
coordinates = get_country_coordinates()
|
170 |
m = folium.Map(location=[27.0, 42.0], zoom_start=5)
|
171 |
|
172 |
-
# Color mapping for sentiments
|
173 |
sentiment_colors = {
|
174 |
'LABEL_1': 'green', # Positive
|
175 |
'LABEL_0': 'red', # Negative
|
@@ -179,14 +172,12 @@ def create_topic_map(summaries):
|
|
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 |
'positive': 'LABEL_1',
|
185 |
'negative': 'LABEL_0',
|
186 |
'neutral': 'LABEL_2'
|
187 |
}
|
188 |
|
189 |
-
# Get dominant sentiment
|
190 |
dominant_emotion = summary['top_emotions'][0]['emotion'] if summary['top_emotions'] else "neutral"
|
191 |
dominant_label = REVERSE_EMOTION_LABELS.get(dominant_emotion, 'LABEL_2')
|
192 |
circle_color = sentiment_colors.get(dominant_label, 'gray')
|
@@ -194,7 +185,6 @@ def create_topic_map(summaries):
|
|
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>
|
200 |
<b>Sentiment Distribution:</b><br>
|
@@ -204,7 +194,6 @@ def create_topic_map(summaries):
|
|
204 |
Total Poems: {summary['total_poems']}
|
205 |
"""
|
206 |
|
207 |
-
# Add marker
|
208 |
folium.CircleMarker(
|
209 |
location=coordinates[country_en],
|
210 |
radius=10,
|
@@ -213,7 +202,6 @@ def create_topic_map(summaries):
|
|
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">
|
219 |
<p><b>Sentiment:</b></p>
|
@@ -505,7 +493,6 @@ if uploaded_file is not None:
|
|
505 |
|
506 |
df['country'] = df['country'].str.strip()
|
507 |
df = df.dropna(subset=['country', 'poem'])
|
508 |
-
# Extract 10 rows per country
|
509 |
sampled_df = df.groupby('country').apply(lambda x: x.head(20)).reset_index(drop=True)
|
510 |
|
511 |
st.subheader("Topic Modeling Settings")
|
|
|
24 |
font_path = os.path.join(current_dir, "ArabicR2013-J25x.ttf")
|
25 |
|
26 |
ARABIC_STOP_WORDS = {
|
|
|
27 |
'ูู', 'ู
ู', 'ุฅูู', 'ุนูู', 'ุนูู', 'ุนู', 'ู
ุน', 'ุฎูุงู', 'ุญุชู', 'ุญุชู', 'ุฅุฐุง',
|
28 |
|
|
|
29 |
'ุซู
', 'ุฃู', 'ู', 'ู', 'ุจ', 'ู', 'ูู', 'ุงู', 'ูุฐุง',
|
30 |
'ูุฐู', 'ุฐูู', 'ุชูู', 'ูุคูุงุก', 'ูู
', 'ูู', 'ูู', 'ูู','ููุง', 'ูุญู',
|
31 |
'ุงูุช', 'ุงูุชู
', 'ูุงู', 'ูุงูุช', 'ูููู', 'ุชููู', 'ุงู', 'ูู',
|
|
|
38 |
'ูุฌุจ', 'ุตุงุฑ', 'ุตุงุฑุช', 'ุถุฏ', 'ูุง', 'ูุง', 'ุงู
ุง',
|
39 |
'ุจูุง', 'ุงู', 'ุจู', 'ุงูู', 'ูู
ุง', 'ุงูุง', 'ุงููู', 'ูู', 'ูู','ุงุฐุง','ุจูุง','ุงู','ูุฏูู','ูุฏูู','ุงูู','ููุช','ููุณ','ุงููุง', 'ููุช',
|
40 |
|
|
|
41 |
'ูุซู
', 'ูุฃู', 'ูู', 'ูุจ', 'ูู', 'ููู', 'ูุงู',
|
42 |
'ููุฐุง', 'ููุฐู', 'ูุฐูู', 'ูุชูู', 'ููุคูุงุก', 'ููู
', 'ููู', 'ููู', 'ููู', 'ููุญู',
|
43 |
'ูุงูุช', 'ูุงูุชู
', 'ููุงู', 'ููุงูุช', 'ููููู', 'ูุชููู', 'ูุงู', 'ููู',
|
|
|
50 |
'ููุฌุจ', 'ูุตุงุฑ', 'ูุตุงุฑุช', 'ูุถุฏ', 'ููุง', 'ููุง', 'ูุงู
ุง',
|
51 |
'ูุจูุง', 'ูุงู', 'ูุจู', 'ูุงูู', 'ููู
ุง', 'ูุงูุง', 'ูุงููู', 'ููู', 'ููู', 'ูููุช',
|
52 |
|
|
|
53 |
'ููู', 'ูู
ู', 'ูุนูู', 'ูุนูู', 'ูุนู', 'ูู
ุน', 'ูุญุชู', 'ูุฅุฐุง',
|
54 |
'ููุฐุง', 'ููุฐู', 'ูุฐูู', 'ูุชูู', 'ููู', 'ููู', 'ููุญู',
|
55 |
'ููุงู', 'ููุงูุช', 'ููู', 'ูุจุนุถ', 'ูุญูู', 'ูุนูุฏ', 'ููุฏ',
|
|
|
57 |
'ูุจูู', 'ููุจู', 'ูุจุนุฏ', 'ููู', 'ูููุง', 'ูููุงู', 'ูุงูู',
|
58 |
'ู
ูู','ุงูุง','ูููุง','ููุง','ููู
','ููู','ุนููู','ู
ููุง','ูู
ุง','ููู
','ููู','ูุงูู','ูู','ููู','ุจู','ูุญู','ูู','ุณูู','ููุง','ููุง','ู
ุนุง','ููู
ุง','ูุฅุฐุง','ู
ูู','ุนูู','ุฅุฐ','ูู
','ุจู','ูููุง','ููุฐุง','ููู
','ููุฏู', 'ูุนููู', 'ูู
ุซู',
|
59 |
|
|
|
60 |
'ูุงุญุฏ', 'ุงุซูุงู', 'ุซูุงุซุฉ', 'ุฃุฑุจุนุฉ', 'ุฎู
ุณุฉ', 'ุณุชุฉ', 'ุณุจุนุฉ',
|
61 |
'ุซู
ุงููุฉ', 'ุชุณุนุฉ', 'ุนุดุฑุฉ',
|
62 |
|
|
|
63 |
'ุงูุฃูู', 'ุงูุซุงูู', 'ุงูุซุงูุซ', 'ุงูุฑุงุจุน', 'ุงูุฎุงู
ุณ', 'ุงูุณุงุฏุณ',
|
64 |
'ุงูุณุงุจุน', 'ุงูุซุงู
ู', 'ุงูุชุงุณุน', 'ุงูุนุงุดุฑ'
|
65 |
}
|
|
|
163 |
coordinates = get_country_coordinates()
|
164 |
m = folium.Map(location=[27.0, 42.0], zoom_start=5)
|
165 |
|
|
|
166 |
sentiment_colors = {
|
167 |
'LABEL_1': 'green', # Positive
|
168 |
'LABEL_0': 'red', # Negative
|
|
|
172 |
for summary in summaries:
|
173 |
country_en = COUNTRY_MAPPING.get(summary['country'])
|
174 |
if country_en and country_en in coordinates:
|
|
|
175 |
REVERSE_EMOTION_LABELS = {
|
176 |
'positive': 'LABEL_1',
|
177 |
'negative': 'LABEL_0',
|
178 |
'neutral': 'LABEL_2'
|
179 |
}
|
180 |
|
|
|
181 |
dominant_emotion = summary['top_emotions'][0]['emotion'] if summary['top_emotions'] else "neutral"
|
182 |
dominant_label = REVERSE_EMOTION_LABELS.get(dominant_emotion, 'LABEL_2')
|
183 |
circle_color = sentiment_colors.get(dominant_label, 'gray')
|
|
|
185 |
# Debug print
|
186 |
print(f"DEBUG - Country: {country_en}, Emotion: {dominant_emotion}, Label: {dominant_label}, Color: {circle_color}")
|
187 |
|
|
|
188 |
popup_content = f"""
|
189 |
<b>{country_en}</b><br>
|
190 |
<b>Sentiment Distribution:</b><br>
|
|
|
194 |
Total Poems: {summary['total_poems']}
|
195 |
"""
|
196 |
|
|
|
197 |
folium.CircleMarker(
|
198 |
location=coordinates[country_en],
|
199 |
radius=10,
|
|
|
202 |
fill=True
|
203 |
).add_to(m)
|
204 |
|
|
|
205 |
legend_html = """
|
206 |
<div style="position: fixed; bottom: 50px; left: 50px; z-index: 1000; background-color: white; padding: 10px; border: 2px solid grey; border-radius: 5px">
|
207 |
<p><b>Sentiment:</b></p>
|
|
|
493 |
|
494 |
df['country'] = df['country'].str.strip()
|
495 |
df = df.dropna(subset=['country', 'poem'])
|
|
|
496 |
sampled_df = df.groupby('country').apply(lambda x: x.head(20)).reset_index(drop=True)
|
497 |
|
498 |
st.subheader("Topic Modeling Settings")
|