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

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +176 -0
app.py ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import folium
4
+ import geopandas as gpd
5
+ 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
12
+ img = cv2.imread(image_path)
13
+
14
+ # Apply image processing techniques (e.g., noise reduction, edge detection)
15
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
16
+ blur = cv2.GaussianBlur(gray, (5, 5), 0)
17
+ edges = cv2.Canny(blur, 100, 200)
18
+
19
+ # Dummy analysis results
20
+ results = {
21
+ 'Topography': 'Mountainous',
22
+ 'Forestry Pattern': 'Dense Forest',
23
+ 'Ocean Pattern': 'Calm',
24
+ 'Geological Features': 'Mountains, Rivers'
25
+ }
26
+
27
+ return img, edges, results
28
+
29
+ def display_images(images):
30
+ # Generate captions for each pair of images
31
+ captions = []
32
+ for i in range(0, len(images), 2):
33
+ captions.append(f'Original Image {i//2 + 1}')
34
+ captions.append(f'Processed Image {i//2 + 1}')
35
+
36
+ # Display images
37
+ st.image(images, caption=captions, width=300)
38
+
39
+ def display_results(results):
40
+ st.write("### Analysis Results")
41
+ for key, value in results.items():
42
+ st.write(f"{key}: {value}")
43
+
44
+ def export_results(results, export_format):
45
+ results_df = pd.DataFrame(results)
46
+ if export_format == "Excel (.xlsx)":
47
+ results_df.to_excel('analysis_results.xlsx', index=False)
48
+ st.success("Results exported to analysis_results.xlsx")
49
+ elif export_format == "CSV (.csv)":
50
+ results_df.to_csv('analysis_results.csv', index=False)
51
+ st.success("Results exported to analysis_results.csv")
52
+ elif export_format == "JSON (.json)":
53
+ results_df.to_json('analysis_results.json', orient='records')
54
+ st.success("Results exported to analysis_results.json")
55
+
56
+ def create_map(location_name, latitude, longitude):
57
+ map = folium.Map(location=[latitude, longitude], zoom_start=10)
58
+ folium.Marker(location=[latitude, longitude], popup=location_name).add_to(map)
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
76
+ st.title("Drone Image Processing")
77
+
78
+ # Input for location details
79
+ location_name = st.text_input("Location Name")
80
+ latitude_deg = st.number_input("Latitude (degrees)", format="%f")
81
+ latitude_dir = st.selectbox("Latitude Direction", ["N", "S"])
82
+ longitude_deg = st.number_input("Longitude (degrees)", format="%f")
83
+ longitude_dir = st.selectbox("Longitude Direction", ["E", "W"])
84
+
85
+ # Convert latitude and longitude to decimal degrees
86
+ latitude = latitude_deg if latitude_dir == "N" else -latitude_deg
87
+ longitude = longitude_deg if longitude_dir == "E" else -longitude_deg
88
+
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)
100
+
101
+ if uploaded_files and location_name and latitude and longitude:
102
+ images = []
103
+ results_list = []
104
+
105
+ for uploaded_file in uploaded_files:
106
+ # Save the uploaded file to a temporary location
107
+ with open(f"temp_{uploaded_file.name}", "wb") as f:
108
+ f.write(uploaded_file.getbuffer())
109
+
110
+ # Process the image
111
+ original_img, processed_img, results = process_image(f"temp_{uploaded_file.name}")
112
+
113
+ # Append images and results
114
+ images.append(original_img)
115
+ images.append(processed_img)
116
+ results_list.append(results)
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': [],
126
+ 'Urbanisation and Population Analysis': []
127
+ }
128
+ for i, results in enumerate(results_list):
129
+ st.write(f"### Results for Image {i+1}")
130
+ display_results(results)
131
+ combined_results['Geological Analysis'].append({
132
+ 'Topography': results['Topography'],
133
+ 'Geological Features': results['Geological Features']
134
+ })
135
+ combined_results['Agricultural and Environmental Analysis'].append({
136
+ 'Forestry Pattern': results['Forestry Pattern'],
137
+ 'Ocean Pattern': results['Ocean Pattern']
138
+ })
139
+ combined_results['Urbanisation and Population Analysis'].append({
140
+ 'Urbanisation Impact': 'Not implemented'
141
+ })
142
+
143
+ # Export options
144
+ st.sidebar.subheader("Export Options")
145
+ export_format = st.sidebar.radio(
146
+ "Export Format",
147
+ ["Excel (.xlsx)", "CSV (.csv)", "JSON (.json)"]
148
+ )
149
+
150
+ # Export results button
151
+ if st.sidebar.button("Export Results"):
152
+ export_results(combined_results, export_format)
153
+
154
+ # Filter results
155
+ st.write("### Filter Results")
156
+ filter_option = st.selectbox("Select Analysis Type", ["Geological Analysis", "Agricultural and Environmental Analysis", "Urbanisation and Population Analysis"])
157
+
158
+ if filter_option == "Geological Analysis":
159
+ st.write("### Geological Analysis Results")
160
+ for i, results in enumerate(combined_results['Geological Analysis']):
161
+ st.write(f"### Results for Image {i+1}")
162
+ st.write(f"Topography: {results['Topography']}")
163
+ st.write(f"Geological Features: {results['Geological Features']}")
164
+
165
+ elif filter_option == "Agricultural and Environmental Analysis":
166
+ st.write("### Agricultural and Environmental Analysis Results")
167
+ for i, results in enumerate(combined_results['Agricultural and Environmental Analysis']):
168
+ st.write(f"### Results for Image {i+1}")
169
+ st.write(f"Forestry Pattern: {results['Forestry Pattern']}")
170
+ st.write(f"Ocean Pattern: {results['Ocean Pattern']}")
171
+
172
+ elif filter_option == "Urbanisation and Population Analysis":
173
+ st.write("### Urbanisation and Population Analysis Results")
174
+ for i, results in enumerate(combined_results['Urbanisation and Population Analysis']):
175
+ st.write(f"### Results for Image {i+1}")
176
+ st.write("Urbanisation and Population Analysis not implemented yet.")