SwapnaneelBanerjee commited on
Commit
ea40630
1 Parent(s): 49692b3

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.py +74 -0
  2. ex1.jpg +0 -0
  3. ex2.jpeg +0 -0
  4. ex3.jpg +0 -0
  5. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
4
+
5
+
6
+ extractor = AutoFeatureExtractor.from_pretrained("susnato/plant_disease_detection-beans")
7
+ model = AutoModelForImageClassification.from_pretrained("susnato/plant_disease_detection-beans")
8
+
9
+ labels = ['angular_leaf_spot', 'rust', 'healthy']
10
+
11
+ def classify(im):
12
+ features = extractor(im, return_tensors='pt')
13
+ logits = model(features["pixel_values"])[-1]
14
+ probability = torch.nn.functional.softmax(logits, dim=-1)
15
+ probs = probability[0].detach().numpy()
16
+ confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
17
+ return confidences
18
+
19
+
20
+ block = gr.Blocks(theme="JohnSmith9982/small_and_pretty")
21
+ with block:
22
+ gr.HTML(
23
+ """
24
+ <h1 align="center">PLANT DISEASE DETECTION<h1>
25
+ """
26
+ )
27
+ with gr.Group():
28
+ with gr.Row():
29
+ gr.HTML(
30
+ """
31
+ <p style="color:black">
32
+ <h4 style="font-color:powderblue;">
33
+ <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. <br><br>
34
+ Using Computer Vision 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>
35
+ </h4>
36
+ </p>
37
+
38
+ <p align="center">
39
+ <img src="https://huggingface.co/datasets/susnato/stock_images/resolve/main/merged.png">
40
+ </p>
41
+ """
42
+ )
43
+
44
+ with gr.Group():
45
+ with gr.Row():
46
+ gr.HTML(
47
+ """
48
+ <center><h3>Our Approach</h3></center>
49
+
50
+ <p align="center">
51
+ <img src="https://huggingface.co/datasets/susnato/stock_images/resolve/main/diagram2.png">
52
+ </p>
53
+ """
54
+ )
55
+
56
+ with gr.Group():
57
+ image = gr.Image(type='pil')
58
+ outputs = gr.Label()
59
+ button = gr.Button("Classify")
60
+
61
+ button.click(classify,
62
+ inputs=[image],
63
+ outputs=[outputs],
64
+ )
65
+
66
+ with gr.Group():
67
+ gr.Examples(["ex3.jpg"],
68
+ fn=classify,
69
+ inputs=[image],
70
+ outputs=[outputs],
71
+ cache_examples=True
72
+ )
73
+
74
+ block.launch(debug=False, share=False)
ex1.jpg ADDED
ex2.jpeg ADDED
ex3.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ torch
2
+ datasets
3
+ torchvision
4
+ git+https://github.com/huggingface/transformers
5
+ gradio