Skip to content

Commit d995ec2

Browse files
committed
upadted and deployed flask server
1 parent 2a3b775 commit d995ec2

20 files changed

+663
-48
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*/__pycache__

Assets/web.gif

4.58 MB
Loading
81.4 MB
Binary file not shown.

Flask/Template/images/b3.jpg

-82 KB
Binary file not shown.

Flask/Template/images/b6.jpg

-65.8 KB
Binary file not shown.

Flask/app.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from flask import Flask, render_template, jsonify, request, Markup
2+
from model import predict_image
3+
import utils
4+
5+
app = Flask(__name__)
6+
7+
8+
@app.route('/', methods=['GET'])
9+
def home():
10+
return render_template('index.html')
11+
12+
13+
@app.route('/predict', methods=['GET', 'POST'])
14+
def predict():
15+
if request.method == 'POST':
16+
try:
17+
file = request.files['file']
18+
img = file.read()
19+
prediction = predict_image(img)
20+
print(prediction)
21+
res = Markup(utils.disease_dic[prediction])
22+
return render_template('display.html', status=200, result=res)
23+
except:
24+
pass
25+
return render_template('index.html', status=500, res="Internal Server Error")
26+
27+
28+
if __name__ == "__main__":
29+
app.run(debug=True)

Flask/model.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import torch
2+
import torch.nn as nn
3+
import torchvision.models as models
4+
import torchvision.transforms as transforms
5+
from PIL import Image
6+
import io
7+
8+
9+
class Plant_Disease_Model(nn.Module):
10+
11+
def __init__(self):
12+
super().__init__()
13+
self.network = models.resnet34(pretrained=True)
14+
num_ftrs = self.network.fc.in_features
15+
self.network.fc = nn.Linear(num_ftrs, 38)
16+
17+
def forward(self, xb):
18+
out = self.network(xb)
19+
return out
20+
21+
22+
transform = transforms.Compose(
23+
[transforms.Resize(size=128),
24+
transforms.ToTensor()])
25+
26+
num_classes = ['Apple___Apple_scab', 'Apple___Black_rot', 'Apple___Cedar_apple_rust', 'Apple___healthy', 'Blueberry___healthy', 'Cherry_(including_sour)___Powdery_mildew', 'Cherry_(including_sour)___healthy', 'Corn_(maize)___Cercospora_leaf_spot Gray_leaf_spot', 'Corn_(maize)___Common_rust_', 'Corn_(maize)___Northern_Leaf_Blight', 'Corn_(maize)___healthy', 'Grape___Black_rot', 'Grape___Esca_(Black_Measles)', 'Grape___Leaf_blight_(Isariopsis_Leaf_Spot)', 'Grape___healthy', 'Orange___Haunglongbing_(Citrus_greening)', 'Peach___Bacterial_spot', 'Peach___healthy',
27+
'Pepper,_bell___Bacterial_spot', 'Pepper,_bell___healthy', 'Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy', 'Raspberry___healthy', 'Soybean___healthy', 'Squash___Powdery_mildew', 'Strawberry___Leaf_scorch', 'Strawberry___healthy', 'Tomato___Bacterial_spot', 'Tomato___Early_blight', 'Tomato___Late_blight', 'Tomato___Leaf_Mold', 'Tomato___Septoria_leaf_spot', 'Tomato___Spider_mites Two-spotted_spider_mite', 'Tomato___Target_Spot', 'Tomato___Tomato_Yellow_Leaf_Curl_Virus', 'Tomato___Tomato_mosaic_virus', 'Tomato___healthy']
28+
29+
30+
model = Plant_Disease_Model()
31+
model.load_state_dict(torch.load(
32+
'./Models/plantDisease-resnet34.pth', map_location=torch.device('cpu')))
33+
model.eval()
34+
35+
36+
def predict_image(img):
37+
img_pil = Image.open(io.BytesIO(img))
38+
tensor = transform(img_pil)
39+
xb = tensor.unsqueeze(0)
40+
yb = model(xb)
41+
_, preds = torch.max(yb, dim=1)
42+
return num_classes[preds[0].item()]

Flask/requirements.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
numpy
2+
pandas
3+
Flask
4+
Pillow
5+
gunicorn == 20.0.4
6+
https://download.pytorch.org/whl/cpu/torch-1.8.0%2Bcpu-cp36-cp36m-linux_x86_64.whl
7+
https://download.pytorch.org/whl/cpu/torchvision-0.9.0%2Bcpu-cp36-cp36m-linux_x86_64.whl
File renamed without changes.
File renamed without changes.

Flask/Template/css/style.css Flask/static/styles/style.css

+29-4
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ background-color: #212121;
469469
/* banner */
470470

