umgefahren
commited on
Commit
·
576a42b
1
Parent(s):
d055ece
This is great and plotly
Browse files- Dockerfile +1 -0
- main.py +42 -43
Dockerfile
CHANGED
@@ -37,6 +37,7 @@ RUN python -m pip install git+https://github.com/PatBall1/detectree2.git
|
|
37 |
RUN python -m pip install opencv-python
|
38 |
RUN python -m pip install requests
|
39 |
|
|
|
40 |
RUN python -m pip install gradio
|
41 |
|
42 |
COPY --chown=user . $HOME/app
|
|
|
37 |
RUN python -m pip install opencv-python
|
38 |
RUN python -m pip install requests
|
39 |
|
40 |
+
RUN python -m pip install plotly
|
41 |
RUN python -m pip install gradio
|
42 |
|
43 |
COPY --chown=user . $HOME/app
|
main.py
CHANGED
@@ -8,8 +8,8 @@ import gradio as gr
|
|
8 |
import rasterio
|
9 |
from rasterio.plot import show
|
10 |
import geopandas as gpd
|
11 |
-
import matplotlib.pyplot as plt
|
12 |
from shapely.geometry import Point
|
|
|
13 |
|
14 |
|
15 |
|
@@ -97,54 +97,53 @@ def greet(image_path: str):
|
|
97 |
# Set the interactive backend to Qt5Agg
|
98 |
# plt.switch_backend('Qt5Agg') # You have to install PyQt5
|
99 |
|
100 |
-
# Enable interactive mode
|
101 |
-
plt.ion()
|
102 |
-
|
103 |
# Plotting
|
104 |
-
fig
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
111 |
|
112 |
# Set plot title
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
break
|
141 |
-
|
142 |
# Connect the click event to the handler function
|
143 |
-
|
|
|
144 |
|
145 |
-
|
146 |
|
147 |
-
return figure
|
148 |
|
149 |
#tif_file_name = "TreeCrownVectorDataset_761588_9673769_20_20_32720.tif"
|
150 |
#tif_input = "/Users/jonathanseele/ETH/Hackathons/EcoHackathon/WeCanopy/test/" + tif_file_name
|
|
|
8 |
import rasterio
|
9 |
from rasterio.plot import show
|
10 |
import geopandas as gpd
|
|
|
11 |
from shapely.geometry import Point
|
12 |
+
import plotly.grraph_objects as go
|
13 |
|
14 |
|
15 |
|
|
|
97 |
# Set the interactive backend to Qt5Agg
|
98 |
# plt.switch_backend('Qt5Agg') # You have to install PyQt5
|
99 |
|
|
|
|
|
|
|
100 |
# Plotting
|
101 |
+
fig = go.Figure()
|
102 |
+
fig.add_trace(go.Image(z=tif_image.transpose((1, 2, 0))))
|
103 |
+
for idx, row in geojson_data.iterrows():
|
104 |
+
geojson_dict = json.loads(row['geometry'].to_json())
|
105 |
+
fig.add_trace(go.Scattergeo(
|
106 |
+
lon=[coord[0] for coord in geojson_dict['coordinates'][0]],
|
107 |
+
lat=[coord[1] for coord in geojson_dict['coordinates'][0]],
|
108 |
+
mode='lines',
|
109 |
+
line=dict(color='red'),
|
110 |
+
name=f'Polygon {idx}'
|
111 |
+
))
|
112 |
|
113 |
# Set plot title
|
114 |
+
fig.update_layout(
|
115 |
+
title='TIF Image with Tree Crowns Overlay',
|
116 |
+
geo=dict(
|
117 |
+
projection_scale=1,
|
118 |
+
center=dict(
|
119 |
+
lon=tif_transform.c + (tif_transform.a * tif_image.width / 2),
|
120 |
+
lat=tif_transform.f + (tif_transform.e * tif_image.height / 2)
|
121 |
+
)
|
122 |
+
)
|
123 |
+
)
|
124 |
+
|
125 |
+
# Function to handle click events
|
126 |
+
def on_click(trace, points, state):
|
127 |
+
if points.point_inds:
|
128 |
+
idx = points.point_inds[0]
|
129 |
+
row = geojson_data.iloc[idx]
|
130 |
+
species_info = row['species']
|
131 |
+
confidence_score = row['Confidence_score']
|
132 |
+
text = f"Polygon {idx}\n\nConfidence:\n{confidence_score}\n\nSpecies and their probability:\n{species_info}"
|
133 |
+
fig.update_layout(annotations=[dict(
|
134 |
+
x=points.xs[0],
|
135 |
+
y=points.ys[0],
|
136 |
+
text=text,
|
137 |
+
showarrow=True,
|
138 |
+
arrowhead=7
|
139 |
+
)])
|
140 |
+
|
|
|
|
|
141 |
# Connect the click event to the handler function
|
142 |
+
for trace in fig.data:
|
143 |
+
trace.on_click(on_click)
|
144 |
|
145 |
+
return fig
|
146 |
|
|
|
147 |
|
148 |
#tif_file_name = "TreeCrownVectorDataset_761588_9673769_20_20_32720.tif"
|
149 |
#tif_input = "/Users/jonathanseele/ETH/Hackathons/EcoHackathon/WeCanopy/test/" + tif_file_name
|