Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from PIL import Image
|
|
| 4 |
import numpy as np
|
| 5 |
import cv2
|
| 6 |
import hashlib
|
|
|
|
| 7 |
import time
|
| 8 |
import os
|
| 9 |
|
|
@@ -60,6 +61,24 @@ def overlay_mask(base_image_path, mean_mask):
|
|
| 60 |
final_image = Image.composite(mask_rgba, base_image, mean_mask_image)
|
| 61 |
return final_image
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
st.title("IB Geo IA Survey")
|
| 64 |
|
| 65 |
# Upload an image
|
|
@@ -82,13 +101,19 @@ canvas_result = st_canvas(
|
|
| 82 |
drawing_mode="freedraw",
|
| 83 |
key="canvas",
|
| 84 |
)
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
if st.button("Save"):
|
| 87 |
|
| 88 |
mask = canvas_to_mask(canvas_result, img_array.shape)
|
| 89 |
if mask is not None:
|
| 90 |
mask = fill_enclosed_areas(mask)
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
else:
|
| 93 |
st.warning("Please draw on the image.")
|
| 94 |
|
|
@@ -108,4 +133,8 @@ if st.button("Aggregate data"):
|
|
| 108 |
mime="image/png"
|
| 109 |
)
|
| 110 |
else:
|
| 111 |
-
st.warning("No saved data found in the data folder.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import cv2
|
| 6 |
import hashlib
|
| 7 |
+
import pyimgur
|
| 8 |
import time
|
| 9 |
import os
|
| 10 |
|
|
|
|
| 61 |
final_image = Image.composite(mask_rgba, base_image, mean_mask_image)
|
| 62 |
return final_image
|
| 63 |
|
| 64 |
+
def delete_files_in_folder(folder_path):
|
| 65 |
+
try:
|
| 66 |
+
# Iterate over all files in the folder
|
| 67 |
+
for filename in os.listdir(folder_path):
|
| 68 |
+
file_path = os.path.join(folder_path, filename)
|
| 69 |
+
|
| 70 |
+
# Check if the path is a file (not a directory)
|
| 71 |
+
if os.path.isfile(file_path):
|
| 72 |
+
# Delete the file
|
| 73 |
+
os.remove(file_path)
|
| 74 |
+
print(f"Deleted: {file_path}")
|
| 75 |
+
|
| 76 |
+
print("All files deleted successfully.")
|
| 77 |
+
|
| 78 |
+
except Exception as e:
|
| 79 |
+
print(f"Error deleting files: {e}")
|
| 80 |
+
|
| 81 |
+
|
| 82 |
st.title("IB Geo IA Survey")
|
| 83 |
|
| 84 |
# Upload an image
|
|
|
|
| 101 |
drawing_mode="freedraw",
|
| 102 |
key="canvas",
|
| 103 |
)
|
| 104 |
+
im = pyimgur.Imgur(
|
| 105 |
+
"253ebfef9de391c"
|
| 106 |
+
)
|
| 107 |
if st.button("Save"):
|
| 108 |
|
| 109 |
mask = canvas_to_mask(canvas_result, img_array.shape)
|
| 110 |
if mask is not None:
|
| 111 |
mask = fill_enclosed_areas(mask)
|
| 112 |
+
cur = generate_short_hash()
|
| 113 |
+
cv2.imwrite(f"data/{cur}.png", mask)
|
| 114 |
+
uploaded_image = im.upload_image(f"data/{cur}.png", title="Data Backup")
|
| 115 |
+
st.markdown(uploaded_image.title)
|
| 116 |
+
st.markdown(uploaded_image.link)
|
| 117 |
else:
|
| 118 |
st.warning("Please draw on the image.")
|
| 119 |
|
|
|
|
| 133 |
mime="image/png"
|
| 134 |
)
|
| 135 |
else:
|
| 136 |
+
st.warning("No saved data found in the data folder.")
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
if st.button("Clear data"):
|
| 140 |
+
delete_files_in_folder("data")
|