471471
.main-top {
472-
background: linear-gradient(rgba(46, 46, 46, 0.418), rgba(27, 27, 27, 0.349)),
472+
background: linear-gradient(rgba(46, 46, 46, 0.493), rgba(27, 27, 27, 0.466)),
473473
url(../images/b7.jpg) no-repeat bottom;
474474
background-size: cover;
475475
-webkit-background-size: cover;
@@ -532,9 +532,34 @@ button.btn1:hover,
532532
}
533533

534534
/* //banner */
535+
/*--inner-banner -- */
536+
.inner_page-banner {
537+
text-align: center;
538+
background: url(../images/b7.jpg) no-repeat center;
539+
background-size: cover;
540+
-webkit-background-size: cover;
541+
-moz-background-size: cover;
542+
-o-background-size: cover;
543+
-ms-background-size: cover;
544+
min-height: 300px;
545+
}
535546

536-
/* about */
547+
.using-border {
548+
width: 100%;
549+
border: none;
550+
background: #7d5dba;
551+
text-align: center;
552+
}
537553

554+
ul.short_ls li a {
555+
color: #ffffff;
556+
text-decoration: none;
557+
}
558+
559+
/* about */
560+
.about-two-grids{
561+
color: rgb(129, 40, 189);
562+
}
538563
.about-oil-w3layouts {
539564
padding: 3em 1em;
540565
color: #000;
@@ -600,10 +625,10 @@ a.move-top {
600625
font-size: 31px;
601626
}
602627
#logo a {
603-
font-size: 32px;
628+
font-size: 30px;
604629
}
605630
.title {
606-
font-size: 35px;
631+
font-size: 30px;
607632
}
608633
.collection-w3layouts h4,
609634
.ser-sevice-grid h4,

Flask/templates/display.html

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>Plant AI</title>
6+
<!--meta tags -->
7+
<meta charset="UTF-8">
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
<!--//meta tags ends here-->
10+
<!--booststrap-->
11+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
12+
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
13+
<!--//booststrap end-->
14+
15+
<!-- font-awesome icons -->
16+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
17+
integrity="sha512-SfTiTlX6kk+qitfevl/7LibUOeJWlt9rbyDn92a1DqWOw9vWG2MFoays0sgObmWazO5BQPiFucnnEAjpAB+/Sw=="
18+
crossorigin="anonymous" />
19+
<!-- //font-awesome icons -->
20+
21+
<!--stylesheets-->
22+
<link href="../static/styles/style.css" rel='stylesheet' type='text/css' media="all">
23+
<!--//stylesheets-->
24+
25+
</head>
26+
27+
<body>
28+
<!--headder-->
29+
<div class="header-outs inner_page-banner" id="home">
30+
<div class="headder-top">
31+
<!-- nav -->
32+
<nav>
33+
<div id="logo">
34+
<h1><a href="/">Plant-AI</a></h1>
35+
</div>
36+
37+
</nav>
38+
<!-- //nav -->
39+
</div>
40+
</div>
41+
<!--//headder-->
42+
<!-- short -->
43+
<div class="using-border py-3">
44+
<div class="inner_breadcrumb ml-4">
45+
<ul class="short_ls">
46+
<li>
47+
<a href="/">Home</a>
48+
</ul>
49+
</div>
50+
</div>
51+
<!-- //short-->
52+
<!-- about -->
53+
<section class="about py-lg-4 py-md-3 py-sm-3 py-3" id="about">
54+
<div class="container py-lg-5 py-md-4 py-sm-4 py-3">
55+
<div class="row" style="justify-content: center;">
56+
<div class="col-md-10 about-two-grids">
57+
<h3 class="mb-md-4 mb-sm-3 mb-3 text-center">Result</h3>
58+
<div class="about-para-txt text-justify">
59+
{{result}}
60+
61+
</div>
62+
</div>
63+
</div>
64+
</div>
65+
</section>
66+
<!-- //about -->
67+
68+
<!-- footer -->
69+
<footer>
70+
<div class="container pt-5 pb-3">
71+
<div class="footer-w3layouts-head text-center">
72+
<h2><a href="/">Plant-AI</a></h2>
73+
</div>
74+
<div class="bottem-wthree-footer text-center pt-md-4 pt-3">
75+
<p>
76+
All Rights Reserved | Design by Soumyajit
77+
</p>
78+
</div>
79+
<!-- move icon -->
80+
<div class="text-center">
81+
<a href="#home" class="move-top text-center mt-3"><i class="fa fa-arrow-up" aria-hidden="true"></i></a>
82+
</div>
83+
<!--//move icon -->
84+
</div>
85+
</footer>
86+
<!--//footer -->
87+
88+
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
89+
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
90+
crossorigin="anonymous"></script>
91+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
92+
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
93+
crossorigin="anonymous"></script>
94+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
95+
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
96+
crossorigin="anonymous"></script>
97+
</body>
98+
99+
</html>

Flask/Template/index.html Flask/templates/index.html

