Full Source Code – Plant Disease
Detection Project
[Link]
from flask import Flask, render_template, redirect, request
import os
import torch
import [Link] as TF
from PIL import Image
import pandas as pd
import numpy as np
import CNN
disease_info = pd.read_csv('disease_info.csv', encoding='latin-1')
supplement_info = pd.read_csv('supplement_info.csv', encoding='latin-1')
model = [Link](38)
model.load_state_dict([Link]('Plant_Disease_Detection_Model.pth',
map_location=[Link]('cpu')))
[Link]()
def prediction(path_image):
image = [Link](path_image)
image = [Link]("RGB")
image = [Link]((224,224))
input_data = TF.to_tensor(image)
input_data = input_data.view(-1,3,224,224)
output = model(input_data)
output = [Link]().numpy()
index = [Link](output)
return index
app = Flask(__name__)
@[Link]("/")
def home_page():
return render_template('[Link]')
@[Link]('/index')
def ai_engine_page():
return render_template('[Link]')
@[Link]('/submit', methods=['GET', 'POST'])
def submit():
if [Link] == 'POST':
image = [Link]['image']
filename = [Link]
file_path = [Link]('static/upload', filename)
[Link]('static/upload', exist_ok=True)
[Link](file_path)
pred = prediction(file_path)
title = disease_info['disease_name'][pred]
description = disease_info['description'][pred]
prevent = disease_info['Possible Steps'][pred]
image_url = disease_info['image_url'][pred]
supplement_name = supplement_info['supplement name'][pred]
supplement_image_url = supplement_info['supplement image'][pred]
supplement_buy_link = supplement_info['buy link'][pred]
return render_template('[Link]', title=title, desc=description, prevent=prevent,
image_url=image_url, pred=pred, sname=supplement_name,
simage=supplement_image_url, buy_link=supplement_buy_link)
if __name__ == "__main__":
[Link](debug=True)
[Link]
import [Link] as nn
import torch
class CNN([Link]):
def __init__(self, k):
super(CNN, self).__init__()
self.conv_layers = [Link](
nn.Conv2d(3,32,3,padding=1), [Link](), nn.BatchNorm2d(32),
nn.Conv2d(32,32,3,padding=1), [Link](), nn.BatchNorm2d(32), nn.MaxPool2d(2),
nn.Conv2d(32,64,3,padding=1), [Link](), nn.BatchNorm2d(64),
nn.Conv2d(64,64,3,padding=1), [Link](), nn.BatchNorm2d(64), nn.MaxPool2d(2),
nn.Conv2d(64,128,3,padding=1), [Link](), nn.BatchNorm2d(128),
nn.Conv2d(128,128,3,padding=1), [Link](), nn.BatchNorm2d(128),
nn.MaxPool2d(2),
nn.Conv2d(128,256,3,padding=1), [Link](), nn.BatchNorm2d(256),
nn.Conv2d(256,256,3,padding=1), [Link](), nn.BatchNorm2d(256),
nn.MaxPool2d(2)
)
self.dense_layers = [Link](
[Link](0.4),
[Link](50176,1024),
[Link](),
[Link](0.4),
[Link](1024,k)
)
def forward(self,x):
x = self.conv_layers(x)
x = [Link](-1,50176)
x = self.dense_layers(x)
return x
[Link] (sample)
<form action="/submit" method="POST" enctype="multipart/form-data">
<input type="file" name="image">
<button type="submit">Submit</button>
</form>