radius / tools /arabic_generator.py
Batnini's picture
Update tools/arabic_generator.py
46d83f0 verified
raw
history blame contribute delete
716 Bytes
from transformers import pipeline
class ArabicTextGenerator:
def __init__(self):
self.model_loaded = False
def load_model(self):
if not self.model_loaded:
self.generator = pipeline(
'text-generation',
model='aubmindlab/aragpt2-base',
device=-1 # Force CPU
)
self.model_loaded = True
def generate(self, prompt, max_length=100):
self.load_model()
output = self.generator(
prompt,
max_length=max_length,
num_return_sequences=1,
pad_token_id=50256 # eos_token_id for aragpt2
)
return output[0]['generated_text']