umgefahren
commited on
Commit
·
bc19b2d
1
Parent(s):
41ca88f
Add progress bars
Browse files
main.py
CHANGED
@@ -64,28 +64,35 @@ def delete_files_in_directory(directory_path: str) -> None:
|
|
64 |
else:
|
65 |
print(f"Skipped non-file: {file_path}")
|
66 |
|
67 |
-
def process_image(image_path: str):
|
68 |
current_directory = os.getcwd()
|
69 |
|
70 |
output_directory = os.path.join(current_directory, "outputs")
|
71 |
if not os.path.exists(output_directory):
|
72 |
os.makedirs(output_directory)
|
73 |
|
|
|
74 |
delete_files_in_directory("tiles")
|
75 |
delete_files_in_directory("tiles/predictions")
|
76 |
delete_files_in_directory("tiles/predictions_geo")
|
77 |
delete_files_in_directory("tree_images")
|
78 |
delete_files_in_directory("detected_trees")
|
|
|
79 |
|
80 |
|
81 |
|
82 |
run_detectree2(image_path, store_path=output_directory)
|
|
|
|
|
83 |
|
84 |
processed_output_df = postprocess(output_directory + '/detectree2_delin.geojson', output_directory + '/processed_delin.geojson')
|
|
|
85 |
|
86 |
processed_geojson = output_directory + '/processed_delin.geojson'
|
87 |
|
|
|
88 |
generate_tree_images(processed_geojson, image_path)
|
|
|
89 |
|
90 |
output_folder = './tree_images'
|
91 |
|
@@ -111,7 +118,9 @@ def process_image(image_path: str):
|
|
111 |
|
112 |
final_output_path = 'result'
|
113 |
|
|
|
114 |
export_geojson(processed_output_df, final_output_path)
|
|
|
115 |
|
116 |
return final_output_path, image_path
|
117 |
|
@@ -168,9 +177,11 @@ def plot_results(geojson_path, image_path):
|
|
168 |
|
169 |
|
170 |
|
171 |
-
def greet(image_path: str):
|
172 |
-
geojson_path, image_path = process_image(image_path)
|
|
|
173 |
fig = plot_results (geojson_path, image_path)
|
|
|
174 |
|
175 |
return fig
|
176 |
|
@@ -191,7 +202,7 @@ def main():
|
|
191 |
outputs=gr.Plot(label="Tree Crowns"),
|
192 |
)
|
193 |
|
194 |
-
demo.launch(server_name='0.0.0.0', debug=True)
|
195 |
|
196 |
if __name__ == "__main__":
|
197 |
main()
|
|
|
64 |
else:
|
65 |
print(f"Skipped non-file: {file_path}")
|
66 |
|
67 |
+
def process_image(image_path: str, progress: gr.Progress):
|
68 |
current_directory = os.getcwd()
|
69 |
|
70 |
output_directory = os.path.join(current_directory, "outputs")
|
71 |
if not os.path.exists(output_directory):
|
72 |
os.makedirs(output_directory)
|
73 |
|
74 |
+
progress(0, desc="Deleting files")
|
75 |
delete_files_in_directory("tiles")
|
76 |
delete_files_in_directory("tiles/predictions")
|
77 |
delete_files_in_directory("tiles/predictions_geo")
|
78 |
delete_files_in_directory("tree_images")
|
79 |
delete_files_in_directory("detected_trees")
|
80 |
+
progress(0.01, desc="Running detectree2")
|
81 |
|
82 |
|
83 |
|
84 |
run_detectree2(image_path, store_path=output_directory)
|
85 |
+
progress(0.2, desc="Ran detectree2")
|
86 |
+
|
87 |
|
88 |
processed_output_df = postprocess(output_directory + '/detectree2_delin.geojson', output_directory + '/processed_delin.geojson')
|
89 |
+
progress(0.4, desc="Post processed")
|
90 |
|
91 |
processed_geojson = output_directory + '/processed_delin.geojson'
|
92 |
|
93 |
+
progress(0.6, desc="Generating tree images")
|
94 |
generate_tree_images(processed_geojson, image_path)
|
95 |
+
progress(0.7, desc="Generated tree images")
|
96 |
|
97 |
output_folder = './tree_images'
|
98 |
|
|
|
118 |
|
119 |
final_output_path = 'result'
|
120 |
|
121 |
+
progress(0.8, desc="Exporting geojson")
|
122 |
export_geojson(processed_output_df, final_output_path)
|
123 |
+
progress(0.9, desc="Exported geojson")
|
124 |
|
125 |
return final_output_path, image_path
|
126 |
|
|
|
177 |
|
178 |
|
179 |
|
180 |
+
def greet(image_path: str, progress=gr.Progress()):
|
181 |
+
geojson_path, image_path = process_image(image_path, progress)
|
182 |
+
progress(0.0, desc="Plotting results")
|
183 |
fig = plot_results (geojson_path, image_path)
|
184 |
+
progress(1, desc="Plotted results")
|
185 |
|
186 |
return fig
|
187 |
|
|
|
202 |
outputs=gr.Plot(label="Tree Crowns"),
|
203 |
)
|
204 |
|
205 |
+
demo.launch(server_name='0.0.0.0', debug=True, show_error=True)
|
206 |
|
207 |
if __name__ == "__main__":
|
208 |
main()
|