minor changes

parent f0cdb539
import math
import random
import os
from werkzeug.utils import secure_filename
import numpy as np
from flask import Flask, request, jsonify, render_template
from flask import Flask, request, jsonify, render_template, flash, redirect, url_for
from PIL import Image
from urllib import request
#from urllib import request
from io import BytesIO
from keras_preprocessing import image
import urllib.request
......@@ -11,16 +14,23 @@ from datetime import date
from keras.models import load_model
import csv
UPLOAD_FOLDER = ''
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
# Create flask app
flask_app = Flask(__name__)
flask_app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
print("worr")
model1 = load_model('imgClassification.h5')
print("wk")
wt = random.randint(380, 490)
# wt = random.randint(380, 490)
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@flask_app.route("/")
def Home():
......@@ -45,7 +55,8 @@ def classify():
def price():
today = date.today()
dt = today.strftime("%d/%m/%Y")
image_path = "https://static9.depositphotos.com/1628352/1107/i/600/depositphotos_11071200-stock-photo-cabbage.jpg"
image_path = "http://192.168.8.103/capture?_cb=1634477807414"
wt = random.randint(380, 560)
class_names = ['banana', 'cabbage', 'cucumber', 'mango', 'orange', 'tomato']
img = Image.open(BytesIO(request.urlopen(image_path).read())).resize((224, 224))
# img = image.load_img(request.urlopen(image_path), target_size=(224,224,3))
......@@ -68,9 +79,54 @@ def price():
print(line['price'])
return render_template("resultsPrice.html", vegita = out, dte = dt, price = para, weight = wt)
# return render_template("predi.html", prediction_text_class_price="The price is {}".format(para))
return render_template("resultsPrice.html", vegita = out, dte = dt, price = para, weight = wt, esti = math.trunc(int(para) * int(wt) / 1000))
@flask_app.route("/priceC", methods = ["POST"])
def priceC():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit an empty part without filename
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
print(filename)
image_path = filename
print("workinggggg")
today = date.today()
wt = random.randint(380, 560)
dt = today.strftime("%d/%m/%Y")
class_names = ['banana', 'cabbage', 'cucumber', 'mango', 'orange', 'tomato']
img = image.load_img(image_path, target_size=(224,224,3))
# img = image.load_img(request.urlopen(image_path), target_size=(224,224,3))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
images = np.vstack([x])
pred = model1.predict(images, batch_size=6)
label = np.argmax(pred, axis=1)
out = class_names[np.argmax(pred)]
with open('data/Predict_vegetable_2021_SL.csv', encoding="utf8") as f:
csv_reader = csv.DictReader(f)
next(csv_reader)
for line in csv_reader:
if line['date'] == dt and line['item'] == out:
para = line['price']
print(line['price'])
return render_template("resultsPrice.html", vegita = out, dte = dt, price = para, weight = wt, esti = math.trunc(int(para) * int(wt) / 1000))
if __name__ == "__main__":
flask_app.run(debug=False)
\ No newline at end of file
date,item,price
16/10/2021,banana,97
16/10/2021,mango,46
16/10/2021,orange,64
16/10/2021,cabbage,110
16/10/2021,cucumber,92
16/10/2021,tomato,122
17/10/2021,banana,101
17/10/2021,mango,54
17/10/2021,orange,62
17/10/2021,cabbage,135
17/10/2021,cucumber,98
17/10/2021,tomato,115
18/10/2021,banana,98
18/10/2021,mango,51
18/10/2021,orange,62
18/10/2021,cabbage,101
18/10/2021,cucumber,82
18/10/2021,tomato,77
19/10/2021,banana,94
19/10/2021,mango,66
19/10/2021,orange,82
19/10/2021,cabbage,114
19/10/2021,cucumber,90
19/10/2021,tomato,63
20/10/2021,banana,54
20/10/2021,mango,35
20/10/2021,orange,75
20/10/2021,cabbage,94
20/10/2021,cucumber,82
20/10/2021,tomato,90
21/10/2021,banana,98
21/10/2021,mango,51
21/10/2021,orange,62
21/10/2021,cabbage,101
21/10/2021,cucumber,82
21/10/2021,tomato,77
22/10/2021,banana,89
22/10/2021,mango,53
22/10/2021,orange,77
22/10/2021,cabbage,90
22/10/2021,cucumber,85
22/10/2021,tomato,96
23/10/2021,banana,95
23/10/2021,mango,59
23/10/2021,orange,82
23/10/2021,cabbage,99
23/10/2021,cucumber,84
23/10/2021,tomato,97
24/10/2021,banana,94
24/10/2021,mango,66
24/10/2021,orange,82
24/10/2021,cabbage,114
24/10/2021,cucumber,90
24/10/2021,tomato,63
25/10/2021,banana,98
25/10/2021,mango,51
25/10/2021,orange,62
25/10/2021,cabbage,101
25/10/2021,cucumber,82
25/10/2021,tomato,77
26/10/2021,banana,89
26/10/2021,mango,53
26/10/2021,orange,77
26/10/2021,cabbage,90
26/10/2021,cucumber,85
26/10/2021,tomato,96
27/10/2021,banana,94
27/10/2021,mango,66
27/10/2021,orange,82
27/10/2021,cabbage,114
27/10/2021,cucumber,90
27/10/2021,tomato,63
28/10/2021,banana,98
28/10/2021,mango,51
28/10/2021,orange,62
28/10/2021,cabbage,101
28/10/2021,cucumber,82
28/10/2021,tomato,77
29/10/2021,banana,89
29/10/2021,mango,53
29/10/2021,orange,77
29/10/2021,cabbage,90
29/10/2021,cucumber,85
29/10/2021,tomato,96
30/10/2021,banana,94
30/10/2021,mango,66
30/10/2021,orange,82
30/10/2021,cabbage,114
30/10/2021,cucumber,90
30/10/2021,tomato,63
......@@ -102,14 +102,14 @@
<div class="container">
<div class="row align-items-center justify-content-between">
<div class="col-md">
<img src="https://static9.depositphotos.com/1628352/1107/i/600/depositphotos_11071200-stock-photo-cabbage.jpg" class="img-fluid" alt=""/>
<img src="http://192.168.8.103/capture?_cb=1634477807414" class="img-fluid" alt=""/>
</div>
<div class="col-md p-5">
<h2>Device Connection</h2>
<p>
Please connect your <span class="text-warning"> OrgiCheck&trade; Smart</span> with the same network
</p>
<a href="http://192.168.8.103/" class="btn btn-light mt-3">
<a href="#check" class="btn btn-light mt-3">
<i class="bi bi-camera"></i> Retake Image
</a>
</div>
......@@ -155,8 +155,7 @@
<input class="btn btn-primary" type="file" id="img" name="img" accept="image/*">
<br>
<br>
<button data-bs-toggle="modal"
data-bs-target="#diseases" class="btn btn-warning">Check with choosed image</button>
<button type="submit" class="btn btn-warning">Check with choosed image</button>
</form>
or
......@@ -199,12 +198,11 @@
</div>
<h3 class="card-title mb-3">Price</h3>
<form action="{{ url_for('price')}}"method="post">
<input class="btn btn-primary" type="file" id="img" name="img" accept="image/*">
<form action="{{ url_for('priceC')}}"method="post" enctype="multipart/form-data">
<input class="btn btn-primary" type="file" id="img" name="file" accept="image/*">
<br>
<br>
<button type="submit" data-bs-toggle="modal"
data-bs-target="#price" class="btn btn-warning">Check with choosed image</button>
<button type="submit" class="btn btn-warning">Check with choosed image</button>
</form>
or
<br>
......@@ -212,7 +210,6 @@
<button type="submit" class="btn btn-success">Check with captured image</button>
</form>
</div>
{{ price }}
</div>
</div>
......
......@@ -64,9 +64,10 @@
</div>
<h3 class="card-title mb-3">Price</h3>
<p>{{ vegita }}</p>
<p>{{ weight }}</p>
<p> {{ price }} </p>
<p><span class="text-warning"> Detected Fruit/Vegetable : </span>{{ vegita }}</p>
<p><span class="text-warning"> Estimated Weight : </span>{{ weight }} grams.</p>
<p> <span class="text-warning"> Estimated Price for 1Kg : </span> LKR. {{ price }}.00 </p>
<p> <span class="text-warning"> Estimated Price : </span> LKR. {{ esti }}.00 </p>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment