Spaces:
Runtime error
Runtime error
kurianbenoy
commited on
Commit
•
328d36e
1
Parent(s):
a81406d
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
from huggingface_hub import from_pretrained_fastai
|
4 |
+
|
5 |
+
repo_id = "kurianbenoy/paddy_convnext_model"
|
6 |
+
learn = from_pretrained_fastai(repo_id)
|
7 |
+
labels = learn.dls.vocab
|
8 |
+
|
9 |
+
def predict(img):
|
10 |
+
img = PILImage.create(img)
|
11 |
+
_pred, _pred_w_idx, probs = learn.predict(img)
|
12 |
+
# gradio doesn't support tensors, so converting to float
|
13 |
+
labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
|
14 |
+
return labels_probs
|
15 |
+
|
16 |
+
interface_options = {
|
17 |
+
"title": "Paddy Doctor",
|
18 |
+
"description": "Paddy cultivation requires consistent supervision because several diseases and pests might affect the paddy crops, leading to up to 70% yield loss. This spaces is an online demo to showcase a model build for [real-world Kaggle competition](https://www.kaggle.com/competitions/paddy-disease-classification/overview).",
|
19 |
+
"interpretation": "default",
|
20 |
+
"layout": "horizontal",
|
21 |
+
# Audio from validation file
|
22 |
+
"examples": [
|
23 |
+
"100098.jpg",
|
24 |
+
],
|
25 |
+
"allow_flagging": "never",
|
26 |
+
}
|
27 |
+
|
28 |
+
demo = gr.Interface(
|
29 |
+
fn=predict,
|
30 |
+
inputs=gr.inputs.Image(shape=(480, 480)),
|
31 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
32 |
+
**interface_options,
|
33 |
+
)
|
34 |
+
|
35 |
+
launch_options = {
|
36 |
+
"enable_queue": True,
|
37 |
+
"share": False,
|
38 |
+
}
|
39 |
+
|
40 |
+
demo.launch(**launch_options)
|