yunusserhat commited on
Commit
b0b2255
·
verified ·
1 Parent(s): 9aa9bdf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -182,7 +182,7 @@ def main():
182
  # Define page navigation using the sidebar
183
  page = st.sidebar.selectbox(
184
  "Choose your action:",
185
- ("Home", "Upload Images", "Social Media URL", "Web Page URL"),
186
  index=0 # Default to Home
187
  )
188
 
@@ -235,33 +235,34 @@ def social_media_page():
235
  st.header("Social Media Analyser")
236
  social_media_url = st.text_input("Enter a social media URL to analyse:", key='social_media_url_input')
237
  if social_media_url:
238
- media_data = get_media(social_media_url) # Assume this function is defined elsewhere
239
  if media_data:
240
- # Display the full text of the first media found
241
  full_text = media_data[0][1]
242
  st.subheader("Full Text")
243
  st.write(full_text)
244
- most_used_location = most_frequent_locations(full_text)
245
  st.subheader("Most Frequent Location")
246
  st.write(most_used_location)
247
 
248
- # Process and display each image found in the media data
249
  for idx, (media_url, _) in enumerate(media_data, start=1):
250
  st.subheader(f"Image {idx}")
251
  response = requests.get(media_url)
252
  if response.status_code == 200:
253
  image = Image.open(BytesIO(response.content)).convert('RGB')
254
  st.image(image, caption=f'Image from URL: {media_url}', use_column_width=True)
255
- model = load_geoloc_model() # Assume this function is defined elsewhere
256
  if model:
257
- result = predict_location(image, model) # Assume this function is defined elsewhere
258
  if result:
259
  gps_degrees, location_query, city_geojson, processing_time = result
260
- st.write(
261
- f"City: {location_query['name']}, Region: {location_query['admin1']}, Country: {location_query['cc']}")
262
  if city_geojson:
263
  display_map(city_geojson, gps_degrees)
264
  st.write(f"Processing Time (seconds): {processing_time}")
 
 
 
265
  else:
266
  st.error(f"Failed to fetch image at URL {media_url}: HTTP {response.status_code}")
267
 
 
182
  # Define page navigation using the sidebar
183
  page = st.sidebar.selectbox(
184
  "Choose your action:",
185
+ ("Home", "Images", "Social Media", "Web Pages"),
186
  index=0 # Default to Home
187
  )
188
 
 
235
  st.header("Social Media Analyser")
236
  social_media_url = st.text_input("Enter a social media URL to analyse:", key='social_media_url_input')
237
  if social_media_url:
238
+ media_data = get_media(social_media_url)
239
  if media_data:
 
240
  full_text = media_data[0][1]
241
  st.subheader("Full Text")
242
  st.write(full_text)
243
+ most_used_location, most_common_locations = most_frequent_locations(full_text)
244
  st.subheader("Most Frequent Location")
245
  st.write(most_used_location)
246
 
 
247
  for idx, (media_url, _) in enumerate(media_data, start=1):
248
  st.subheader(f"Image {idx}")
249
  response = requests.get(media_url)
250
  if response.status_code == 200:
251
  image = Image.open(BytesIO(response.content)).convert('RGB')
252
  st.image(image, caption=f'Image from URL: {media_url}', use_column_width=True)
253
+ model = load_geoloc_model()
254
  if model:
255
+ result = predict_location(image, model)
256
  if result:
257
  gps_degrees, location_query, city_geojson, processing_time = result
258
+ location_name = f"{location_query['name']}, {location_query['admin1']}, {location_query['cc']}"
259
+ st.write(f"City: {location_query['name']}, Region: {location_query['admin1']}, Country: {location_query['cc']}")
260
  if city_geojson:
261
  display_map(city_geojson, gps_degrees)
262
  st.write(f"Processing Time (seconds): {processing_time}")
263
+ # Check for match and notify
264
+ if location_query['name'] in most_common_locations:
265
+ st.success(f"The predicted location {location_query['name']} matches the most frequently mentioned location!")
266
  else:
267
  st.error(f"Failed to fetch image at URL {media_url}: HTTP {response.status_code}")
268