MarkJoshua's picture
Add classifier app
48a4cbc
Raw
History Blame Contribute Delete
912 Bytes
"""
app.py - Gradio app for Hugging Face Spaces
---------------------------------------------
Hosts the Bean Disease Classifier as a permanent, always-on API endpoint
that the Flet app (or anything else) can call.
This file goes in the root of your Hugging Face Space repo alongside
requirements.txt and README.md.
"""
import gradio as gr
from huggingface_hub import from_pretrained_fastai
HF_MODEL_ID = "MarkJoshua/Mak-Bean-Disease-Classifier"
learner = from_pretrained_fastai(HF_MODEL_ID)
def classify(img):
pred_label, pred_idx, probs = learner.predict(img)
vocab = learner.dls.vocab
return {str(vocab[i]): float(probs[i]) for i in range(len(probs))}
demo = gr.Interface(
fn=classify,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=5),
title="Bean Disease Classifier",
description=f"Model: {HF_MODEL_ID}",
)
if __name__ == "__main__":
demo.launch()