feat: Added required files
Browse files- app.py +6 -10
- poembot_weight.h5 +3 -0
app.py
CHANGED
@@ -6,16 +6,12 @@ import tensorflow as tf
|
|
6 |
from tensorflow.keras.preprocessing.text import Tokenizer
|
7 |
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
8 |
|
|
|
9 |
# Static constants
|
10 |
-
vocab_size = 103
|
11 |
max_seq_len = 18
|
12 |
-
model = tf.keras.
|
13 |
-
|
14 |
-
|
15 |
-
tf.keras.layers.Dense(vocab_size, activation='softmax')
|
16 |
-
])
|
17 |
-
model.load_weights("model_weight/")
|
18 |
-
word_token = json.load("word_token.json")
|
19 |
# Main function
|
20 |
def text_generator(seed_text,n):
|
21 |
|
@@ -24,7 +20,7 @@ def text_generator(seed_text,n):
|
|
24 |
token_list = pad_sequences([token_list], maxlen=max_seq_len-1, padding='pre')
|
25 |
predicted = np.argmax(model.predict(token_list), axis=-1)
|
26 |
output_word = ""
|
27 |
-
output_word = word_token
|
28 |
if "0" in output_word[-1]:
|
29 |
output_word = output_word[:-1]
|
30 |
seed_text += " " + output_word +"."
|
@@ -38,4 +34,4 @@ iface = gr.Interface(
|
|
38 |
title="Poem Bot",
|
39 |
live=False
|
40 |
)
|
41 |
-
iface.launch()
|
|
|
6 |
from tensorflow.keras.preprocessing.text import Tokenizer
|
7 |
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
8 |
|
9 |
+
|
10 |
# Static constants
|
|
|
11 |
max_seq_len = 18
|
12 |
+
model = tf.keras.models.load_model('poembot_weight.h5')
|
13 |
+
with open("word_token.json") as wt:
|
14 |
+
word_token = json.load(wt)
|
|
|
|
|
|
|
|
|
15 |
# Main function
|
16 |
def text_generator(seed_text,n):
|
17 |
|
|
|
20 |
token_list = pad_sequences([token_list], maxlen=max_seq_len-1, padding='pre')
|
21 |
predicted = np.argmax(model.predict(token_list), axis=-1)
|
22 |
output_word = ""
|
23 |
+
output_word = word_token.get(str(predicted[0]))
|
24 |
if "0" in output_word[-1]:
|
25 |
output_word = output_word[:-1]
|
26 |
seed_text += " " + output_word +"."
|
|
|
34 |
title="Poem Bot",
|
35 |
live=False
|
36 |
)
|
37 |
+
iface.launch(debug=True)
|
poembot_weight.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7bbcc1ade1290a9d2cbd5544e56539d1e2d74a5b2c3d878e54440dbf1579d5f5
|
3 |
+
size 1097832
|