-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
55 lines (46 loc) · 1.27 KB
/
main.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
from flask import Flask, render_template, request
from werkzeug.utils import secure_filename
from werkzeug.datastructures import FileStorage
from keras.preprocessing.image import ImageDataGenerator
import tensorflow as tf
import numpy as np
import os
from PIL import Image
try:
import shutil
shutil.rmtree('uploaded/image')
# os.system('cd uploaded')
os.system('mkdir uploaded/image')
os.system('cd ..')
print()
except:
print('fail')
pass
model = tf.keras.models.load_model('model_06-0.91.h5')
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'uploaded/image'
@app.route('/')
def upload_f():
return render_template('upload.html')
def finds():
vals = ['Star', 'Galaxy']
a = os.listdir('uploaded/image')
b = 'uploaded/image/' + a[0]
print(b)
image = Image.open(b)
numpydata = np.asarray(image)
X = numpydata / 255.0
X = X.reshape(1, X.shape[0], X.shape[1], 3)
pred = model.predict_generator(X)
print(pred)
# print(np.argmax(pred))
return vals[int(pred[0][0])]
@app.route('/uploader', methods = ['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
f.save(os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(f.filename)))
val = finds()
return render_template('pred.html', ss = val)
if __name__ == '__main__':
app.run()