Spaces:
Runtime error
Runtime error
Daniel Verdu
commited on
Commit
·
2ec64cc
1
Parent(s):
3c47651
fixed extra iteration while uploading new files
Browse files
app.py
CHANGED
@@ -23,17 +23,19 @@ from app_utils import get_model_bin
|
|
23 |
|
24 |
|
25 |
SESSION_STATE_VARIABLES = [
|
26 |
-
'model_folder',
|
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)
|
38 |
def load_model(model_dir, option):
|
39 |
if option.lower() == 'artistic':
|
@@ -243,19 +245,15 @@ 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)
|
@@ -263,6 +261,6 @@ if colorizer is not None:
|
|
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 |
|
|
|
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 |
+
|
38 |
+
|
39 |
@st.cache(allow_output_mutation=True, show_spinner=False)
|
40 |
def load_model(model_dir, option):
|
41 |
if option.lower() == 'artistic':
|
|
|
245 |
|
246 |
if colorizer is not None:
|
247 |
st_title_message.markdown("**To begin, please upload an image** 👇")
|
248 |
+
|
249 |
#Choose your own image
|
250 |
uploaded_files = st_file_uploader.file_uploader("Upload a black and white photo",
|
251 |
type=['png', 'jpg', 'jpeg'],
|
252 |
accept_multiple_files=True,
|
253 |
key=f"{st.session_state['uploaded_file_key']}"
|
254 |
)
|
255 |
+
|
256 |
if uploaded_files:
|
|
|
|
|
|
|
|
|
257 |
|
258 |
if len(uploaded_files) == 1:
|
259 |
display_single_image(uploaded_files[0], st.session_state.max_img_size)
|
|
|
261 |
process_multiple_images(uploaded_files, st.session_state.max_img_size)
|
262 |
|
263 |
st.session_state['uploaded_file_key'] = str(randint(1000, 100000000)) # remove the uploaded file from the UI
|
264 |
+
st.experimental_rerun() # Force rerun to reload the file_uploader object with new key
|
265 |
|
266 |
|