matedeaa commited on
Commit
e68ef55
·
verified ·
1 Parent(s): ab3a358

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -26
app.py CHANGED
@@ -3,36 +3,28 @@ from transformers import AutoImageProcessor, AutoModelForObjectDetection
3
  from PIL import Image
4
  import torch
5
 
6
- # Cargar modelo
7
- ckpt = 'yainage90/fashion-object-detection'
8
- processor = AutoImageProcessor.from_pretrained(ckpt)
9
- model = AutoModelForObjectDetection.from_pretrained(ckpt)
10
 
11
- # Precios promedios manuales
12
  PRECIOS = {
13
- 'top': 5000,
14
- 'bottom': 15000,
15
- 'shoes': 30000,
16
- 'bag': 20000,
17
- 'outer': 25000
18
  }
19
 
20
- def procesar_imagen(img):
21
- inputs = processor(images=[img], return_tensors="pt")
22
  outputs = model(**inputs)
23
- results = processor.post_process_object_detection(outputs, threshold=0.4, target_sizes=[[img.height, img.width]])[0]
 
 
 
24
  total = 0
25
- detalle = []
26
- for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
27
- prenda = model.config.id2label[label.item()]
28
- precio = PRECIOS.get(prenda, 0)
29
- total += precio
30
- detalle.append(f"{prenda}: ${precio}")
31
- texto = "\n".join(detalle + [f"\nTotal aprox.: ${total}"])
32
- return texto
33
 
34
- iface = gr.Interface(fn=procesar_imagen,
35
- inputs=gr.Image(type="pil"),
36
- outputs="textbox",
37
- title="Cuánto vale tu outfit?")
38
- iface.launch()
 
3
  from PIL import Image
4
  import torch
5
 
6
+ # Modelo que detecta prendas de vestir
7
+ model_name = "yainage90/fashion-object-detection"
8
+ processor = AutoImageProcessor.from_pretrained(model_name)
9
+ model = AutoModelForObjectDetection.from_pretrained(model_name)
10
 
11
+ # Precios fijos por prenda (estimados)
12
  PRECIOS = {
13
+ 'top': 7000,
14
+ 'bottom': 18000,
15
+ 'shoes': 25000,
16
+ 'bag': 15000,
17
+ 'outer': 22000
18
  }
19
 
20
+ def estimar_precio(imagen):
21
+ inputs = processor(images=imagen, return_tensors="pt")
22
  outputs = model(**inputs)
23
+
24
+ target_size = [imagen.height, imagen.width]
25
+ results = processor.post_process_object_detection(outputs, threshold=0.5, target_sizes=[target_size])[0]
26
+
27
  total = 0
28
+ resumen = []
 
 
 
 
 
 
 
29
 
30
+ for score, label, box in zip(results["scores"], results["labels"], results["box]()