Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -273,4 +273,111 @@ def analyze_tree(image, latitude, longitude):
|
|
273 |
map_html = "<p>Could not generate map</p>"
|
274 |
else:
|
275 |
location_result = "No GPS coordinates provided"
|
276 |
-
map_html = "<p>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
map_html = "<p>Could not generate map</p>"
|
274 |
else:
|
275 |
location_result = "No GPS coordinates provided"
|
276 |
+
map_html = "<p>No location data available</p>"
|
277 |
+
|
278 |
+
return species_status, height_result, species_text, location_result, map_html
|
279 |
+
|
280 |
+
except Exception as e:
|
281 |
+
logger.error(f"Analysis failed: {e}")
|
282 |
+
return f"Analysis failed: {str(e)}", "", "", "", ""
|
283 |
+
|
284 |
+
# Gradio interface
|
285 |
+
def create_interface():
|
286 |
+
"""Create the Gradio interface"""
|
287 |
+
with gr.Blocks(title="Tree Analyzer", theme=gr.themes.Soft()) as demo:
|
288 |
+
gr.HTML("""
|
289 |
+
<div style="text-align: center; padding: 20px;">
|
290 |
+
<h1>π³ Tree Analyzer</h1>
|
291 |
+
<p>Upload an image of a tree and optionally provide GPS coordinates for comprehensive analysis</p>
|
292 |
+
</div>
|
293 |
+
""")
|
294 |
+
|
295 |
+
with gr.Row():
|
296 |
+
with gr.Column(scale=1):
|
297 |
+
image_input = gr.Image(
|
298 |
+
type="pil",
|
299 |
+
label="Upload Tree Image",
|
300 |
+
height=400
|
301 |
+
)
|
302 |
+
|
303 |
+
with gr.Row():
|
304 |
+
lat_input = gr.Number(
|
305 |
+
label="Latitude",
|
306 |
+
placeholder="e.g., 40.7128",
|
307 |
+
precision=6
|
308 |
+
)
|
309 |
+
lon_input = gr.Number(
|
310 |
+
label="Longitude",
|
311 |
+
placeholder="e.g., -74.0060",
|
312 |
+
precision=6
|
313 |
+
)
|
314 |
+
|
315 |
+
analyze_btn = gr.Button("π Analyze Tree", variant="primary", size="lg")
|
316 |
+
|
317 |
+
gr.HTML("""
|
318 |
+
<div style="margin-top: 20px; padding: 15px; background-color: #f0f0f0; border-radius: 8px;">
|
319 |
+
<h4>π How to get GPS coordinates:</h4>
|
320 |
+
<ul>
|
321 |
+
<li>Google Maps: Right-click location β Copy coordinates</li>
|
322 |
+
<li>Phone: Use GPS coordinate apps</li>
|
323 |
+
<li>Camera: Check photo metadata for GPS info</li>
|
324 |
+
</ul>
|
325 |
+
</div>
|
326 |
+
""")
|
327 |
+
|
328 |
+
with gr.Column(scale=2):
|
329 |
+
with gr.Tab("π Analysis Results"):
|
330 |
+
status_output = gr.Textbox(
|
331 |
+
label="Analysis Status",
|
332 |
+
interactive=False
|
333 |
+
)
|
334 |
+
|
335 |
+
height_output = gr.Textbox(
|
336 |
+
label="Height Estimation",
|
337 |
+
interactive=False,
|
338 |
+
lines=3
|
339 |
+
)
|
340 |
+
|
341 |
+
species_output = gr.Markdown(
|
342 |
+
label="Species Identification",
|
343 |
+
height=300
|
344 |
+
)
|
345 |
+
|
346 |
+
with gr.Tab("πΊοΈ Location"):
|
347 |
+
location_output = gr.Textbox(
|
348 |
+
label="Location Information",
|
349 |
+
interactive=False
|
350 |
+
)
|
351 |
+
|
352 |
+
map_output = gr.HTML(
|
353 |
+
label="Location Map",
|
354 |
+
height=400
|
355 |
+
)
|
356 |
+
|
357 |
+
# Connect the analyze button
|
358 |
+
analyze_btn.click(
|
359 |
+
fn=analyze_tree,
|
360 |
+
inputs=[image_input, lat_input, lon_input],
|
361 |
+
outputs=[status_output, height_output, species_output, location_output, map_output]
|
362 |
+
)
|
363 |
+
|
364 |
+
gr.HTML("""
|
365 |
+
<div style="text-align: center; padding: 20px; margin-top: 30px; border-top: 1px solid #ddd;">
|
366 |
+
<p><strong>Features:</strong></p>
|
367 |
+
<p>π Species identification using AI models | π Height estimation via depth analysis | πΊοΈ Location mapping | π Wikipedia integration</p>
|
368 |
+
<p style="color: #666; font-size: 0.9em;">
|
369 |
+
Note: This tool provides estimates and suggestions. For scientific purposes, consult with professional botanists or arborists.
|
370 |
+
</p>
|
371 |
+
</div>
|
372 |
+
""")
|
373 |
+
|
374 |
+
return demo
|
375 |
+
|
376 |
+
if __name__ == "__main__":
|
377 |
+
# Create and launch the interface
|
378 |
+
demo = create_interface()
|
379 |
+
demo.launch(
|
380 |
+
share=True,
|
381 |
+
debug=True,
|
382 |
+
show_error=True
|
383 |
+
)
|