Note - Double Click to Copy Code Contact Us!

Ayurveda---Medicinal-Plant-Classification-Using-Ensemble-Learning-Techniques

Tech Doubility
Ayurveda---Medicinal-Plant-Classification-Using-Ensemble-Learning-Techniques
 

Python Code
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Fri Mar 17 23:34:05 2023
  4.  
  5. @author: UBED
  6. """
  7. '''
  8.  
  9.  
  10. from tensorflow.keras.preprocessing import image
  11. from tensorflow.keras.utils import load_img
  12. from keras.models import load_model
  13. import os
  14. from flask import Flask, flash, request, redirect, url_for,jsonify
  15.  
  16.  
  17.  
  18. from werkzeug.utils import secure_filename
  19. import numpy as np
  20. from PIL import Image
  21. from flask import Flask, render_template, request
  22.  
  23. result = {
  24. 0: 'Amaranthus Green', 1: 'Amaranthus Red', 2: 'Balloon vine', 3: 'Betel Leaves', 4: 'Black Night Shade', 5: 'Celery', 6: 'Chinese Spinach', 7: 'Coriander Leaves', 8: 'Curry Leaf',
  25. 9: 'Dwarf Copperleaf (Green)', 10: 'Dwarf copperleaf (Red)', 11: 'False Amarnath', 12: 'Fenugreek Leaves', 13: 'Giant Pigweed', 14: 'Gongura', 15: 'Indian pennywort', 16: 'Lagos Spinach',
  26. 17: 'Lambs Quarters', 18: 'Lettuce Tree', 19: 'Malabar Spinach (Green)', 20: 'Mint Leaves', 21: 'Mustard', 22: 'Palak', 23: 'Siru Keerai', 24: 'Water Spinach'
  27. }
  28.  
  29. #Predicting Image
  30. MODEL_PATH = 'CNN_model.h5'
  31. model_dl = load_model(MODEL_PATH)
  32.  
  33.  
  34. app = Flask(__name__)
  35.  
  36. @app.route("/")
  37. def hello_world():
  38.  
  39. return render_template("index.html")
  40. # return "<p>Hello, World!</p>"
  41.  
  42.  
  43. @app.route('/upload', methods=['POST'])
  44. def upload():
  45. if 'file' not in request.files:
  46. return 'No file uploaded.', 400
  47.  
  48. file = request.files['file']
  49. if file.filename == '':
  50. return 'No file selected.', 400
  51.  
  52. # Save the file to the "image" folder
  53. file.save(os.path.join('image', file.filename))
  54.  
  55. temp_path = os.path.join('image',file.filename)
  56.  
  57. # Preprocess the image for the model
  58. img = image.load_img(temp_path, target_size=(224, 224))
  59. img_arr = np.expand_dims(img, axis=0)
  60. img_arr = image.img_to_array(img)
  61. img_arr = np.vstack([img_arr])
  62.  
  63. # Make a prediction with the model
  64. Result = model_dl.predict(img_arr)
  65. prediction_index = np.argmax(Result)
  66. # print(Result,prediction_index)
  67. prediction = result[prediction_index]
  68.  
  69. # Remove the temporary file
  70. # os.remove(temp_path)
  71.  
  72. # Return the prediction as a JSON response
  73. response = {'prediction': str(prediction)}
  74. return jsonify(response)
  75.  
  76.  
  77. if __name__ == '__main__':
  78. app.run()
  79.  
  80. '''
  81.  
  82.  
  83. from tensorflow.keras.preprocessing import image
  84. from tensorflow.keras.utils import load_img
  85. from keras.models import load_model
  86. import os
  87. from flask import Flask, flash, request, redirect, url_for,jsonify
  88.  
  89.  
  90.  
  91. from werkzeug.utils import secure_filename
  92. import numpy as np
  93. from PIL import Image
  94. from flask import Flask, render_template, request
  95.  
  96. import tempfile
  97. app=Flask(__name__)
  98.  
  99. result = {0: 'Amaranthus Green', 1: 'Amaranthus Red', 2: 'Balloon vine', 3: 'Betel Leaves', 4: 'Black Night Shade', 5: 'Celery', 6: 'Chinese Spinach', 7: 'Coriander Leaves', 8: 'Curry Leaf', 9: 'Dwarf Copperleaf (Green)', 10: 'Dwarf copperleaf (Red)', 11: 'False Amarnath', 12: 'Fenugreek Leaves', 13: 'Giant Pigweed', 14: 'Gongura', 15: 'Indian pennywort', 16: 'Lagos Spinach', 17: 'Lambs Quarters', 18: 'Lettuce Tree', 19: 'Malabar Spinach (Green)', 20: 'Mint Leaves', 21: 'Mustard', 22: 'Palak', 23: 'Siru Keerai', 24: 'Water Spinach'}
  100. MODEL_PATH = 'CNN_model.h5'
  101.  
  102. model_dl = load_model(MODEL_PATH)
  103. @app.route('/predict', methods=['GET', 'POST'])
  104. def predict():
  105. if request.method == 'POST':
  106. img_file = request.files['image']
  107.  
  108. # Save the temporary file
  109. with tempfile.NamedTemporaryFile(delete=False) as temp:
  110. img_file.save(temp.name)
  111. temp_path = temp.name
  112.  
  113. # Preprocess the image for the model
  114. img = image.load_img(temp_path, target_size=(224, 224))
  115. img_arr = image.img_to_array(img)
  116. img_arr = np.expand_dims(img_arr, axis=0)
  117. img_arr = np.vstack([img_arr])
  118.  
  119. # Make a prediction with the model
  120. Result = model_dl.predict(img_arr)
  121. prediction_index = np.argmax(Result)
  122. prediction = result[prediction_index]
  123.  
  124. # Remove the temporary file
  125. os.remove(temp_path)
  126.  
  127. # Return the prediction as a JSON response
  128. response = {'prediction': str(prediction)}
  129. return jsonify(response)
  130. else:
  131. return "No image passed UBED"
  132.  
  133.  
  134. if __name__ == '__main__':
  135. app.run()
HTML CODE
  1.  
  2. <head>
  3. <meta charset="UTF-8">
  4. <title>TYEDI</title>
  5. <link rel="stylesheet" href="{{ url_for('static', filename='css/app.css') }}">
  6. </head>
  7. <body>
  8. <header>
  9. <div id="nav_heading">
  10. MEDICINAL PLANT FINDER?
  11. </div>
  12. </header>
  13. <section>
  14. <div class="container">
  15. <div id="heading">
  16. GET THE INFO ABOUT THE PLANT
  17. </div>
  18. <div id="subheading">
  19. Upload the image the find which type of medicinal plant it is.
  20. </div>
  21. <div id="uploadDiv">Select the IMAGE</div>
  22. </div>
  23. </section>
  24. <script src="{{ url_for('static', filename='js/app.js') }}"></script>
  25. </body>
  26. </html>
CSS Code
  1. @import url(https://fonts.googleapis.com/css?family=Roboto:300);
  2.  
  3. .sw* {
  4. margin: 0;
  5. }
  6.  
  7. body{
  8. /* font-family: "Gill Sans Extrabold", sans-serif; */
  9. background-color: #ecfdf3;
  10. }
  11. #nav_heading {
  12. padding:10px;
  13. height: 50px;
  14. text-align: center;
  15. line-height: 50px;
  16. font-weight: bolder;
  17. font-size: 2.5rem;
  18. background-color: #fff;
  19. box-shadow: rgba(10, 160, 35, 0.15) 0px 48px 200px 0px;
  20.  
  21. font-family: 'Roboto Slab', serif;
  22. }
  23.  
  24. section{
  25. height:calc(100vh - 70px);
  26. display: flex;
  27. flex-direction: column;
  28. align-items: center;
  29. justify-content: center;
  30. box-shadow: rgba(42, 8, 234, 0.15) 0px 48px 100px 0px;
  31. }
  32. section .container{
  33. display: flex;
  34. flex-direction: column;
  35. align-items: center;
  36. justify-content: center;
  37. width:500px;
  38.  
  39. height:300px;
  40. border-radius: 1rem;
  41. background: #2cbc63;
  42. border: 2px solid #033510;
  43. }
  44.  
  45. #heading{
  46. /* margin-top:-1rem; */
  47. font-size: 1.8rem;
  48. }
  49.  
  50. #uploadDiv{
  51. margin-top:2rem;
  52. width: 150px;
  53. height:70px;
  54. background-color:#fff;
  55. border: 2px solid #033510;
  56. border-radius: 0.5rem;
  57. line-height:70px;
  58. text-align: center;
  59. font-weight: 600;
  60.  
  61. font-family: 'Roboto Slab', serif;
  62. box-shadow: rgba(0, 0, 0, 0.25) 0px 0.0625em 0.0625em, rgba(0, 0, 0, 0.25) 0px 0.125em 0.5em, rgba(255, 255, 255, 0.1) 0px 0px 0px 1px inset;
  63. }
  64.  
  65. #uploadDiv:hover{
  66. cursor:pointer;
  67. }
  68.  
  69. #uploadDiv:active{
  70. transform: scale(0.95);
  71. }
JavaScript Code
  1. console.log('yes')
  2. document.getElementById('uploadDiv').addEventListener('click', function() {
  3. let input = document.createElement('input');
  4. input.type = 'file';
  5. input.accept = 'image/*';
  6.  
  7. input.onchange = function(e) {
  8. let file = e.target.files[0];
  9. let formData = new FormData();
  10. formData.append('file', file);
  11.  
  12. fetch('/upload', {
  13. method: 'POST',
  14. body: formData
  15. })
  16. .then(response => response.text())
  17. .then(result => {
  18. console.log(result);
  19. })
  20. .catch(error => {
  21. console.error('Error:', error);
  22. });
  23. };
  24.  
  25. input.click();
  26. });

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.