File tree 1 file changed +11
-0
lines changed
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 23
23
model_predict = loaded_model .signatures ["serving_default" ]
24
24
25
25
26
+ def warm_up_model ():
27
+ """Sends a dummy request to the model to 'warm it up'."""
28
+ dummy_query = "SELECT * FROM users WHERE id = 1"
29
+ query_seq = TOKENIZER .texts_to_sequences ([dummy_query ])
30
+ query_vec = pad_sequences (query_seq , maxlen = MAX_LEN )
31
+ input_tensor = tf .convert_to_tensor (query_vec , dtype = tf .float32 )
32
+ _ = model_predict (input_tensor ) # Make a dummy prediction to initialize the model
33
+ print ("Model warmed up and ready to serve requests." )
34
+
35
+
26
36
@app .route ("/predict" , methods = ["POST" ])
27
37
def predict ():
28
38
if not request .json or "query" not in request .json :
@@ -54,4 +64,5 @@ def predict():
54
64
55
65
56
66
if __name__ == "__main__" :
67
+ warm_up_model ()
57
68
app .run (host = "0.0.0.0" , port = 8000 , debug = True )
You can’t perform that action at this time.
0 commit comments