Intern-4
commited on
Commit
·
d84f242
1
Parent(s):
079bb81
fallback to old version
Browse files- gradio_with_map.py +12 -33
gradio_with_map.py
CHANGED
@@ -15,9 +15,8 @@ import os
|
|
15 |
IMAGE_WIDTH = 4000
|
16 |
IMAGE_HEIGHT = 3000
|
17 |
|
18 |
-
|
19 |
# Load YOLO model
|
20 |
-
model = YOLOv10("
|
21 |
|
22 |
# Define the directory for saving uploaded images
|
23 |
UPLOAD_DIR = 'uploads' # Or any other directory within your project
|
@@ -83,7 +82,12 @@ def predict_image(img, conf_threshold, iou_threshold):
|
|
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,7 +102,7 @@ def predict_image(img, conf_threshold, iou_threshold):
|
|
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,17 +185,9 @@ def predict_image(img, conf_threshold, iou_threshold):
|
|
181 |
tiles='Esri.WorldImagery'
|
182 |
)
|
183 |
|
184 |
-
#
|
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,23 +203,7 @@ def predict_image(img, conf_threshold, iou_threshold):
|
|
207 |
encoded_html = base64.b64encode(folium_map_html.encode()).decode('utf-8')
|
208 |
data_url = f"data:text/html;base64,{encoded_html}"
|
209 |
|
210 |
-
|
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,12 +221,11 @@ iface = gr.Interface(
|
|
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,
|
249 |
)
|
250 |
|
251 |
if __name__ == "__main__":
|
252 |
-
iface.launch()
|
|
|
|
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 |
print(f"Gimbal Pitch Degree: {gimbal_pitch_degree}")
|
83 |
else:
|
84 |
print("XMP data not found in the image.")
|
85 |
+
# Set default values when XMP data is not found
|
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 |
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 |
tiles='Esri.WorldImagery'
|
186 |
)
|
187 |
|
188 |
+
# Add markers for each detected building
|
|
|
|
|
|
|
|
|
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 |
encoded_html = base64.b64encode(folium_map_html.encode()).decode('utf-8')
|
204 |
data_url = f"data:text/html;base64,{encoded_html}"
|
205 |
|
206 |
+
return im, f'<iframe src="{data_url}" width="100%" height="600" style="border:none;"></iframe>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
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,
|
227 |
)
|
228 |
|
229 |
if __name__ == "__main__":
|
230 |
+
iface.launch()
|
231 |
+
|