Intern-4
commited on
Commit
·
079bb81
1
Parent(s):
80c561d
adding table and information about detected buildings
Browse files- gradio_with_map.py +32 -10
gradio_with_map.py
CHANGED
@@ -15,8 +15,9 @@ import os
|
|
15 |
IMAGE_WIDTH = 4000
|
16 |
IMAGE_HEIGHT = 3000
|
17 |
|
|
|
18 |
# Load YOLO model
|
19 |
-
model = YOLOv10("weights/yolov10m-e100-b16-full-best.pt")
|
20 |
|
21 |
# Define the directory for saving uploaded images
|
22 |
UPLOAD_DIR = 'uploads' # Or any other directory within your project
|
@@ -82,12 +83,7 @@ def predict_image(img, conf_threshold, iou_threshold):
|
|
82 |
print(f"Gimbal Pitch Degree: {gimbal_pitch_degree}")
|
83 |
else:
|
84 |
print("XMP data not found in the image.")
|
85 |
-
|
86 |
-
relative_altitude = 60.0 # Default relative altitude
|
87 |
-
gimbal_yaw_degree = 30.0 # Default yaw degree
|
88 |
-
gimbal_pitch_degree = -90.0 # Default pitch degree
|
89 |
-
|
90 |
-
# Continue with the rest of the function...
|
91 |
# Extract EXIF data
|
92 |
exif_data = img.info.get("exif")
|
93 |
try:
|
@@ -102,7 +98,7 @@ def predict_image(img, conf_threshold, iou_threshold):
|
|
102 |
img.save(img_path, exif=exif_data) # Save the image with its EXIF data
|
103 |
else:
|
104 |
img.save(img_path) # Save without EXIF data if not available
|
105 |
-
|
106 |
# Convert PIL Image to OpenCV image
|
107 |
img_cv2 = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
|
108 |
|
@@ -185,9 +181,17 @@ def predict_image(img, conf_threshold, iou_threshold):
|
|
185 |
tiles='Esri.WorldImagery'
|
186 |
)
|
187 |
|
188 |
-
#
|
|
|
|
|
|
|
|
|
189 |
for i, (building_lat, building_lon, class_id) in enumerate(building_locations):
|
190 |
building_status = 'Damaged' if class_id == 1 else 'Undamaged'
|
|
|
|
|
|
|
|
|
191 |
|
192 |
folium.Marker(
|
193 |
location=(building_lat, building_lon),
|
@@ -203,7 +207,23 @@ def predict_image(img, conf_threshold, iou_threshold):
|
|
203 |
encoded_html = base64.b64encode(folium_map_html.encode()).decode('utf-8')
|
204 |
data_url = f"data:text/html;base64,{encoded_html}"
|
205 |
|
206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
|
208 |
description_with_logo = """
|
209 |
<img src="https://www.bewelltech.com.tr/_app/immutable/assets/bewell_logo.fda8f209.png" alt="Logo" style="width: 150px; margin-bottom: 10px;">
|
@@ -221,6 +241,8 @@ iface = gr.Interface(
|
|
221 |
outputs=[
|
222 |
gr.Image(type="pil", label="Annotated Image"),
|
223 |
gr.HTML(label="Map"),
|
|
|
|
|
224 |
],
|
225 |
title="Custom trained Yolov10 Model on Rescuenet Dataset",
|
226 |
description=description_with_logo,
|
|
|
15 |
IMAGE_WIDTH = 4000
|
16 |
IMAGE_HEIGHT = 3000
|
17 |
|
18 |
+
|
19 |
# Load YOLO model
|
20 |
+
model = YOLOv10("./weights/yolov10m-e100-b16-full-best.pt")
|
21 |
|
22 |
# Define the directory for saving uploaded images
|
23 |
UPLOAD_DIR = 'uploads' # Or any other directory within your project
|
|
|
83 |
print(f"Gimbal Pitch Degree: {gimbal_pitch_degree}")
|
84 |
else:
|
85 |
print("XMP data not found in the image.")
|
86 |
+
|
|
|
|
|
|
|
|
|
|
|
87 |
# Extract EXIF data
|
88 |
exif_data = img.info.get("exif")
|
89 |
try:
|
|
|
98 |
img.save(img_path, exif=exif_data) # Save the image with its EXIF data
|
99 |
else:
|
100 |
img.save(img_path) # Save without EXIF data if not available
|
101 |
+
|
102 |
# Convert PIL Image to OpenCV image
|
103 |
img_cv2 = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
|
104 |
|
|
|
181 |
tiles='Esri.WorldImagery'
|
182 |
)
|
183 |
|
184 |
+
# Initialize counters for damaged and undamaged buildings
|
185 |
+
damaged_count = 0
|
186 |
+
undamaged_count = 0
|
187 |
+
|
188 |
+
# Add markers for each detected building and count the damaged and undamaged buildings
|
189 |
for i, (building_lat, building_lon, class_id) in enumerate(building_locations):
|
190 |
building_status = 'Damaged' if class_id == 1 else 'Undamaged'
|
191 |
+
if class_id == 1:
|
192 |
+
damaged_count += 1
|
193 |
+
else:
|
194 |
+
undamaged_count += 1
|
195 |
|
196 |
folium.Marker(
|
197 |
location=(building_lat, building_lon),
|
|
|
207 |
encoded_html = base64.b64encode(folium_map_html.encode()).decode('utf-8')
|
208 |
data_url = f"data:text/html;base64,{encoded_html}"
|
209 |
|
210 |
+
# Create a summary of the building counts
|
211 |
+
summary = f"Damaged Buildings: {damaged_count}, Undamaged Buildings: {undamaged_count}"
|
212 |
+
|
213 |
+
# Create an HTML table for building information
|
214 |
+
table_html = "<table style='width: 100%; border-collapse: collapse;'>"
|
215 |
+
table_html += "<tr><th style='border: 1px solid black;'>Building Number</th><th style='border: 1px solid black;'>Building Type</th><th style='border: 1px solid black;'>Location (Lat, Lon)</th></tr>"
|
216 |
+
|
217 |
+
for i, (lat, lon, class_id) in enumerate(building_locations):
|
218 |
+
building_type = 'Damaged' if class_id == 1 else 'Undamaged'
|
219 |
+
table_html += f"<tr><td style='border: 1px solid black;'>{i+1}</td><td style='border: 1px solid black;'>{building_type}</td><td style='border: 1px solid black;'>{lat}, {lon}</td></tr>"
|
220 |
+
|
221 |
+
table_html += "</table>"
|
222 |
+
|
223 |
+
return im, f'<iframe src="{data_url}" width="100%" height="600" style="border:none;"></iframe>', summary, table_html
|
224 |
+
|
225 |
+
|
226 |
+
logo_url = "https://www.bewelltech.com.tr/_app/immutable/assets/bewell_logo.fda8f209.png"
|
227 |
|
228 |
description_with_logo = """
|
229 |
<img src="https://www.bewelltech.com.tr/_app/immutable/assets/bewell_logo.fda8f209.png" alt="Logo" style="width: 150px; margin-bottom: 10px;">
|
|
|
241 |
outputs=[
|
242 |
gr.Image(type="pil", label="Annotated Image"),
|
243 |
gr.HTML(label="Map"),
|
244 |
+
gr.HTML(label="Summary"), # New output for the summary
|
245 |
+
gr.HTML(label="Building Information"), # New output for the table
|
246 |
],
|
247 |
title="Custom trained Yolov10 Model on Rescuenet Dataset",
|
248 |
description=description_with_logo,
|