Spaces:
Runtime error
Runtime error
Commit ·
48a4cbc
1
Parent(s): 3ce114d
Add classifier app
Browse files- main.py +34 -0
- requirements.txt +3 -0
main.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
app.py - Gradio app for Hugging Face Spaces
|
| 3 |
+
---------------------------------------------
|
| 4 |
+
Hosts the Bean Disease Classifier as a permanent, always-on API endpoint
|
| 5 |
+
that the Flet app (or anything else) can call.
|
| 6 |
+
|
| 7 |
+
This file goes in the root of your Hugging Face Space repo alongside
|
| 8 |
+
requirements.txt and README.md.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import gradio as gr
|
| 12 |
+
from huggingface_hub import from_pretrained_fastai
|
| 13 |
+
|
| 14 |
+
HF_MODEL_ID = "MarkJoshua/Mak-Bean-Disease-Classifier"
|
| 15 |
+
|
| 16 |
+
learner = from_pretrained_fastai(HF_MODEL_ID)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def classify(img):
|
| 20 |
+
pred_label, pred_idx, probs = learner.predict(img)
|
| 21 |
+
vocab = learner.dls.vocab
|
| 22 |
+
return {str(vocab[i]): float(probs[i]) for i in range(len(probs))}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
demo = gr.Interface(
|
| 26 |
+
fn=classify,
|
| 27 |
+
inputs=gr.Image(type="pil"),
|
| 28 |
+
outputs=gr.Label(num_top_classes=5),
|
| 29 |
+
title="Bean Disease Classifier",
|
| 30 |
+
description=f"Model: {HF_MODEL_ID}",
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastai==2.8.7
|
| 2 |
+
huggingface_hub>=1.21.0
|
| 3 |
+
gradio
|