#app.py: # from huggingface_hub import from_pretrained_fastai import gradio as gr from fastai.data.block import DataBlock from fastai.data.transforms import get_image_files, FuncSplitter, Normalize from fastai.layers import Mish from fastai.losses import BaseLoss from fastai.optimizer import ranger from fastai.torch_core import tensor from fastai.vision.augment import aug_transforms from fastai.vision.core import PILImage, PILMask from fastai.vision.data import ImageBlock, MaskBlock, imagenet_stats from fastai.vision.learner import unet_learner from PIL import Image import numpy as np from torch import nn import torch import torch.nn.functional as F # # repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME" # repo_id = "islasher/segm-grapes" # repo_id='islasher/segm-grapes' # # Definimos una función que se encarga de llevar a cabo las predicciones # from fastai.learner import load_learner # # Cargar el modelo y el tokenizador # learn = load_learner(repo_id) #learner = from_pretrained_fastai(repo_id) from huggingface_hub import from_pretrained_fastai import torchvision.transforms as transforms class TargetMaskConvertTransform(ItemTransform): def __init__(self): pass def encodes(self, x): img,mask = x #Convert to array mask = np.array(mask) # Changes: (codes= array(['Background', 'Leaves', 'Wood', 'Pole', 'Grape'], dtype='