annikwag commited on
Commit
64b9d89
·
verified ·
1 Parent(s): 529dce6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -21
app.py CHANGED
@@ -224,24 +224,42 @@ if button:
224
  client_name = metadata.get('client', 'Unknown Client')
225
  start_year = metadata.get('start_year', None)
226
  end_year_ = metadata.get('end_year', None)
227
-
228
  try:
229
  c_list = json.loads(countries.replace("'", '"'))
230
- country_names = [
231
- get_country_name(code.upper(), region_df)
232
- for code in c_list
233
- if len(code) == 2
234
- ]
235
  except json.JSONDecodeError:
236
- country_names = []
237
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  start_year_str = f"{int(round(float(start_year)))}" if start_year else "Unknown"
239
  end_year_str = f"{int(round(float(end_year_)))}" if end_year_ else "Unknown"
240
-
241
- additional_text = (
242
- f"**{', '.join(country_names)}**, commissioned by **{client_name}**, "
243
- f"**{start_year_str}-{end_year_str}**"
244
- )
 
 
 
 
 
 
 
 
 
245
  st.markdown(additional_text)
246
  st.divider()
247
 
@@ -276,19 +294,42 @@ if button:
276
  client_name = metadata.get('client', 'Unknown Client')
277
  start_year = metadata.get('start_year', None)
278
  end_year_ = metadata.get('end_year', None)
279
-
280
  try:
281
  c_list = json.loads(countries.replace("'", '"'))
282
- country_names = [get_country_name(code.upper(), region_df) for code in c_list if len(code) == 2]
283
  except json.JSONDecodeError:
284
- country_names = []
285
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  start_year_str = f"{int(round(float(start_year)))}" if start_year else "Unknown"
287
  end_year_str = f"{int(round(float(end_year_)))}" if end_year_ else "Unknown"
288
-
289
- additional_text = (
290
- f"**{', '.join(country_names)}**, commissioned by **{client_name}**, **{start_year_str}-{end_year_str}**"
291
- )
 
 
 
 
 
 
 
 
 
 
292
  st.markdown(additional_text)
293
  st.divider()
294
 
 
224
  client_name = metadata.get('client', 'Unknown Client')
225
  start_year = metadata.get('start_year', None)
226
  end_year_ = metadata.get('end_year', None)
227
+
228
  try:
229
  c_list = json.loads(countries.replace("'", '"'))
 
 
 
 
 
230
  except json.JSONDecodeError:
231
+ c_list = []
232
+
233
+ # Only keep country names if the region lookup (get_country_name)
234
+ # returns something different than the raw code.
235
+ matched_countries = []
236
+ for code in c_list:
237
+ if len(code) == 2:
238
+ resolved_name = get_country_name(code.upper(), region_df)
239
+ # If get_country_name didn't find a match,
240
+ # it typically just returns the same code (like "XX").
241
+ # We'll consider "successfully looked up" if
242
+ # resolved_name != code.upper().
243
+ if resolved_name.upper() != code.upper():
244
+ matched_countries.append(resolved_name)
245
+
246
+ # Format the year range
247
  start_year_str = f"{int(round(float(start_year)))}" if start_year else "Unknown"
248
  end_year_str = f"{int(round(float(end_year_)))}" if end_year_ else "Unknown"
249
+
250
+ # Build the final string
251
+ if matched_countries:
252
+ # We have at least 1 valid country name
253
+ additional_text = (
254
+ f"**{', '.join(matched_countries)}**, commissioned by **{client_name}**, "
255
+ f"**{start_year_str}-{end_year_str}**"
256
+ )
257
+ else:
258
+ # No valid countries found
259
+ additional_text = (
260
+ f"Commissioned by **{client_name}**, **{start_year_str}-{end_year_str}**"
261
+ )
262
+
263
  st.markdown(additional_text)
264
  st.divider()
265
 
 
294
  client_name = metadata.get('client', 'Unknown Client')
295
  start_year = metadata.get('start_year', None)
296
  end_year_ = metadata.get('end_year', None)
297
+
298
  try:
299
  c_list = json.loads(countries.replace("'", '"'))
 
300
  except json.JSONDecodeError:
301
+ c_list = []
302
+
303
+ # Only keep country names if the region lookup (get_country_name)
304
+ # returns something different than the raw code.
305
+ matched_countries = []
306
+ for code in c_list:
307
+ if len(code) == 2:
308
+ resolved_name = get_country_name(code.upper(), region_df)
309
+ # If get_country_name didn't find a match,
310
+ # it typically just returns the same code (like "XX").
311
+ # We'll consider "successfully looked up" if
312
+ # resolved_name != code.upper().
313
+ if resolved_name.upper() != code.upper():
314
+ matched_countries.append(resolved_name)
315
+
316
+ # Format the year range
317
  start_year_str = f"{int(round(float(start_year)))}" if start_year else "Unknown"
318
  end_year_str = f"{int(round(float(end_year_)))}" if end_year_ else "Unknown"
319
+
320
+ # Build the final string
321
+ if matched_countries:
322
+ # We have at least 1 valid country name
323
+ additional_text = (
324
+ f"**{', '.join(matched_countries)}**, commissioned by **{client_name}**, "
325
+ f"**{start_year_str}-{end_year_str}**"
326
+ )
327
+ else:
328
+ # No valid countries found
329
+ additional_text = (
330
+ f"Commissioned by **{client_name}**, **{start_year_str}-{end_year_str}**"
331
+ )
332
+
333
  st.markdown(additional_text)
334
  st.divider()
335