File size: 680 Bytes
f5b9309
 
28d8aa0
f5b9309
 
28d8aa0
f5b9309
 
 
f414ed4
f5b9309
 
 
 
28d8aa0
f5b9309
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

# නායකතුමා කියපු මොඩල් එක
model_id = "google/gemma-4-31B-it-assistant"

# මෙතනදී 0.5B නිසා සාමාන්‍ය CPU එකක වුණත් ලෝඩ් වෙයි
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16)

def generate_text(prompt):
    inputs = tokenizer(prompt, return_tensors="pt")
    outputs = model.generate(**inputs, max_new_tokens=50)
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

print(generate_text("Hi Inachi!"))