nguyen-brat commited on
Commit
f9c2ecb
·
1 Parent(s): 0855034
Files changed (2) hide show
  1. Dockerfile +0 -1
  2. app.py +3 -19
Dockerfile CHANGED
@@ -82,4 +82,3 @@ CMD ["app.py", "--server.port=7860", "--server.headless=true", "--server.enableC
82
  # --server.fileWatcherType none
83
 
84
 
85
-
 
82
  # --server.fileWatcherType none
83
 
84
 
 
app.py CHANGED
@@ -39,28 +39,10 @@ def zip_result_files(result_folder):
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"])
56
 
57
- if uploaded_file is not None:
58
- input_path = "test_folder"
59
- output_path = "target_test"
60
- input_file_path = os.path.join(input_path, uploaded_file.name)
61
- with open(input_file_path, "wb") as f:
62
- f.write(uploaded_file.getbuffer())
63
-
64
  if uploaded_file is not None:
65
  st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
66
 
@@ -74,6 +56,8 @@ if uploaded_file is not None:
74
  os.makedirs(osp(output_path, "mask"), exist_ok=True)
75
 
76
  input_file_path = os.path.join(input_path, uploaded_file.name)
 
 
77
 
78
  if st.button("Run Text Detection"):
79
  progress_placeholder = st.empty()
@@ -111,7 +95,7 @@ if uploaded_file is not None:
111
  st.error(f"An error occurred: {str(e)}")
112
  finally:
113
  # Clean up temporary files
114
- clear_folder(osp(output_path, "mask"))
115
  progress_placeholder.empty()
116
  status_text.empty()
117
 
 
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"])
45
 
 
 
 
 
 
 
 
46
  if uploaded_file is not None:
47
  st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
48
 
 
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:
60
+ f.write(uploaded_file.getbuffer())
61
 
62
  if st.button("Run Text Detection"):
63
  progress_placeholder = st.empty()
 
95
  st.error(f"An error occurred: {str(e)}")
96
  finally:
97
  # Clean up temporary files
98
+ shutil.rmtree(osp(output_path, "mask"), ignore_errors=True)
99
  progress_placeholder.empty()
100
  status_text.empty()
101