|
import tensorflow as tf
|
|
from transformers import AutoTokenizer, TFAutoModelForSeq2SeqLM
|
|
|
|
|
|
model = TFAutoModelForSeq2SeqLM.from_pretrained('models\\greeting_model\\saved_model')
|
|
tokenizer = AutoTokenizer.from_pretrained('models\\greeting_model\\saved_model')
|
|
|
|
def generate_response(input_text, max_length=500):
|
|
|
|
input_ids = tokenizer.encode(input_text, return_tensors='tf')
|
|
|
|
|
|
outputs = model.generate(input_ids, max_length=max_length, num_beams=4, early_stopping=True)
|
|
|
|
|
|
decoded_response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
return decoded_response
|
|
|