Spaces:
Runtime error
Runtime error
File size: 836 Bytes
0a2ab02 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
from transformers import GPT2LMHeadModel, GPT2Tokenizer
def aumentar_prompt(script, prompt, model_name='gpt2'):
# Carregar modelo e tokenizer
model = GPT2LMHeadModel.from_pretrained(model_name)
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
# Tokenizar o script e prompt
input_ids = tokenizer.encode(script + "\n" + prompt, return_tensors="pt")
# Gerar texto estendido
output = model.generate(input_ids, max_length=150, num_beams=5, no_repeat_ngram_size=2, top_k=50, top_p=0.95, temperature=0.7)
# Decodificar o texto gerado
extended_prompt = tokenizer.decode(output[0], skip_special_tokens=True)
return extended_prompt
# Exemplo de uso
script = "Em um mundo distante, onde"
prompt = "um herói corajoso"
extended_prompt = aumentar_prompt(script, prompt)
print(extended_prompt)
|