Spaces:
Sleeping
Sleeping
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
# https://www.youtube.com/watch?v=irjYqV6EebU | |
model_name = "gpt2" | |
def load(): | |
global model | |
global tokenizer | |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name) | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
def generate(input_text): | |
# Tokenize the input text | |
input_ids = tokenizer.encode(input_text, return_tensors="pt") | |
# Generate output using the model | |
output_ids = model.generate(input_ids, num_beams=5, no_repeat_ngram_size=2) | |
return tokenizer.decode(output_ids[0], skip_special_tokens=True) |