CoolFace
Apppublic

damoref/Practica1

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
app.py20 linesDownload Raw Back to root
1from huggingface_hub import from_pretrained_fastai2import gradio as gr3from fastai.vision.all import *4 5 6 7# repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME"8repo_id = "damoref/p1-model"9 10learner = from_pretrained_fastai(repo_id)11labels = learner.dls.vocab12 13# Definimos una función que se encarga de llevar a cabo las predicciones14def predict(img):15    #img = PILImage.create(img)16    pred,pred_idx,probs = learner.predict(img)17    return {labels[i]: float(probs[i]) for i in range(len(labels))}18    19# Creamos la interfaz y la lanzamos. 20gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(128, 128)), outputs=gr.outputs.Label(num_top_classes=3),examples=['1191_20384_5673.jpg','1031_6038_22742.jpg']).launch(share=False)