Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
CHANGED
|
@@ -3,36 +3,28 @@ from transformers import AutoImageProcessor, AutoModelForObjectDetection
|
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
processor = AutoImageProcessor.from_pretrained(
|
| 9 |
-
model = AutoModelForObjectDetection.from_pretrained(
|
| 10 |
|
| 11 |
-
# Precios
|
| 12 |
PRECIOS = {
|
| 13 |
-
'top':
|
| 14 |
-
'bottom':
|
| 15 |
-
'shoes':
|
| 16 |
-
'bag':
|
| 17 |
-
'outer':
|
| 18 |
}
|
| 19 |
|
| 20 |
-
def
|
| 21 |
-
inputs = processor(images=
|
| 22 |
outputs = model(**inputs)
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
total = 0
|
| 25 |
-
|
| 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 |
-
|
| 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]()
|
|
|
|
|
|
|
|
|
|
|
|