4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | Plant Disease Detection
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing guidelines
2 |
3 | ## Before contributing
4 |
5 | Welcome to [Algorithms/Python](https://github.com/shashank1623/Plant-disease-Detection)! Before sending your pull requests, make sure that you __read the whole guidelines__. If you have any doubt on the contributing guide, please feel free to [state it clearly in an issue](https://github.com/shashank1623/Plant-disease-Detection/issues/new) or ask me by sending me an email at `shashankbhardwaj2030@gmail.com`.
6 |
7 |
8 |
9 | ## Contributing
10 |
11 | ### Contributor
12 |
13 | We are very happy that you are considering implementing algorithms and data structures for others! This repository is referenced and used by learners from all over the globe. Being one of our contributors, you agree and confirm that:
14 |
15 | - You did your work - no plagiarism allowed
16 | - Any plagiarized work will not be merged.
17 | - Your work will be distributed under [MIT License](LICENSE.md) once your pull request is merged
18 | - Your submitted work fulfils or mostly fulfils our styles and standards
19 |
20 | __New implementation__ is welcome! For example, new solutions for a problem, different representations for a graph data structure or algorithm designs with different complexity but __identical implementation__ of an existing implementation is not allowed. Please check whether the solution is already implemented or not before submitting your pull request.
21 |
22 | __Improving comments__ and __writing proper tests__ are also highly welcome.
23 |
24 | ### Contribution
25 |
26 | We appreciate any contribution, from fixing a grammar mistake in a comment to implementing complex algorithms. Please read this section if you are contributing your work.
27 |
28 | Please help us keep our issue list small by adding fixes: #{$ISSUE_NO} to the commit message of pull requests that resolve open issues. GitHub will use this tag to auto-close the issue when the PR is merged.
29 |
30 |
31 |
32 | Writer [@shashank1623](https://github.com/shashank1623), Feb 2023.
33 |
--------------------------------------------------------------------------------
/frontend/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `npm start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13 |
14 | The page will reload if you make edits.\
15 | You will also see any lint errors in the console.
16 |
17 | ### `npm test`
18 |
19 | Launches the test runner in the interactive watch mode.\
20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21 |
22 | ### `npm run build`
23 |
24 | Builds the app for production to the `build` folder.\
25 | It correctly bundles React in production mode and optimizes the build for the best performance.
26 |
27 | The build is minified and the filenames include the hashes.\
28 | Your app is ready to be deployed!
29 |
30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31 |
32 | ### `npm run eject`
33 |
34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35 |
36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37 |
38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39 |
40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41 |
42 | ## Learn More
43 |
44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45 |
46 | To learn React, check out the [React documentation](https://reactjs.org/).
47 |
48 | ### Code Splitting
49 |
50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51 |
52 | ### Analyzing the Bundle Size
53 |
54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55 |
56 | ### Making a Progressive Web App
57 |
58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59 |
60 | ### Advanced Configuration
61 |
62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63 |
64 | ### Deployment
65 |
66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67 |
68 | ### `npm run build` fails to minify
69 |
70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
71 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Plant-disease-Detection
2 |
3 | ## Problem Statement
4 |
5 | Farmers who grown plant/vegetables are facing lot of economical Loss every year because of various Disease that can happen to a plant/vegetables . In our problem i have found 38 different types of disease of 15 plants . If a farmer can detect these early and apply appropriate treatment it can save lot of waste and prevent the economical loss .
6 |
7 | ## About:
8 | In this Project , i have build an end to end machine learning Project in Agriculture Domain to solve the problem of Plants disease. In this Project i have build a web application using `React.js` which will deployed to the cloud and anywhere form the world can acess this applicaiton . All they just need to do give the image of the leaves of plant and the application will tell you disease of the plant with accuracy . Behind the scenes it will be using deep learning model and CNN .
9 |
10 |
11 | Steps that i have Followed In order to implement this project:
12 | Step 1: Data Collection (Used Open Database)
13 | Step 2: Model Building
14 | Step 3 : MLOPs
15 | Step 4: Deployemnt of Model (GCP/AWS)
16 | Step 5: Frontend Development
17 |
18 | Steps to install and Start the apps.
19 | ## Setup for Python:
20 | 1. Install Python ([Setup instructions](https://wiki.python.org/moin/BeginnersGuide))
21 | 2. Make a Virtual Env.
22 | 3. Install Python packages
23 |
24 | ```
25 | pip3 install -r api/requirements.txt
26 | ```
27 | 3. Install Tensorflow Serving ([Setup instructions](https://www.tensorflow.org/tfx/serving/setup))
28 |
29 | ## Setup for ReactJS
30 |
31 | 1. Install Nodejs ([Setup instructions](https://nodejs.org/en/download/package-manager/))
32 | 2. Install NPM ([Setup instructions](https://www.npmjs.com/get-npm))
33 | 3. Install dependencies
34 |
35 | ```bash
36 | cd frontend
37 | npm install --from-lock-json
38 | npm audit fix
39 | ```
40 | 4. Copy `.env.example` as `.env`.
41 |
42 | 5. Change API url in `.env`.
43 |
44 | ## Training the Model
45 | Note :- If have gpu based machine then run it otherwise it will take more than a day for model building . or you can reduce the size of data from every folder then train the model.
46 | 1. Download the data from [kaggle](https://www.kaggle.com/arjuntejaswi/plant-village).
47 | 2. Keep all the data in a seprate folder in a project directory.
48 | 3. Run Jupyter Notebook in Browser.
49 |
50 | ```bash
51 | jupyter notebook
52 | ```
53 |
54 | 4. Open `training/potato-disease-training.ipynb` in Jupyter Notebook.
55 | 5. In cell #2, update the path to dataset.
56 | 6. Run all the Cells one by one.
57 | 7. Copy the model generated and save it with the version number in the `models` folder.
58 |
59 | ### Using FastAPI
60 |
61 | 1. Get inside `api` folder
62 |
63 | ```bash
64 | cd api
65 | ```
66 |
67 | 2. Run the FastAPI Server using uvicorn
68 |
69 | ```bash
70 | uvicorn main:app --reload --host 0.0.0.0
71 | ```
72 |
73 | 3. Your API is now running at `0.0.0.0:8000`
74 |
75 | ### Using FastAPI & TF Serve
76 |
77 | 1. Get inside `api` folder
78 |
79 | ```bash
80 | cd api
81 | ```
82 |
83 | 2. Copy the `models.config.example` as `models.config` and update the paths in file.
84 | 3. Run the TF Serve (Update config file path below)
85 |
86 | ```bash
87 | docker run -t --rm -p 8501:8501 -v C:/Code/potato-disease-classification:/potato-disease-classification tensorflow/serving --rest_api_port=8501 --model_config_file=/potato-disease-classification/models.config
88 | ```
89 |
90 | 4. Run the FastAPI Server using uvicorn
91 | For this you can directly run it from your main.py or main-tf-serving.py using pycharm run option (as shown in the video tutorial)
92 | OR you can run it from command prompt as shown below,
93 |
94 | ```bash
95 | uvicorn main-tf-serving:app --reload --host 0.0.0.0
96 | ```
97 |
98 | 5. Your API is now running at `0.0.0.0:8000`
99 |
100 | ## Running the Frontend
101 |
102 | 1. Get inside `api` folder
103 |
104 | ```bash
105 | cd frontend
106 | ```
107 |
108 | 2. Copy the `.env.example` as `.env` and update `REACT_APP_API_URL` to API URL if needed.
109 | 3. Run the frontend
110 |
111 | ```bash
112 | npm run start
113 | ```
114 |
115 | Datasets credits:- https://www.kaggle.com/arjuntejaswi/plant-village
116 | Contact Us:- shashankbhardwaj2030@gmai.com (Hope this repo found it usefull to you then please give a star to this repo).
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, religion, or sexual identity
10 | and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | * Demonstrating empathy and kindness toward other people
21 | * Being respectful of differing opinions, viewpoints, and experiences
22 | * Giving and gracefully accepting constructive feedback
23 | * Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | * Focusing on what is best not just for us as individuals, but for the
26 | overall community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | * The use of sexualized language or imagery, and sexual attention or
31 | advances of any kind
32 | * Trolling, insulting or derogatory comments, and personal or political attacks
33 | * Public or private harassment
34 | * Publishing others' private information, such as a physical or email
35 | address, without their explicit permission
36 | * Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official e-mail address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | shashankbhardwaj2030@gmail.com.
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series
86 | of actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or
93 | permanent ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within
113 | the community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.0, available at
119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120 |
121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct
122 | enforcement ladder](https://github.com/mozilla/diversity).
123 |
124 | [homepage]: https://www.contributor-covenant.org
125 |
126 | For answers to common questions about this code of conduct, see the FAQ at
127 | https://www.contributor-covenant.org/faq. Translations are available at
128 | https://www.contributor-covenant.org/translations.
129 |
--------------------------------------------------------------------------------
/frontend/src/home.js:
--------------------------------------------------------------------------------
1 | import { useState, useEffect } from "react";
2 | import { makeStyles, withStyles } from "@material-ui/core/styles";
3 | import AppBar from "@material-ui/core/AppBar";
4 | import Toolbar from "@material-ui/core/Toolbar";
5 | import Typography from "@material-ui/core/Typography";
6 | import Avatar from "@material-ui/core/Avatar";
7 | import Container from "@material-ui/core/Container";
8 | import React from "react";
9 | import Card from "@material-ui/core/Card";
10 | import CardContent from "@material-ui/core/CardContent";
11 | import {
12 | Paper,
13 | CardActionArea,
14 | CardMedia,
15 | Grid,
16 | TableContainer,
17 | Table,
18 | TableBody,
19 | TableHead,
20 | TableRow,
21 | TableCell,
22 | Button,
23 | CircularProgress,
24 | } from "@material-ui/core";
25 | import cblogo from "./cblogo.PNG";
26 | import image from "./bg.png";
27 | import { DropzoneArea } from "material-ui-dropzone";
28 | import { common } from "@material-ui/core/colors";
29 | import Clear from "@material-ui/icons/Clear";
30 |
31 | const ColorButton = withStyles((theme) => ({
32 | root: {
33 | color: theme.palette.getContrastText(common.white),
34 | backgroundColor: common.white,
35 | "&:hover": {
36 | backgroundColor: "#ffffff7a",
37 | },
38 | },
39 | }))(Button);
40 | const axios = require("axios").default;
41 |
42 | const useStyles = makeStyles((theme) => ({
43 | grow: {
44 | flexGrow: 1,
45 | },
46 | clearButton: {
47 | width: "-webkit-fill-available",
48 | borderRadius: "15px",
49 | padding: "15px 22px",
50 | color: "#000000a6",
51 | fontSize: "20px",
52 | fontWeight: 900,
53 | },
54 | root: {
55 | maxWidth: 345,
56 | flexGrow: 1,
57 | },
58 | media: {
59 | height: 400,
60 | },
61 | paper: {
62 | padding: theme.spacing(2),
63 | margin: "auto",
64 | maxWidth: 500,
65 | },
66 | gridContainer: {
67 | justifyContent: "center",
68 | padding: "4em 1em 0 1em",
69 | },
70 | mainContainer: {
71 | backgroundImage: `url(${image})`,
72 | backgroundRepeat: "no-repeat",
73 | backgroundPosition: "center",
74 | backgroundSize: "cover",
75 | height: "93vh",
76 | marginTop: "8px",
77 | },
78 | imageCard: {
79 | margin: "auto",
80 | maxWidth: 400,
81 | height: 500,
82 | backgroundColor: "transparent",
83 | boxShadow: "0px 9px 70px 0px rgb(0 0 0 / 30%) !important",
84 | borderRadius: "15px",
85 | },
86 | imageCardEmpty: {
87 | height: "auto",
88 | },
89 | noImage: {
90 | margin: "auto",
91 | width: 400,
92 | height: "400 !important",
93 | },
94 | input: {
95 | display: "none",
96 | },
97 | uploadIcon: {
98 | background: "white",
99 | },
100 | tableContainer: {
101 | backgroundColor: "transparent !important",
102 | boxShadow: "none !important",
103 | },
104 | table: {
105 | backgroundColor: "transparent !important",
106 | },
107 | tableHead: {
108 | backgroundColor: "transparent !important",
109 | },
110 | tableRow: {
111 | backgroundColor: "transparent !important",
112 | },
113 | tableCell: {
114 | fontSize: "22px",
115 | backgroundColor: "transparent !important",
116 | borderColor: "transparent !important",
117 | color: "#000000a6 !important",
118 | fontWeight: "bolder",
119 | padding: "1px 24px 1px 16px",
120 | },
121 | tableCell1: {
122 | fontSize: "14px",
123 | backgroundColor: "transparent !important",
124 | borderColor: "transparent !important",
125 | color: "#000000a6 !important",
126 | fontWeight: "bolder",
127 | padding: "1px 24px 1px 16px",
128 | },
129 | tableBody: {
130 | backgroundColor: "transparent !important",
131 | },
132 | text: {
133 | color: "white !important",
134 | textAlign: "center",
135 | },
136 | buttonGrid: {
137 | maxWidth: "416px",
138 | width: "100%",
139 | },
140 | detail: {
141 | backgroundColor: "white",
142 | display: "flex",
143 | justifyContent: "center",
144 | flexDirection: "column",
145 | alignItems: "center",
146 | },
147 | appbar: {
148 | background: "#be6a77",
149 | boxShadow: "none",
150 | color: "white",
151 | },
152 | loader: {
153 | color: "#be6a77 !important",
154 | },
155 | }));
156 | export const ImageUpload = () => {
157 | const classes = useStyles();
158 | const [selectedFile, setSelectedFile] = useState();
159 | const [preview, setPreview] = useState();
160 | const [data, setData] = useState();
161 | const [image, setImage] = useState(false);
162 | const [isLoading, setIsloading] = useState(false);
163 | let confidence = 0;
164 |
165 | const sendFile = async () => {
166 | if (image) {
167 | let formData = new FormData();
168 | formData.append("file", selectedFile);
169 | let res = await axios({
170 | method: "post",
171 | url: process.env.REACT_APP_API_URL,
172 | data: formData,
173 | });
174 | if (res.status === 200) {
175 | setData(res.data);
176 | }
177 | setIsloading(false);
178 | }
179 | };
180 |
181 | const clearData = () => {
182 | setData(null);
183 | setImage(false);
184 | setSelectedFile(null);
185 | setPreview(null);
186 | };
187 |
188 | useEffect(() => {
189 | if (!selectedFile) {
190 | setPreview(undefined);
191 | return;
192 | }
193 | const objectUrl = URL.createObjectURL(selectedFile);
194 | setPreview(objectUrl);
195 | }, [selectedFile]);
196 |
197 | useEffect(() => {
198 | if (!preview) {
199 | return;
200 | }
201 | setIsloading(true);
202 | sendFile();
203 | }, [preview]);
204 |
205 | const onSelectFile = (files) => {
206 | if (!files || files.length === 0) {
207 | setSelectedFile(undefined);
208 | setImage(false);
209 | setData(undefined);
210 | return;
211 | }
212 | setSelectedFile(files[0]);
213 | setData(undefined);
214 | setImage(true);
215 | };
216 |
217 | if (data) {
218 | confidence = (parseFloat(data.confidence) * 100).toFixed(2);
219 | }
220 |
221 | return (
222 |
223 |
224 |
225 |
226 | Plant Disease Detection
227 |
228 |
229 |
230 | Made with ❤️ theGhost
231 |
232 | {/* */}
233 |
234 |
235 |
240 |
248 |
249 |
254 | {image && (
255 |
256 |
262 |
263 | )}
264 | {!image && (
265 |
266 |
273 |
274 | )}
275 | {data && (
276 |
277 |
281 |