-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathapp.py
61 lines (52 loc) · 1.72 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
50
51
52
53
54
55
56
57
58
59
60
61
#from flask import Flask
#from flask import render_template
#from flask import request
#from PIL import Image
from prediction import *
import os
import cv2
from flask import Flask, render_template, request,jsonify
from PIL import Image
import tensorflow as tf
#import jinja2
app=Flask(__name__)
#app.jinja_env.line_statement_prefix = '%'
UPLOAD_FOLDER = os.path.basename('.')
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route("/", methods=['GET', 'POST'])
def application():
file=""
answer = None
error=""
if request.method=="POST":
try:
file= request.files["image"]
#if file.strip()=="":
# error="Pl. upload an Image"
if file:
#upload
f = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
file.save(f)
print(file.filename)
#read
#image = cv2.imread(UPLOAD_FOLDER+"/"+file.filename)
#filename = "{}.png".format(os.getpid())
#cv2.imwrite(filename, image)
#print(filename)
# Deleting from path after uploading
result=predict(file.filename)
#os.remove(filename)
if result=="":
error="Sorry!"
except(SyntaxError) as e:
error ="Could not understand"
print("Error:" + str(e))
try:
if result!="Sorry!":
answer=result
except Exception as e:
print(e)
return render_template('index.html', file=file,
answer=answer, error=error)
if __name__ == "__main__":
app.run(debug=True)