JertineAI commited on
Commit
bf7c2da
1 Parent(s): 28700b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -9
app.py CHANGED
@@ -6,6 +6,9 @@ import pandas as pd
6
  from PIL import Image
7
  import numpy as np
8
  from streamlit_folium import st_folium
 
 
 
9
 
10
  def process_image(image_path):
11
  # Read the image
@@ -59,17 +62,49 @@ def create_map(location_name, latitude, longitude):
59
  return map
60
 
61
  def analyze_location(location_name, latitude, longitude):
62
- # Dummy function to gather information about the location
63
- # In a real application, this would query a geospatial database or API
64
  location_info = {
65
  'Location Name': location_name,
66
  'Latitude': latitude,
67
  'Longitude': longitude,
68
- 'Environmental Impact': 'Moderate',
69
- 'Geographical Features': 'Mountains, Rivers',
70
- 'Agricultural Impact': 'High',
71
- 'Urbanisation Impact': 'Low'
72
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  return location_info
74
 
75
  # Streamlit app
@@ -89,11 +124,11 @@ longitude = longitude_deg if longitude_dir == "E" else -longitude_deg
89
  # Enter button to find and display the location on the map
90
  if st.button("Enter"):
91
  map = create_map(location_name, latitude, longitude)
92
- st_folium(map, width=700, height=500)
93
  location_info = analyze_location(location_name, latitude, longitude)
94
  st.write("### Location Information")
95
  for key, value in location_info.items():
96
  st.write(f"{key}: {value}")
 
97
 
98
  # File upload
99
  uploaded_files = st.file_uploader("Upload Images", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
@@ -117,9 +152,8 @@ if uploaded_files and location_name and latitude and longitude:
117
 
118
  # Display images
119
  display_images(images)
120
- # Display results
121
- from typing import Dict, List
122
 
 
123
  combined_results: Dict[str, List[Dict[str, str]]] = {
124
  'Geological Analysis': [],
125
  'Agricultural and Environmental Analysis': [],
 
6
  from PIL import Image
7
  import numpy as np
8
  from streamlit_folium import st_folium
9
+ from typing import Dict, List
10
+ import requests
11
+ from time import sleep
12
 
13
  def process_image(image_path):
14
  # Read the image
 
62
  return map
63
 
64
  def analyze_location(location_name, latitude, longitude):
 
 
65
  location_info = {
66
  'Location Name': location_name,
67
  'Latitude': latitude,
68
  'Longitude': longitude,
 
 
 
 
69
  }
70
+
71
+ # Get address data from Nominatim API
72
+ nominatim_url = f"https://nominatim.openstreetmap.org/reverse?format=json&lat={latitude}&lon={longitude}&zoom=10"
73
+ headers = {'User-Agent': 'DroneImageProcessor/1.0'}
74
+ response = requests.get(nominatim_url, headers=headers)
75
+ sleep(1) # Respect rate limiting
76
+
77
+ if response.status_code == 200:
78
+ osm_data = response.json()
79
+ address = osm_data.get('address', {})
80
+
81
+ # Extract relevant information
82
+ location_info.update({
83
+ 'Country': address.get('country', 'Unknown'),
84
+ 'State/Region': address.get('state', address.get('region', 'Unknown')),
85
+ 'City': address.get('city', address.get('town', address.get('village', 'Unknown'))),
86
+ 'Land Use': address.get('landuse', 'Unknown'),
87
+ })
88
+
89
+ # Get elevation data from OpenTopoData API
90
+ elevation_url = f"https://api.opentopodata.org/v1/aster30m?locations={latitude},{longitude}"
91
+ response = requests.get(elevation_url)
92
+ sleep(1) # Respect rate limiting
93
+
94
+ if response.status_code == 200:
95
+ elevation_data = response.json()
96
+ elevation = elevation_data['results'][0]['elevation']
97
+ location_info['Elevation'] = f"{elevation:.1f} meters"
98
+
99
+ # Basic terrain classification based on elevation
100
+ if elevation < 100:
101
+ terrain = "Lowland"
102
+ elif elevation < 500:
103
+ terrain = "Hills"
104
+ else:
105
+ terrain = "Mountains"
106
+ location_info['Terrain Type'] = terrain
107
+
108
  return location_info
109
 
110
  # Streamlit app
 
124
  # Enter button to find and display the location on the map
125
  if st.button("Enter"):
126
  map = create_map(location_name, latitude, longitude)
 
127
  location_info = analyze_location(location_name, latitude, longitude)
128
  st.write("### Location Information")
129
  for key, value in location_info.items():
130
  st.write(f"{key}: {value}")
131
+ st_folium(map, width=700, height=500)
132
 
133
  # File upload
134
  uploaded_files = st.file_uploader("Upload Images", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
 
152
 
153
  # Display images
154
  display_images(images)
 
 
155
 
156
+ # Display results
157
  combined_results: Dict[str, List[Dict[str, str]]] = {
158
  'Geological Analysis': [],
159
  'Agricultural and Environmental Analysis': [],