susnato commited on
Commit
1a3049d
1 Parent(s): be83fa0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+
3
+ import torch
4
+ import gradio as gr
5
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
6
+
7
+ dataset = load_dataset("beans")
8
+
9
+ extractor = AutoFeatureExtractor.from_pretrained("nateraw/vit-base-beans")
10
+ model = AutoModelForImageClassification.from_pretrained("nateraw/vit-base-beans")
11
+
12
+ labels = ['angular_leaf_spot', 'rust', 'healthy']
13
+
14
+ def classify(im):
15
+ features = extractor(im, return_tensors='pt')
16
+ logits = model(features["pixel_values"])[-1]
17
+ probability = torch.nn.functional.softmax(logits, dim=-1)
18
+ probs = probability[0].detach().numpy()
19
+ confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
20
+ return confidences
21
+
22
+
23
+ block = gr.Blocks(theme="gary109/HaleyCH_Theme")
24
+ with block:
25
+ gr.HTML(
26
+ """
27
+ <h1 align="center">PLANT DISEASE DETECTION<h1>
28
+ """
29
+ )
30
+ with gr.Group():
31
+ with gr.Row():
32
+ gr.HTML(
33
+ """
34
+ <p style="color:black">
35
+ <h4 style="font-color:powderblue;">
36
+ <center>Crop diseases are a major threat to food security, but their rapid identification remains difficult in many parts of the world due to the lack of the necessary infrastructure. The combination of increasing global smartphone penetration and recent advances in computer vision made possible by deep learning has paved the way for smartphone-assisted disease diagnosis.</center>
37
+ <br>
38
+ <center>Using A.I. models in plant disease detection and diagnosis has the potential to revolutionize the way we approach agriculture. By providing real-time monitoring and accurate detection of plant diseases, A.I. can help farmers reduce costs and increase crop</center>
39
+ </h4>
40
+ </p>
41
+
42
+ <p align="center">
43
+ <img src="https://huggingface.co/datasets/susnato/stock_images/resolve/main/merged.png">
44
+ </p>
45
+ """
46
+ )
47
+
48
+ with gr.Group():
49
+ image = gr.Image(type='pil')
50
+ outputs = gr.Label()
51
+ button = gr.Button("Classify")
52
+
53
+ button.click(classify,
54
+ inputs=[image],
55
+ outputs=[outputs],
56
+ )
57
+
58
+ with gr.Group():
59
+ gr.Examples([
60
+ ["ex1.jpg", "ex3.jpg"],
61
+ ],
62
+ fn=classify,
63
+ inputs=[image],
64
+ outputs=[outputs],
65
+ cache_examples=True
66
+ )
67
+
68
+ block.launch(debug=False, share=False)