asdfghjk1 commited on
Commit
96effb7
·
verified ·
1 Parent(s): 0e91aba
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from huggingface_hub import from_pretrained_fastai
4
+ from pathlib import Path
5
+
6
+ examples = ["examples/example_0.png",
7
+ "examples/example_1.png",
8
+ "examples/example_2.png",
9
+ "examples/example_3.png",
10
+ "examples/example_4.png"]
11
+
12
+ repo_id = "hugginglearners/rice_image_classification"
13
+ path = Path("./")
14
+
15
+ def get_y(r):
16
+ return r["label"]
17
+
18
+ def get_x(r):
19
+ return path/r["fname"]
20
+
21
+ learner = from_pretrained_fastai(repo_id)
22
+ labels = learner.dls.vocab
23
+
24
+ def inference(image):
25
+ label_predict, _, probs = learner.predict(image)
26
+ labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
27
+ return labels_probs
28
+
29
+ gr.Interface(
30
+ fn=inference,
31
+ title="Rice Disease Classification",
32
+ description="Predict which type of rice disease is affecting the leaf: Tungro, Rice Blast, Bacterial Blight, or Healthy Rice Leaf.",
33
+ inputs=gr.Image(),
34
+ examples=examples,
35
+ outputs=gr.Label(num_top_classes=4, label='Prediction'),
36
+ cache_examples=False,
37
+ article="Authors: Your Team Name",
38
+ ).launch(debug=True, enable_queue=True)