-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.py
49 lines (33 loc) · 1.09 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import sys
import numpy as np
from flask import Flask, render_template, request
from werkzeug.utils import secure_filename
from tensorflow.keras.preprocessing import image
from tensorflow.keras.models import load_model
from PIL import Image, ImageFile
import my_tf_mod
from io import BytesIO
import matplotlib.pyplot as plt
import base64
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/Prediction', methods=['GET','POST'])
def pred():
if request.method=='POST':
file = request.files['file']
org_img, img= my_tf_mod.preprocess(file)
print(img.shape)
fruit_dict=my_tf_mod.classify_fruit(img)
rotten=my_tf_mod.check_rotten(img)
img_x=BytesIO()
plt.imshow(org_img/255.0)
plt.savefig(img_x,format='png')
plt.close()
img_x.seek(0)
plot_url=base64.b64encode(img_x.getvalue()).decode('utf8')
return render_template('Pred3.html', fruit_dict=fruit_dict, rotten=rotten, plot_url=plot_url)
if __name__=='__main__':
app.run(debug=True)