+39-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<!-- //font-awesome icons -->
2020

2121
<!--stylesheets-->
22-
<link href="css/style.css" rel='stylesheet' type='text/css' media="all">
22+
<link href="../static/styles/style.css" rel='stylesheet' type='text/css' media="all">
2323
<!--//stylesheets-->
2424

2525
</head>
@@ -54,7 +54,8 @@ <h5>Offering Farming Solutions Worldwide
5454
</h5>
5555
</div>
5656
<div class="two-demo-button mt-md-4 mt-3">
57-
<p> Developing models for making disease detection easy and imporving crop production</p>
57+
<p> Developing models for making disease detection easy and providing solutions for improving crop production
58+
</p>
5859
</div>
5960

6061
</div>
@@ -66,15 +67,19 @@ <h5>Offering Farming Solutions Worldwide
6667
<section class="about py-lg-4 py-md-3 py-sm-3 py-3" id="about">
6768
<div class="container py-lg-5 py-md-4 py-sm-4 py-3">
6869
<div class="row">
69-
<div class="col-lg-6 about-imgs-txt pt-10">
70-
<img src="images/4.jpg" alt="news image" class="img-fluid" style="border-radius: 8px;">
70+
<div class="col-lg-6 about-imgs-txt pt-3">
71+
<img src="../static/images/4.jpg" alt="news image" class="img-fluid" style="border-radius: 8px;">
7172
</div>
72-
<div class="col-lg-6 text-justify about-two-grids pt-5">
73-
<h3 class="title mb-md-4 mb-sm-3 mb-3 text-center">About</h3>
73+
<div class="col-lg-6 text-justify about-two-grids pt-3">
74+
<h3 class="title text-center">About</h3>
7475
<div class="about-para-txt">
75-
<p>sed do eiusmod tempor incididunt ut Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet, eiusmod tempor
76-
incididunt ut labore et consectetur adipiscing sed do eiusmod tempor incididunt ut Lorem ipsum dolor sit
77-
amet Lorem ipsum dolor sit amet, eiusmod tempor incididunt ut labore et consectetur adipiscing</p>
76+
<p>Food security for billions of people on earth requires minimizing crop damage by timely detection of
77+
diseases.Developing methods for detection of plant diseases serves the dual purpose of increasing crop
78+
yield and reducing pesticide use without knowing about the proper disease. Along with development of
79+
better crop varieties, disease detection is thus paramount goal for achieving food security. The
80+
traditional method of disease detection has been to use manual examination by either farmers or experts,
81+
which can be time consuming and costly, proving infeasible for millions of small and medium sized farms
82+
around the world.</p>
7883
</div>
7984
</div>
8085
</div>
@@ -104,8 +109,8 @@ <h4 class="pb-3">Easy Detection</h4>
104109
<span class="fa fa-pagelines" aria-hidden="true"></span>
105110
</div>
106111
<div class="ser-sevice-grid">
107-
<h4 class="pb-3">High Accuracy</h4>
108-
<p>The Accuracy of correct detection is about 98%.</p>
112+
<h4 class="pb-3">Cause and Solution</h4>
113+
<p>Provides the cause and solution of the identified diseases.</p>
109114
</div>
110115
</div>
111116
</div>
@@ -128,9 +133,19 @@ <h4 class="pb-3">Large Plant Support</h4>
128133
<section class="blog_w3ls py-3 pb-5 pt-10" id="test">
129134
<div class="container pb-xl-5 pb-lg-3">
130135
<h3 class="title text-center mb-lg-5 mb-md-4 mb-sm-4 mb-3"> Test Your Plants</h3>
131-
<div class="row">
132-
136+
<div class="row" style="justify-content: center;">
137+
<form action="{{ url_for('predict') }}" method="POST" enctype=multipart/form-data>
138+
<div class="form-group text-center">
139+
<label for="exampleFormControlFile1"><b>Input a file</b></label>
140+
<input type="file" name="file" class="form-control-file" id="inputImage" onchange=previewImage(event)
141+
required>
142+
<br />
143+
<button class="btn btn-primary" type="submit"> Predict </button>
144+
</div>
145+
</form>
133146
</div>
147+
<img id="output-image" class="rounded mx-auto d-block" />
148+
<br />
134149
</div>
135150

136151
</section>
@@ -164,6 +179,17 @@ <h2><a href="index.html">Plant-AI</a></h2>
164179
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
165180
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
166181
crossorigin="anonymous"></script>
182+
183+
<script>
184+
function previewImage(event) {
185+
var reader = new FileReader();
186+
reader.onload = function () {
187+
var output = document.getElementById('output-image')
188+
output.src = reader.result;
189+
}
190+
reader.readAsDataURL(event.target.files[0]);
191+
}
192+
</script>
167193
</body>
168194

169195
</html>

0 commit comments

Comments
 (0)