is_it_a_llama / app.py
osanseviero's picture
osanseviero HF staff
Create new file
d76860c
import gradio as gr
import torch
from huggingface_hub import from_pretrained_fastai
from pathlib import Path
examples = ["llama.jpg"]
repo_id = "osanseviero/is_it_a_llama"
path = Path("./")
def get_y(r):
return r["label"]
def get_x(r):
return path/r["fname"]
learner = from_pretrained_fastai(repo_id)
labels = learner.dls.vocab
def inference(image):
label_predict,_,probs = learner.predict(image)
labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
return labels_probs
gr.Interface(
fn=inference,
title="Llama image classification",
description = "Predict if this image has a llama (or a forest)",
inputs="image",
outputs="label",
examples=examples,
).launch(debug=True, enable_queue=True)