├── frontend ├── .env.example ├── public │ ├── robots.txt │ ├── cblogo.PNG │ └── index.html ├── src │ ├── bg.png │ ├── cblogo.PNG │ ├── leaf.jpg │ ├── App.js │ ├── App.test.js │ ├── reportWebVitals.js │ ├── index.js │ ├── index.css │ └── home.js ├── .gitignore ├── package.json └── README.md ├── gcp ├── requirements.txt └── main.py ├── potato_Detection.h5 ├── saved_models ├── 1 │ ├── saved_model.pb │ └── variables │ │ ├── variables.index │ │ └── variables.data-00000-of-00001 ├── 2 │ ├── saved_model.pb │ └── variables │ │ ├── variables.index │ │ └── variables.data-00000-of-00001 └── 3 │ ├── saved_model.pb │ └── variables │ ├── variables.index │ └── variables.data-00000-of-00001 ├── api ├── requirements.txt ├── main-tf-serving.py └── main.py ├── models.config ├── LICENSE ├── CONTRIBUTING.md ├── README.md └── CODE_OF_CONDUCT.md /frontend/.env.example: -------------------------------------------------------------------------------- 1 | REACT_APP_API_URL=http://localhost:8000/predict 2 | -------------------------------------------------------------------------------- /gcp/requirements.txt: -------------------------------------------------------------------------------- 1 | tensorflow==2.5 2 | google-cloud-storage==1.16.1 3 | Pillow==6.0.0 -------------------------------------------------------------------------------- /frontend/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /frontend/src/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/frontend/src/bg.png -------------------------------------------------------------------------------- /potato_Detection.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/potato_Detection.h5 -------------------------------------------------------------------------------- /frontend/src/cblogo.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/frontend/src/cblogo.PNG -------------------------------------------------------------------------------- /frontend/src/leaf.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/frontend/src/leaf.jpg -------------------------------------------------------------------------------- /frontend/public/cblogo.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/frontend/public/cblogo.PNG -------------------------------------------------------------------------------- /saved_models/1/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/saved_models/1/saved_model.pb -------------------------------------------------------------------------------- /saved_models/2/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/saved_models/2/saved_model.pb -------------------------------------------------------------------------------- /saved_models/3/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/saved_models/3/saved_model.pb -------------------------------------------------------------------------------- /api/requirements.txt: -------------------------------------------------------------------------------- 1 | tensorflow 2 | fastapi 3 | uvicorn 4 | python-multipart 5 | pillow 6 | tensorflow-serving-api 7 | matplotlib 8 | numpy -------------------------------------------------------------------------------- /saved_models/1/variables/variables.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/saved_models/1/variables/variables.index -------------------------------------------------------------------------------- /saved_models/2/variables/variables.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/saved_models/2/variables/variables.index -------------------------------------------------------------------------------- /saved_models/3/variables/variables.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/saved_models/3/variables/variables.index -------------------------------------------------------------------------------- /saved_models/1/variables/variables.data-00000-of-00001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/saved_models/1/variables/variables.data-00000-of-00001 -------------------------------------------------------------------------------- /saved_models/2/variables/variables.data-00000-of-00001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/saved_models/2/variables/variables.data-00000-of-00001 -------------------------------------------------------------------------------- /saved_models/3/variables/variables.data-00000-of-00001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shashank1623/Plant-disease-Detection/HEAD/saved_models/3/variables/variables.data-00000-of-00001 -------------------------------------------------------------------------------- /frontend/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { ImageUpload } from "./home"; 3 | 4 | function App() { 5 | return ; 6 | } 7 | 8 | export default App; 9 | -------------------------------------------------------------------------------- /models.config: -------------------------------------------------------------------------------- 1 | model_config_list { 2 | config { 3 | name: 'Disease_model' 4 | base_path: '/Disease-Detection/saved_models/' 5 | model_platform: 'tensorflow' 6 | model_version_policy: {all: {}} 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /frontend/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | .env 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /frontend/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /frontend/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /frontend/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | 15 | .MuiDropzoneArea-root { 16 | background-color: transparent !important; 17 | } 18 | .MuiDropzoneArea-text, .MuiDropzoneArea-icon { 19 | color: white !important; 20 | } -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "photo", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@material-ui/core": "^4.11.4", 7 | "@material-ui/icons": "^4.11.2", 8 | "axios": "^0.21.1", 9 | "material-ui-dropzone": "^3.5.0", 10 | "react": "^17.0.2", 11 | "react-dom": "^17.0.2", 12 | "react-scripts": "^5.0.1", 13 | "web-vitals": "^1.1.2" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": [ 23 | "react-app", 24 | "react-app/jest" 25 | ] 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.2%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Shashank Bhardwaj 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /api/main-tf-serving.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI, File ,UploadFile 2 | import uvicorn 3 | import numpy as np 4 | from io import BytesIO 5 | from PIL import Image 6 | import tensorflow as tf 7 | import requests 8 | 9 | app = FastAPI() 10 | 11 | endpoint = 'http://localhost:8501/v1/models/Disease_model:predict' 12 | CLASS_NAMES = ["Early Blight", "Late Blight", "Healthy"] 13 | @app.get("/ping") 14 | async def ping(): 15 | return "Hello I'm alive" 16 | 17 | def read_file_as_image(data) -> np.ndarray: 18 | image = np.array(Image.open(BytesIO(data))) 19 | return image 20 | 21 | 22 | @app.post("/predict") 23 | async def predict( 24 | file: UploadFile = File(...) 25 | ): 26 | image = read_file_as_image(await file.read()) 27 | img_batch = np.expand_dims(image,0) 28 | json_data = { 29 | "instances":img_batch.tolist() 30 | } 31 | response = requests.post(endpoint,json=json_data) 32 | prediction = np.array(response.json()["predictions"][0]) 33 | predicted_class = CLASS_NAMES[np.argmax(prediction)] 34 | confidence = np.max(prediction) 35 | 36 | return{ 37 | "class" : predicted_class, 38 | "confidence" : float(confidence) 39 | } 40 | 41 | 42 | 43 | if __name__ =="__main__": 44 | uvicorn.run(app,host='localhost',port=8000) -------------------------------------------------------------------------------- /gcp/main.py: -------------------------------------------------------------------------------- 1 | from google.cloud import storage 2 | import tensorflow as tf 3 | from PIL import Image 4 | import numpy as np 5 | 6 | model = None 7 | interpreter = None 8 | input_index = None 9 | output_index = None 10 | 11 | class_names = ["Early Blight", "Late Blight", "Healthy"] 12 | 13 | BUCKET_NAME = 'theghost-potato-diseasae-1' 14 | 15 | def download_blob(bucket_name, source_blob_name, destination_file_name): 16 | """Downloads a blob from the bucket.""" 17 | storage_client = storage.Client() 18 | bucket = storage_client.get_bucket(bucket_name) 19 | blob = bucket.blob(source_blob_name) 20 | 21 | blob.download_to_filename(destination_file_name) 22 | 23 | print(f"Blob {source_blob_name} downloaded to {destination_file_name}.") 24 | 25 | 26 | def predict(request): 27 | global model 28 | if model is None: 29 | download_blob( 30 | BUCKET_NAME, 31 | "models/potato_Detection.h5", 32 | "/tmp/potato_Detection.h5", 33 | ) 34 | model = tf.keras.models.load_model("/tmp/potato_Detection.h5") 35 | 36 | image = request.files["file"] 37 | 38 | image = np.array( 39 | Image.open(image).convert("RGB").resize((256, 256)) # image resizing 40 | ) 41 | 42 | image = image/255 # normalize the image in 0 to 1 range 43 | 44 | img_array = tf.expand_dims(image, 0) 45 | predictions = model.predict(img_array) 46 | 47 | print("Predictions:",predictions) 48 | 49 | predicted_class = class_names[np.argmax(predictions[0])] 50 | confidence = round((np.max(predictions[0])), 2) 51 | 52 | return {"class": predicted_class, "confidence": confidence} 53 | -------------------------------------------------------------------------------- /api/main.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI, File ,UploadFile 2 | import uvicorn 3 | import numpy as np 4 | from io import BytesIO 5 | from PIL import Image 6 | import tensorflow as tf 7 | from starlette.middleware.cors import CORSMiddleware 8 | 9 | app = FastAPI() 10 | 11 | origins = [ 12 | "http://localhost", 13 | "http://localhost:3000", 14 | ] 15 | 16 | app.add_middleware( 17 | CORSMiddleware, 18 | allow_origins=origins, 19 | allow_credentials=True, 20 | allow_methods=["*"], 21 | allow_headers=["*"], 22 | ) 23 | 24 | MODEL = tf.keras.models.load_model("../saved_models/3") 25 | CLASS_NAMES = ['Pepper__bell___Bacterial_spot', 26 | 'Pepper__bell___healthy', 27 | 'Potato___Early_blight', 28 | 'Potato___Late_blight', 29 | 'Potato___healthy', 30 | 'Tomato_Bacterial_spot', 31 | 'Tomato_Early_blight', 32 | 'Tomato_Late_blight', 33 | 'Tomato_Leaf_Mold', 34 | 'Tomato_Septoria_leaf_spot', 35 | 'Tomato_Spider_mites_Two_spotted_spider_mite', 36 | 'Tomato__Target_Spot', 37 | 'Tomato__YellowLeaf__Curl_Virus', 38 | 'Tomato__mosaic_virus', 39 | 'Tomato_healthy'] 40 | @app.get("/ping") 41 | async def ping(): 42 | return "Hello I'm alive" 43 | 44 | def read_file_as_image(data) -> np.ndarray: 45 | image = np.array(Image.open(BytesIO(data))) 46 | return image 47 | 48 | 49 | @app.post("/predict") 50 | async def predict( 51 | file: UploadFile = File(...) 52 | ): 53 | image = read_file_as_image(await file.read()) 54 | img_batch = np.expand_dims(image,0) 55 | prediction = MODEL.predict(img_batch) 56 | print(np.argmax(prediction[0])) 57 | predicted_class = CLASS_NAMES[np.argmax(prediction[0])] 58 | confidence = np.max(prediction[0]) 59 | return{ 60 | 'class':predicted_class, 61 | 'confidence':float(confidence) 62 | } 63 | 64 | if __name__ =="__main__": 65 | uvicorn.run(app,host='localhost',port=8000) -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | 286 | 287 | 288 | 289 | Label: 290 | 291 | 295 | Confidence: 296 | 297 | 298 | 299 | 300 | 301 | 306 | {data.class} 307 | 308 | 312 | {confidence}% 313 | 314 | 315 | 316 |
317 |
318 |
319 | )} 320 | {isLoading && ( 321 | 322 | 326 | 327 | Processing 328 | 329 | 330 | )} 331 |
332 |
333 | {data && ( 334 | 335 | } 343 | > 344 | Clear 345 | 346 | 347 | )} 348 |
349 |
350 | 351 | ); 352 | }; 353 | --------------------------------------------------------------------------------