Huertas97 commited on
Commit
efb9b71
1 Parent(s): d8480c3

Add shortcut to examples

Browse files
Examples_inpainted/meme_1_inpaint.jpeg ADDED
Examples_inpainted/meme_2_inpaint.jpeg ADDED
Examples_inpainted/meme_3_inpaint.jpeg ADDED
app_inpaint.py CHANGED
@@ -11,6 +11,8 @@ import cv2
11
  import numpy as np
12
  import shutil
13
  import base64
 
 
14
 
15
  @st.cache(show_spinner=False, allow_output_mutation=True, suppress_st_warning=True)
16
  def load_models():
@@ -53,7 +55,7 @@ def inpaint_text(img, text_coordinates):
53
  def file_selector(folder_path='.'):
54
  filenames = os.listdir(folder_path)
55
  selected_filename = st.selectbox('Select a file', filenames)
56
- return os.path.join(folder_path, selected_filename)
57
 
58
 
59
 
@@ -130,16 +132,17 @@ with st.expander("Project Description", expanded=False):
130
 
131
 
132
 
133
- filename_example = None
134
  if st.checkbox('Select a example'):
135
  folder_path = './Examples/'
136
  # if st.checkbox('Change directory'):
137
  # folder_path = st.text_input('Enter folder path', '.')
138
- filename_example = file_selector(folder_path=folder_path)
139
- st.write('You selected `%s`' % filename_example)
 
140
 
141
  uploaded_file = st.file_uploader(label="Upload image",
142
- type="jpg",
143
  accept_multiple_files=False,
144
  key=None,
145
  help=None,
@@ -154,30 +157,35 @@ col1, col2, col3 = st.columns([2, 0.5, 2])
154
 
155
 
156
 
157
- if filename_example:
158
  with col1:
159
- st.header("Original")
160
- img = Image.open( filename_example )
 
 
161
  st.image(img, caption=None, width=None, use_column_width=None, clamp=False, channels="RGB", output_format="auto")
162
 
163
  with col3:
164
- st.header("Inpainted")
165
  with st.spinner('Wait for it...'):
166
- img_array = np.array(Image.open( filename_example ))
167
- # detect text
168
- bounds = reader.readtext(img_array, detail=1) #detail=1 # [(coordinates, detected text, confidence threshold)]
169
- text_coordinates = [ bound[0] for bound in bounds]
170
- # inpaint text coordinates
171
- inpaint_image = inpaint_text(img_array, text_coordinates)
 
 
 
172
  st.image(inpaint_image, caption=None, width=None, use_column_width=None, clamp=False, channels="RGB", output_format="auto")
173
 
174
  if uploaded_file:
175
  with col1:
176
- st.header("Original")
177
  st.image(uploaded_file, caption=None, width=None, use_column_width=None, clamp=False, channels="RGB", output_format="auto")
178
 
179
  with col3:
180
- st.header("Inpainted")
181
  with st.spinner('Wait for it...'):
182
  # Transform loaded file to bytes
183
  bytes_data = uploaded_file.getvalue()
 
11
  import numpy as np
12
  import shutil
13
  import base64
14
+ import logging
15
+
16
 
17
  @st.cache(show_spinner=False, allow_output_mutation=True, suppress_st_warning=True)
18
  def load_models():
 
55
  def file_selector(folder_path='.'):
56
  filenames = os.listdir(folder_path)
57
  selected_filename = st.selectbox('Select a file', filenames)
58
+ return os.path.join(folder_path, selected_filename), selected_filename
59
 
60
 
61
 
 
132
 
133
 
134
 
135
+ file_example_path = None
136
  if st.checkbox('Select a example'):
137
  folder_path = './Examples/'
138
  # if st.checkbox('Change directory'):
139
  # folder_path = st.text_input('Enter folder path', '.')
140
+ file_example_path, example_file_name = file_selector(folder_path=folder_path)
141
+ st.write('You selected `%s`' % file_example_path)
142
+
143
 
144
  uploaded_file = st.file_uploader(label="Upload image",
145
+ type=["jpg", "jpeg"],
146
  accept_multiple_files=False,
147
  key=None,
148
  help=None,
 
157
 
158
 
159
 
160
+ if file_example_path and not uploaded_file:
161
  with col1:
162
+ st.subheader("Original")
163
+ st.write(uploaded_file)
164
+ # st.write(f"./Examples_inpainted/{example_file_name.strip(".jpg")}_inpainted.jpeg")
165
+ img = Image.open( file_example_path )
166
  st.image(img, caption=None, width=None, use_column_width=None, clamp=False, channels="RGB", output_format="auto")
167
 
168
  with col3:
169
+ st.subheader("Inpainted")
170
  with st.spinner('Wait for it...'):
171
+ time.sleep(1)
172
+ example_file_name = example_file_name.strip(".jpg")
173
+ inpaint_image = f"./Examples_inpainted/{example_file_name}_inpaint.jpeg"
174
+ # img_array = np.array(Image.open( file_example_path ))
175
+ # # detect text
176
+ # bounds = reader.readtext(img_array, detail=1) #detail=1 # [(coordinates, detected text, confidence threshold)]
177
+ # text_coordinates = [ bound[0] for bound in bounds]
178
+ # # inpaint text coordinates
179
+ # inpaint_image = inpaint_text(img_array, text_coordinates)
180
  st.image(inpaint_image, caption=None, width=None, use_column_width=None, clamp=False, channels="RGB", output_format="auto")
181
 
182
  if uploaded_file:
183
  with col1:
184
+ st.subheader("Original")
185
  st.image(uploaded_file, caption=None, width=None, use_column_width=None, clamp=False, channels="RGB", output_format="auto")
186
 
187
  with col3:
188
+ st.subheader("Inpainted")
189
  with st.spinner('Wait for it...'):
190
  # Transform loaded file to bytes
191
  bytes_data = uploaded_file.getvalue()