Intern-4 commited on
Commit
d9f225e
·
1 Parent(s): d84f242

adding table and summary.

Browse files
Files changed (1) hide show
  1. gradio_with_map.py +26 -2
gradio_with_map.py CHANGED
@@ -184,10 +184,19 @@ def predict_image(img, conf_threshold, iou_threshold):
184
  zoom_start=18,
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,7 +212,20 @@ 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
- 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,6 +243,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,
 
184
  zoom_start=18,
185
  tiles='Esri.WorldImagery'
186
  )
187
+
188
+
189
+ # Initialize counters for damaged and undamaged buildings
190
+ damaged_count = 0
191
+ undamaged_count = 0
192
 
193
+ # Add markers for each detected building and count the damaged and undamaged buildings
194
  for i, (building_lat, building_lon, class_id) in enumerate(building_locations):
195
  building_status = 'Damaged' if class_id == 1 else 'Undamaged'
196
+ if class_id == 1:
197
+ damaged_count += 1
198
+ else:
199
+ undamaged_count += 1
200
 
201
  folium.Marker(
202
  location=(building_lat, building_lon),
 
212
  encoded_html = base64.b64encode(folium_map_html.encode()).decode('utf-8')
213
  data_url = f"data:text/html;base64,{encoded_html}"
214
 
215
+ # Create a summary of the building counts
216
+ summary = f"Damaged Buildings: {damaged_count}, Undamaged Buildings: {undamaged_count}"
217
+
218
+ # Create an HTML table for building information
219
+ table_html = "<table style='width: 100%; border-collapse: collapse;'>"
220
+ 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>"
221
+
222
+ for i, (lat, lon, class_id) in enumerate(building_locations):
223
+ building_type = 'Damaged' if class_id == 1 else 'Undamaged'
224
+ 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>"
225
+
226
+ table_html += "</table>"
227
+
228
+ return im, f'<iframe src="{data_url}" width="100%" height="600" style="border:none;"></iframe>', summary, table_html
229
 
230
  description_with_logo = """
231
  <img src="https://www.bewelltech.com.tr/_app/immutable/assets/bewell_logo.fda8f209.png" alt="Logo" style="width: 150px; margin-bottom: 10px;">
 
243
  outputs=[
244
  gr.Image(type="pil", label="Annotated Image"),
245
  gr.HTML(label="Map"),
246
+ gr.HTML(label="Summary"), # New output for the summary
247
+ gr.HTML(label="Building Information"), # New output for the table
248
  ],
249
  title="Custom trained Yolov10 Model on Rescuenet Dataset",
250
  description=description_with_logo,