Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,11 +10,6 @@ from albumentations import (
|
|
| 10 |
from pathlib import Path
|
| 11 |
import torch
|
| 12 |
|
| 13 |
-
# ✅ 1. Evita imports repetidos e innecesarios
|
| 14 |
-
# ❌ ya importaste fastai.vision.all que lo incluye todo
|
| 15 |
-
# ❌ ya tienes PIL y transforms más arriba
|
| 16 |
-
|
| 17 |
-
# ✅ 2. Función de preprocesamiento
|
| 18 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 19 |
|
| 20 |
def transform_image(image):
|
|
@@ -25,7 +20,6 @@ def transform_image(image):
|
|
| 25 |
])
|
| 26 |
return preprocess(image).unsqueeze(0).to(device)
|
| 27 |
|
| 28 |
-
# ✅ 3. Funciones y clases necesarias para cargar el modelo
|
| 29 |
def get_y_fn(x):
|
| 30 |
return Path(str(x).replace("Images", "Labels").replace("color", "gt").replace(".jpg", ".png"))
|
| 31 |
|
|
@@ -48,12 +42,10 @@ class SegmentationAlbumentationsTransform(ItemTransform):
|
|
| 48 |
aug = self.aug(image=np.array(img), mask=np.array(mask))
|
| 49 |
return PILImage.create(aug["image"]), PILMask.create(aug["mask"])
|
| 50 |
|
| 51 |
-
# ✅ 4. Carga del modelo desde el hub
|
| 52 |
repo_id = "PablitoGil14/AP-Practica3"
|
| 53 |
learn = from_pretrained_fastai(repo_id)
|
| 54 |
model = learn.model.cpu()
|
| 55 |
|
| 56 |
-
# ✅ 5. Función de predicción
|
| 57 |
def predict(img_input):
|
| 58 |
image = Image.fromarray(img_input).resize((640, 480))
|
| 59 |
tensor = transform_image(image)
|
|
@@ -70,7 +62,6 @@ def predict(img_input):
|
|
| 70 |
colored[pred == 4] = 74
|
| 71 |
return Image.fromarray(colored)
|
| 72 |
|
| 73 |
-
# ✅ 6. Interfaz Gradio moderna (gr.Image en lugar de .inputs.Image)
|
| 74 |
demo = gr.Interface(
|
| 75 |
fn=predict,
|
| 76 |
inputs=gr.Image(type="numpy", label="Sube una imagen", shape=(480, 640)),
|
|
|
|
| 10 |
from pathlib import Path
|
| 11 |
import torch
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 14 |
|
| 15 |
def transform_image(image):
|
|
|
|
| 20 |
])
|
| 21 |
return preprocess(image).unsqueeze(0).to(device)
|
| 22 |
|
|
|
|
| 23 |
def get_y_fn(x):
|
| 24 |
return Path(str(x).replace("Images", "Labels").replace("color", "gt").replace(".jpg", ".png"))
|
| 25 |
|
|
|
|
| 42 |
aug = self.aug(image=np.array(img), mask=np.array(mask))
|
| 43 |
return PILImage.create(aug["image"]), PILMask.create(aug["mask"])
|
| 44 |
|
|
|
|
| 45 |
repo_id = "PablitoGil14/AP-Practica3"
|
| 46 |
learn = from_pretrained_fastai(repo_id)
|
| 47 |
model = learn.model.cpu()
|
| 48 |
|
|
|
|
| 49 |
def predict(img_input):
|
| 50 |
image = Image.fromarray(img_input).resize((640, 480))
|
| 51 |
tensor = transform_image(image)
|
|
|
|
| 62 |
colored[pred == 4] = 74
|
| 63 |
return Image.fromarray(colored)
|
| 64 |
|
|
|
|
| 65 |
demo = gr.Interface(
|
| 66 |
fn=predict,
|
| 67 |
inputs=gr.Image(type="numpy", label="Sube una imagen", shape=(480, 640)),
|