LLM_Ariphes / app.py
Euryeth's picture
Update app.py
d5c6c7d verified
raw
history blame
608 Bytes
from transformers import pipeline
import os
# Cache setup
os.environ['HF_HOME'] = '/tmp/cache'
model = pipeline(
"text-generation",
model="gpt2",
device=-1 # Force CPU
)
def generate_text(prompt, max_new_tokens=560, max_context=1080):
"""Generate text with precise token control"""
output = model(
prompt,
max_new_tokens=max_new_tokens, # Response tokens (560)
max_length=min(max_context, 1024), # GPT-2's max context is 1024
truncation=True,
pad_token_id=50256 # Explicitly set to avoid warnings
)
return output[0]["generated_text"]