-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
71 lines (41 loc) · 1.59 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
62
63
64
65
66
67
68
69
70
71
from flask import Flask, render_template,request
from tensorflow.keras.preprocessing.sequence import pad_sequences
import tensorflow as tf
import pickle
import os
import sys
import re
import string
def predict(new_metin):
new_sayi = 40
model = tf.keras.models.load_model("saved_model.h5")
with open('tokenizer.pickle', 'rb') as handle:
tokenizer = pickle.load(handle)
max_sequence_len =143
for x in range(new_sayi):
token_list = tokenizer.texts_to_sequences([new_metin])[0]
token_list = pad_sequences([token_list], maxlen=max_sequence_len-1, padding='pre')
predicted = model.predict_classes(token_list, verbose=0)
output_word = ""
for word,index in tokenizer.word_index.items():
if index == predicted:
output_word = word
break
new_metin += " "+output_word
return new_metin
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/output', methods =["POST"])
def output():
if request.method == "POST":
user_input = request.form.get("start-poem")
if user_input != "":
lower = str.maketrans("ABCÇDEFGĞHIİJKLMNOÖPRŞSTUÜVYZ", "abcçdefgğhıijklmnoöprşstuüvyz")
user_input = user_input.translate(lower)
user_input = predict(user_input.translate(str.maketrans('', '', string.punctuation)))
else: user_input = "Lütfen bir önceki sayfaya gidip, bir cümle giriniz."
return render_template("output.html", output = user_input)
if __name__ == '__main__':
app.run(debug=True)