alexandrecorreia commited on
Commit
9849e1c
·
1 Parent(s): 67242d6

New format for image storage

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -11,12 +11,17 @@ import urllib.request
11
  from PIL import Image
12
  import requests
13
  import matplotlib.pyplot as plt
 
 
14
 
15
  from transformers import CLIPProcessor, CLIPModel
16
 
17
  model = CLIPModel.from_pretrained("patrickjohncyh/fashion-clip")
18
  processor = CLIPProcessor.from_pretrained("patrickjohncyh/fashion-clip")
19
 
 
 
 
20
  # sys.path.insert(1, 'C:/Users/Alexandre/Documents/University/5_Ano/Estagio/repos_1')
21
 
22
  # Create custom Color objects for our primary, secondary, and neutral colors
@@ -215,6 +220,18 @@ with gr.Blocks(theme=theme, title="New Look", css=css) as demo:
215
  gr.Markdown()
216
  gr.Markdown()
217
 
 
 
 
 
 
 
 
 
 
 
 
 
218
 
219
  def search(text_input, image_input, image_path, text_relevance, image_relevance, best_seller_score_weight):
220
  if text_input == "" and image_input == None:
@@ -251,7 +268,12 @@ with gr.Blocks(theme=theme, title="New Look", css=css) as demo:
251
  return bar_plot, labels_probs
252
 
253
 
 
 
 
254
  search_button.click(
 
 
255
  search, [text_input, image_input, image_path, text_relevance, image_relevance, best_seller_score_weight], [image_res_1, image_res_2, image_res_3, image_res_4, image_res_5, response]
256
  )
257
 
 
11
  from PIL import Image
12
  import requests
13
  import matplotlib.pyplot as plt
14
+ from pathlib import Path
15
+ from datetime import datetime
16
 
17
  from transformers import CLIPProcessor, CLIPModel
18
 
19
  model = CLIPModel.from_pretrained("patrickjohncyh/fashion-clip")
20
  processor = CLIPProcessor.from_pretrained("patrickjohncyh/fashion-clip")
21
 
22
+ static_dir = Path('./static')
23
+ static_dir.mkdir(parents=True, exist_ok=True)
24
+
25
  # sys.path.insert(1, 'C:/Users/Alexandre/Documents/University/5_Ano/Estagio/repos_1')
26
 
27
  # Create custom Color objects for our primary, secondary, and neutral colors
 
220
  gr.Markdown()
221
  gr.Markdown()
222
 
223
+ def load(image_input):
224
+ file_name = f"{datetime.utcnow().strftime('%s')}.jpg"
225
+ file_path = static_dir / file_name
226
+ print(file_path)
227
+ image_input.save("img_path.jpg")
228
+ with open(file_path, "w") as f:
229
+ f.write("""
230
+ {% load static %}
231
+ <img src="{% static 'img_path.jpg' %}" alt="My image">
232
+ """)
233
+ link = f'<a href="file={file_path}" target="_blank">{file_name}</a>'
234
+ return link
235
 
236
  def search(text_input, image_input, image_path, text_relevance, image_relevance, best_seller_score_weight):
237
  if text_input == "" and image_input == None:
 
268
  return bar_plot, labels_probs
269
 
270
 
271
+ # search_button.click(
272
+ # search, [text_input, image_input, image_path, text_relevance, image_relevance, best_seller_score_weight], [image_res_1, image_res_2, image_res_3, image_res_4, image_res_5, response]
273
+ # )
274
  search_button.click(
275
+ load, image_input, image_path
276
+ ).then(
277
  search, [text_input, image_input, image_path, text_relevance, image_relevance, best_seller_score_weight], [image_res_1, image_res_2, image_res_3, image_res_4, image_res_5, response]
278
  )
279