Spaces:
Runtime error
Runtime error
Daniel Verdu
commited on
Commit
Β·
3c47651
1
Parent(s):
8b64f9e
solved uploading multiple files
Browse files- .gitignore +2 -1
- __pycache__/app_utils.cpython-38.pyc +0 -0
- app.py +29 -17
- deoldify/__pycache__/generators.cpython-38.pyc +0 -0
- deoldify/__pycache__/visualize.cpython-38.pyc +0 -0
.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
__pycache__/
|
|
|
|
1 |
+
__pycache__/
|
2 |
+
**/__pycache__/
|
__pycache__/app_utils.cpython-38.pyc
CHANGED
Binary files a/__pycache__/app_utils.cpython-38.pyc and b/__pycache__/app_utils.cpython-38.pyc differ
|
|
app.py
CHANGED
@@ -1,14 +1,13 @@
|
|
1 |
# Import general purpose libraries
|
2 |
-
import os,
|
3 |
import streamlit as st
|
4 |
import PIL
|
5 |
-
from PIL import Image
|
6 |
import cv2
|
7 |
import numpy as np
|
8 |
import uuid
|
9 |
from zipfile import ZipFile, ZIP_DEFLATED
|
10 |
from io import BytesIO
|
11 |
-
from
|
12 |
|
13 |
# Import util functions from deoldify
|
14 |
# NOTE: This must be the first call in order to work properly!
|
@@ -23,9 +22,16 @@ from app_utils import get_model_bin
|
|
23 |
|
24 |
|
25 |
|
26 |
-
|
27 |
-
model_folder
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
################################
|
30 |
|
31 |
@st.cache(allow_output_mutation=True, show_spinner=False)
|
@@ -101,7 +107,6 @@ def get_button_html_code(data_str, filename, filetype, button_id, button_txt='Do
|
|
101 |
return href
|
102 |
|
103 |
def display_single_image(uploaded_file, img_size=800):
|
104 |
-
print('Type: ', type(uploaded_file))
|
105 |
st_title_message.markdown("**Processing your image, please wait** β")
|
106 |
img_name = uploaded_file.name
|
107 |
|
@@ -134,7 +139,7 @@ def process_multiple_images(uploaded_files, img_size=800):
|
|
134 |
|
135 |
st_progress_bar.progress(0)
|
136 |
|
137 |
-
for idx, uploaded_file in
|
138 |
st_title_message.markdown("**Processing image {}/{}. Please wait** β".format(idx,
|
139 |
num_imgs))
|
140 |
|
@@ -227,7 +232,7 @@ st_color_option = st.sidebar.selectbox('Select colorizer mode',
|
|
227 |
# Load models
|
228 |
try:
|
229 |
print('before loading the model')
|
230 |
-
colorizer = load_model(model_folder, st_color_option)
|
231 |
print('after loading the model')
|
232 |
|
233 |
except Exception as e:
|
@@ -238,19 +243,26 @@ except Exception as e:
|
|
238 |
|
239 |
if colorizer is not None:
|
240 |
st_title_message.markdown("**To begin, please upload an image** π")
|
241 |
-
|
242 |
#Choose your own image
|
243 |
uploaded_files = st_file_uploader.file_uploader("Upload a black and white photo",
|
244 |
type=['png', 'jpg', 'jpeg'],
|
245 |
-
accept_multiple_files=True
|
246 |
-
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
if len(uploaded_files) == 1:
|
249 |
-
display_single_image(uploaded_files[0], max_img_size)
|
250 |
elif len(uploaded_files) > 1:
|
251 |
-
process_multiple_images(uploaded_files, max_img_size)
|
|
|
|
|
252 |
|
253 |
-
# Clear uploaded files
|
254 |
-
uploaded_files.seek(0)
|
255 |
|
256 |
|
|
|
1 |
# Import general purpose libraries
|
2 |
+
import os, re, time
|
3 |
import streamlit as st
|
4 |
import PIL
|
|
|
5 |
import cv2
|
6 |
import numpy as np
|
7 |
import uuid
|
8 |
from zipfile import ZipFile, ZIP_DEFLATED
|
9 |
from io import BytesIO
|
10 |
+
from random import randint
|
11 |
|
12 |
# Import util functions from deoldify
|
13 |
# NOTE: This must be the first call in order to work properly!
|
|
|
22 |
|
23 |
|
24 |
|
25 |
+
SESSION_STATE_VARIABLES = [
|
26 |
+
'model_folder', 'max_img_size', 'uploaded_file_key'
|
27 |
+
]
|
28 |
+
for i in SESSION_STATE_VARIABLES:
|
29 |
+
if i not in st.session_state:
|
30 |
+
st.session_state[i] = None
|
31 |
+
|
32 |
+
#### SET INPUT PARAMS ###########
|
33 |
+
if not st.session_state.model_folder: st.session_state.model_folder = 'models/'
|
34 |
+
if not st.session_state.max_img_size: st.session_state.max_img_size = 800
|
35 |
################################
|
36 |
|
37 |
@st.cache(allow_output_mutation=True, show_spinner=False)
|
|
|
107 |
return href
|
108 |
|
109 |
def display_single_image(uploaded_file, img_size=800):
|
|
|
110 |
st_title_message.markdown("**Processing your image, please wait** β")
|
111 |
img_name = uploaded_file.name
|
112 |
|
|
|
139 |
|
140 |
st_progress_bar.progress(0)
|
141 |
|
142 |
+
for idx, uploaded_file in enumerate(uploaded_files, start=1):
|
143 |
st_title_message.markdown("**Processing image {}/{}. Please wait** β".format(idx,
|
144 |
num_imgs))
|
145 |
|
|
|
232 |
# Load models
|
233 |
try:
|
234 |
print('before loading the model')
|
235 |
+
colorizer = load_model(st.session_state.model_folder, st_color_option)
|
236 |
print('after loading the model')
|
237 |
|
238 |
except Exception as e:
|
|
|
243 |
|
244 |
if colorizer is not None:
|
245 |
st_title_message.markdown("**To begin, please upload an image** π")
|
246 |
+
|
247 |
#Choose your own image
|
248 |
uploaded_files = st_file_uploader.file_uploader("Upload a black and white photo",
|
249 |
type=['png', 'jpg', 'jpeg'],
|
250 |
+
accept_multiple_files=True,
|
251 |
+
key=f"{st.session_state['uploaded_file_key']}"
|
252 |
+
)
|
253 |
+
|
254 |
+
if uploaded_files:
|
255 |
+
|
256 |
+
# # Get only newest elements
|
257 |
+
# new_files = uploaded_files[st.session_state.img_counter:]
|
258 |
+
# st.session_state.img_counter = len(uploaded_files) - st.session_state.img_counter
|
259 |
+
|
260 |
if len(uploaded_files) == 1:
|
261 |
+
display_single_image(uploaded_files[0], st.session_state.max_img_size)
|
262 |
elif len(uploaded_files) > 1:
|
263 |
+
process_multiple_images(uploaded_files, st.session_state.max_img_size)
|
264 |
+
|
265 |
+
st.session_state['uploaded_file_key'] = str(randint(1000, 100000000)) # remove the uploaded file from the UI
|
266 |
|
|
|
|
|
267 |
|
268 |
|
deoldify/__pycache__/generators.cpython-38.pyc
CHANGED
Binary files a/deoldify/__pycache__/generators.cpython-38.pyc and b/deoldify/__pycache__/generators.cpython-38.pyc differ
|
|
deoldify/__pycache__/visualize.cpython-38.pyc
CHANGED
Binary files a/deoldify/__pycache__/visualize.cpython-38.pyc and b/deoldify/__pycache__/visualize.cpython-38.pyc differ
|
|