File size: 1,378 Bytes
e43c5ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr

from tools.extract_features import extract_features_image
from tools.search import search_similar_products
from tools.load_database import select_database

# Default values
MARCAS = ["Ninguno", "Zara", "Adidas", "Nike", "Puma", "Levi's", "Forever 21", "H&M", "Gap", "Converse", "Mango"]
PRENDAS = ["bag", "dress", "hat", "jacket", "pants", "shirt", "shoe", "shorts", "skirt", "sunglass"]


def process_image(image, marca, prenda):
   """Visual Search Pipeline"""
   vgg_search = extract_features_image(image)
   database = select_database(marca, prenda)
   result = search_similar_products(vgg_search, database)
   return result


# Gradio app
examples = [
    ["examples/bag_93.99.png", "Adidas", "bag"],
    ["examples/shirt_82.84.png", "Nike", "shirt"],
    ["examples/skirt_87.54.png", "Puma", "skirt"]
]

title =  "Visual Search 🔍 | Powered by Xpertium SA"
description =  """
               <p style='text-align: center'>Carga tu imagen y selecciona la marca & tipo de prenda.</p>
               """

iface = gr.Interface(
  fn=process_image, 
  inputs=[
     gr.Image(label="imagen"), 
     gr.Dropdown(label="marca", choices=MARCAS, value=MARCAS[1]),
     gr.Dropdown(label="prenda", choices=PRENDAS, value=PRENDAS[1]),
     ], 
  outputs=gr.JSON(label="resultado"),
  title=title,
  examples=examples,
  description=description
)

iface.launch()