Commit
·
a5e19ff
1
Parent(s):
f25211b
update
Browse files- Dockerfile +3 -4
- app.py +27 -9
Dockerfile
CHANGED
|
@@ -55,6 +55,9 @@ COPY --chown=user . $HOME/app/text-remove/lama
|
|
| 55 |
RUN curl -LJO https://huggingface.co/smartywu/big-lama/resolve/main/big-lama.zip
|
| 56 |
RUN unzip big-lama.zip
|
| 57 |
|
|
|
|
|
|
|
|
|
|
| 58 |
# RUN useradd -m -u 1000 user
|
| 59 |
# USER user
|
| 60 |
# ENV HOME /home/user
|
|
@@ -63,9 +66,6 @@ RUN unzip big-lama.zip
|
|
| 63 |
# Set the working directory back to the root of the project
|
| 64 |
WORKDIR $HOME/app/text-remove
|
| 65 |
|
| 66 |
-
RUN chmod 777 $HOME/app/text-remove/target_test
|
| 67 |
-
RUN chmod 777 $HOME/app/text-remove/test_folder
|
| 68 |
-
|
| 69 |
# Make port 7860 available to the world outside this container
|
| 70 |
EXPOSE 7860
|
| 71 |
|
|
@@ -74,7 +74,6 @@ ENV PYTHONPATH=$HOME/app/text-remove
|
|
| 74 |
# Run app.py when the container launches
|
| 75 |
ENTRYPOINT ["streamlit", "run"]
|
| 76 |
CMD ["app.py", "--server.port=7860", "--server.headless=true", "--server.enableCORS=false", "--server.enableXsrfProtection=false", "--server.fileWatcherType=none"]
|
| 77 |
-
# CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
|
| 78 |
|
| 79 |
#CMD streamlit run app.py \
|
| 80 |
# ---server.port=7860 \
|
|
|
|
| 55 |
RUN curl -LJO https://huggingface.co/smartywu/big-lama/resolve/main/big-lama.zip
|
| 56 |
RUN unzip big-lama.zip
|
| 57 |
|
| 58 |
+
RUN chmod 777 $HOME/app/text-remove/target_test
|
| 59 |
+
RUN chmod 777 $HOME/app/text-remove/test_folder
|
| 60 |
+
|
| 61 |
# RUN useradd -m -u 1000 user
|
| 62 |
# USER user
|
| 63 |
# ENV HOME /home/user
|
|
|
|
| 66 |
# Set the working directory back to the root of the project
|
| 67 |
WORKDIR $HOME/app/text-remove
|
| 68 |
|
|
|
|
|
|
|
|
|
|
| 69 |
# Make port 7860 available to the world outside this container
|
| 70 |
EXPOSE 7860
|
| 71 |
|
|
|
|
| 74 |
# Run app.py when the container launches
|
| 75 |
ENTRYPOINT ["streamlit", "run"]
|
| 76 |
CMD ["app.py", "--server.port=7860", "--server.headless=true", "--server.enableCORS=false", "--server.enableXsrfProtection=false", "--server.fileWatcherType=none"]
|
|
|
|
| 77 |
|
| 78 |
#CMD streamlit run app.py \
|
| 79 |
# ---server.port=7860 \
|
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import shutil
|
|
| 8 |
import time
|
| 9 |
import sys
|
| 10 |
from PIL import Image
|
|
|
|
| 11 |
|
| 12 |
def GET_PROJECT_ROOT():
|
| 13 |
count = 0
|
|
@@ -68,6 +69,21 @@ def clear_folder(folder_path):
|
|
| 68 |
shutil.rmtree(file_path, ignore_errors=True) # Remove directory and its contents
|
| 69 |
except Exception as e:
|
| 70 |
print(f'Failed to delete {file_path}. Reason: {e}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
st.title("Text Detection App")
|
| 73 |
|
|
@@ -79,15 +95,17 @@ if uploaded_file is not None:
|
|
| 79 |
# Create a temporary directory for processing
|
| 80 |
|
| 81 |
# Save the uploaded file temporarily
|
| 82 |
-
input_path =
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
os.makedirs(
|
| 86 |
-
os.makedirs(osp(output_path, "
|
|
|
|
| 87 |
|
| 88 |
input_file_path = os.path.join(input_path, uploaded_file.name)
|
| 89 |
image = Image.open(uploaded_file)
|
| 90 |
-
image.save(os.path.join(PROJECT_ROOT, input_file_path))
|
|
|
|
| 91 |
|
| 92 |
if st.button("Run Text Detection"):
|
| 93 |
progress_placeholder = st.empty()
|
|
@@ -95,9 +113,9 @@ if uploaded_file is not None:
|
|
| 95 |
|
| 96 |
try:
|
| 97 |
status_text.text("Running text detection...")
|
| 98 |
-
os.makedirs(input_path, exist_ok=True)
|
| 99 |
-
os.makedirs(osp(output_path, "result"), exist_ok=True)
|
| 100 |
-
os.makedirs(osp(output_path, "mask"), exist_ok=True)
|
| 101 |
rc, stderr_output = run_bash_script(input_path, output_path, progress_placeholder, status_text)
|
| 102 |
|
| 103 |
if rc == 0:
|
|
|
|
| 8 |
import time
|
| 9 |
import sys
|
| 10 |
from PIL import Image
|
| 11 |
+
import tempfile
|
| 12 |
|
| 13 |
def GET_PROJECT_ROOT():
|
| 14 |
count = 0
|
|
|
|
| 69 |
shutil.rmtree(file_path, ignore_errors=True) # Remove directory and its contents
|
| 70 |
except Exception as e:
|
| 71 |
print(f'Failed to delete {file_path}. Reason: {e}')
|
| 72 |
+
|
| 73 |
+
def create_temp_structure():
|
| 74 |
+
# Create a temporary directory
|
| 75 |
+
temp_dir = tempfile.mkdtemp()
|
| 76 |
+
|
| 77 |
+
# Create test_folder
|
| 78 |
+
test_folder = os.path.join(temp_dir, "test_folder")
|
| 79 |
+
os.makedirs(test_folder, exist_ok=True)
|
| 80 |
+
|
| 81 |
+
# Create target_folder with mask and result subdirectories
|
| 82 |
+
target_folder = os.path.join(temp_dir, "target_folder")
|
| 83 |
+
os.makedirs(os.path.join(target_folder, "mask"), exist_ok=True)
|
| 84 |
+
os.makedirs(os.path.join(target_folder, "result"), exist_ok=True)
|
| 85 |
+
|
| 86 |
+
return temp_dir, test_folder, target_folder
|
| 87 |
|
| 88 |
st.title("Text Detection App")
|
| 89 |
|
|
|
|
| 95 |
# Create a temporary directory for processing
|
| 96 |
|
| 97 |
# Save the uploaded file temporarily
|
| 98 |
+
_, input_path, output_path = create_temp_structure()
|
| 99 |
+
# input_path = "test_folder"
|
| 100 |
+
# output_path = "target_test"
|
| 101 |
+
# os.makedirs(input_path, exist_ok=True)
|
| 102 |
+
# os.makedirs(osp(output_path, "result"), exist_ok=True)
|
| 103 |
+
# os.makedirs(osp(output_path, "mask"), exist_ok=True)
|
| 104 |
|
| 105 |
input_file_path = os.path.join(input_path, uploaded_file.name)
|
| 106 |
image = Image.open(uploaded_file)
|
| 107 |
+
# image.save(os.path.join(PROJECT_ROOT, input_file_path))
|
| 108 |
+
image.save(input_file_path)
|
| 109 |
|
| 110 |
if st.button("Run Text Detection"):
|
| 111 |
progress_placeholder = st.empty()
|
|
|
|
| 113 |
|
| 114 |
try:
|
| 115 |
status_text.text("Running text detection...")
|
| 116 |
+
#os.makedirs(input_path, exist_ok=True)
|
| 117 |
+
#os.makedirs(osp(output_path, "result"), exist_ok=True)
|
| 118 |
+
#os.makedirs(osp(output_path, "mask"), exist_ok=True)
|
| 119 |
rc, stderr_output = run_bash_script(input_path, output_path, progress_placeholder, status_text)
|
| 120 |
|
| 121 |
if rc == 0:
|