nguyen-brat
commited on
Commit
•
43a3b0d
1
Parent(s):
f9c2ecb
update
Browse files
app.py
CHANGED
@@ -39,6 +39,17 @@ def zip_result_files(result_folder):
|
|
39 |
|
40 |
return zip_buffer
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
st.title("Text Detection App")
|
43 |
|
44 |
uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])
|
@@ -51,9 +62,9 @@ if uploaded_file is not None:
|
|
51 |
# Save the uploaded file temporarily
|
52 |
input_path = "test_folder"
|
53 |
output_path = "target_test"
|
54 |
-
os.makedirs(input_path, exist_ok=True)
|
55 |
-
os.makedirs(osp(output_path, "result"), exist_ok=True)
|
56 |
-
os.makedirs(osp(output_path, "mask"), exist_ok=True)
|
57 |
|
58 |
input_file_path = os.path.join(input_path, uploaded_file.name)
|
59 |
with open(input_file_path, "wb") as f:
|
@@ -65,9 +76,9 @@ if uploaded_file is not None:
|
|
65 |
|
66 |
try:
|
67 |
status_text.text("Running text detection...")
|
68 |
-
os.makedirs(input_path, exist_ok=True)
|
69 |
-
os.makedirs(osp(output_path, "result"), exist_ok=True)
|
70 |
-
os.makedirs(osp(output_path, "mask"), exist_ok=True)
|
71 |
rc, stderr_output = run_bash_script(input_path, output_path, progress_placeholder, status_text)
|
72 |
|
73 |
if rc == 0:
|
@@ -95,7 +106,7 @@ if uploaded_file is not None:
|
|
95 |
st.error(f"An error occurred: {str(e)}")
|
96 |
finally:
|
97 |
# Clean up temporary files
|
98 |
-
|
99 |
progress_placeholder.empty()
|
100 |
status_text.empty()
|
101 |
|
|
|
39 |
|
40 |
return zip_buffer
|
41 |
|
42 |
+
def clear_folder(folder_path):
|
43 |
+
for filename in os.listdir(folder_path):
|
44 |
+
file_path = os.path.join(folder_path, filename)
|
45 |
+
try:
|
46 |
+
if os.path.isfile(file_path) or os.path.islink(file_path):
|
47 |
+
os.unlink(file_path) # Remove file or symlink
|
48 |
+
elif os.path.isdir(file_path):
|
49 |
+
shutil.rmtree(file_path, ignore_errors=True) # Remove directory and its contents
|
50 |
+
except Exception as e:
|
51 |
+
print(f'Failed to delete {file_path}. Reason: {e}')
|
52 |
+
|
53 |
st.title("Text Detection App")
|
54 |
|
55 |
uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])
|
|
|
62 |
# Save the uploaded file temporarily
|
63 |
input_path = "test_folder"
|
64 |
output_path = "target_test"
|
65 |
+
# os.makedirs(input_path, exist_ok=True)
|
66 |
+
# os.makedirs(osp(output_path, "result"), exist_ok=True)
|
67 |
+
# os.makedirs(osp(output_path, "mask"), exist_ok=True)
|
68 |
|
69 |
input_file_path = os.path.join(input_path, uploaded_file.name)
|
70 |
with open(input_file_path, "wb") as f:
|
|
|
76 |
|
77 |
try:
|
78 |
status_text.text("Running text detection...")
|
79 |
+
# os.makedirs(input_path, exist_ok=True)
|
80 |
+
# os.makedirs(osp(output_path, "result"), exist_ok=True)
|
81 |
+
# os.makedirs(osp(output_path, "mask"), exist_ok=True)
|
82 |
rc, stderr_output = run_bash_script(input_path, output_path, progress_placeholder, status_text)
|
83 |
|
84 |
if rc == 0:
|
|
|
106 |
st.error(f"An error occurred: {str(e)}")
|
107 |
finally:
|
108 |
# Clean up temporary files
|
109 |
+
clear_folder(osp(output_path, "mask"))
|
110 |
progress_placeholder.empty()
|
111 |
status_text.empty()
|
112 |
|