Daniel Verdu commited on
Commit
1046ee7
β€’
1 Parent(s): 6fca209

fixing loading model

Browse files
Files changed (1) hide show
  1. app.py +23 -21
app.py CHANGED
@@ -34,7 +34,7 @@ model_folder = 'models/'
34
  max_img_size = 800
35
  ################################
36
 
37
- # @st.cache(allow_output_mutation=True)
38
  def load_model(model_dir, option):
39
  if option.lower() == 'artistic':
40
  model_url = 'https://data.deepai.org/deoldify/ColorizeArtistic_gen.pth'
@@ -132,34 +132,36 @@ color_option = st.sidebar.selectbox('Select colorizer mode',
132
  try:
133
  colorizer = load_model(model_folder, color_option)
134
  except:
 
135
  print('Error while loading the model. Please refresh the page')
136
 
137
- title_message.markdown("**To begin, please upload an image** πŸ‘‡")
 
138
 
139
- #Choose your own image
140
- uploaded_file = st.file_uploader("Upload a black and white photo", type=['png', 'jpg', 'jpeg'])
141
 
142
- # show = st.image(use_column_width='auto')
143
- input_img_pos = st.empty()
144
- output_img_pos = st.empty()
145
 
146
- if uploaded_file is not None:
147
- img_name = uploaded_file.name
148
 
149
- pil_img = PIL.Image.open(uploaded_file)
150
- img_rgb = np.array(pil_img)
151
 
152
- resized_img_rgb = resize_img(img_rgb, max_img_size)
153
- resized_pil_img = PIL.Image.fromarray(resized_img_rgb)
154
 
155
- title_message.markdown("**Processing your image, please wait** βŒ›")
156
 
157
- output_pil_img = colorizer.plot_transformed_pil_image(resized_pil_img, render_factor=35, compare=False)
158
-
159
- title_message.markdown("**To begin, please upload an image** πŸ‘‡")
160
 
161
- # Plot images
162
- input_img_pos.image(resized_pil_img, 'Input image', use_column_width=True)
163
- output_img_pos.image(output_pil_img, 'Output image', use_column_width=True)
164
 
165
- st.markdown(get_image_download_link(output_pil_img, img_name, 'Download '+img_name), unsafe_allow_html=True)
 
34
  max_img_size = 800
35
  ################################
36
 
37
+ @st.cache(allow_output_mutation=True)
38
  def load_model(model_dir, option):
39
  if option.lower() == 'artistic':
40
  model_url = 'https://data.deepai.org/deoldify/ColorizeArtistic_gen.pth'
 
132
  try:
133
  colorizer = load_model(model_folder, color_option)
134
  except:
135
+ colorizer = None
136
  print('Error while loading the model. Please refresh the page')
137
 
138
+ if colorizer is not None:
139
+ title_message.markdown("**To begin, please upload an image** πŸ‘‡")
140
 
141
+ #Choose your own image
142
+ uploaded_file = st.file_uploader("Upload a black and white photo", type=['png', 'jpg', 'jpeg'])
143
 
144
+ # show = st.image(use_column_width='auto')
145
+ input_img_pos = st.empty()
146
+ output_img_pos = st.empty()
147
 
148
+ if uploaded_file is not None:
149
+ img_name = uploaded_file.name
150
 
151
+ pil_img = PIL.Image.open(uploaded_file)
152
+ img_rgb = np.array(pil_img)
153
 
154
+ resized_img_rgb = resize_img(img_rgb, max_img_size)
155
+ resized_pil_img = PIL.Image.fromarray(resized_img_rgb)
156
 
157
+ title_message.markdown("**Processing your image, please wait** βŒ›")
158
 
159
+ output_pil_img = colorizer.plot_transformed_pil_image(resized_pil_img, render_factor=35, compare=False)
160
+
161
+ title_message.markdown("**To begin, please upload an image** πŸ‘‡")
162
 
163
+ # Plot images
164
+ input_img_pos.image(resized_pil_img, 'Input image', use_column_width=True)
165
+ output_img_pos.image(output_pil_img, 'Output image', use_column_width=True)
166
 
167
+ st.markdown(get_image_download_link(output_pil_img, img_name, 'Download '+img_name), unsafe_allow_html=True)