Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
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()
|