kambris commited on
Commit
9444672
ยท
verified ยท
1 Parent(s): 81fb02f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -13
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")