Spaces:
Sleeping
Sleeping
Fix cache not found & memory leak
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from keras.layers import *
|
|
7 |
from keras.preprocessing.text import Tokenizer
|
8 |
import os
|
9 |
import hashlib
|
|
|
10 |
|
11 |
os.mkdir("cache")
|
12 |
|
@@ -28,7 +29,7 @@ def train(data: str, message: str):
|
|
28 |
vocab_size = len(tokenizer.word_index) + 1
|
29 |
data_hash = hash_str(data)+".keras"
|
30 |
if data_hash in os.listdir("cache"):
|
31 |
-
model = load_model(data_hash)
|
32 |
else:
|
33 |
input_layer = Input(shape=(inp_len,))
|
34 |
emb_layer = Embedding(input_dim=vocab_size, output_dim=emb_size, input_length=inp_len)(input_layer)
|
@@ -77,6 +78,7 @@ def train(data: str, message: str):
|
|
77 |
if max_v < i:
|
78 |
max_v = i
|
79 |
max_o = ind
|
|
|
80 |
return responses[ind]
|
81 |
|
82 |
iface = gr.Interface(fn=train, inputs=["text", "text"], outputs="text")
|
|
|
7 |
from keras.preprocessing.text import Tokenizer
|
8 |
import os
|
9 |
import hashlib
|
10 |
+
import keras
|
11 |
|
12 |
os.mkdir("cache")
|
13 |
|
|
|
29 |
vocab_size = len(tokenizer.word_index) + 1
|
30 |
data_hash = hash_str(data)+".keras"
|
31 |
if data_hash in os.listdir("cache"):
|
32 |
+
model = load_model("cache/"+data_hash)
|
33 |
else:
|
34 |
input_layer = Input(shape=(inp_len,))
|
35 |
emb_layer = Embedding(input_dim=vocab_size, output_dim=emb_size, input_length=inp_len)(input_layer)
|
|
|
78 |
if max_v < i:
|
79 |
max_v = i
|
80 |
max_o = ind
|
81 |
+
keras.backend.clear_session()
|
82 |
return responses[ind]
|
83 |
|
84 |
iface = gr.Interface(fn=train, inputs=["text", "text"], outputs="text")
|