File size: 941 Bytes
d41889b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import LoraConfig, get_peft_model
import torch

# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("youssef227/llama-3-8b-Instruct-bnb-telcom-3", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("youssef227/llama-3-8b-Instruct-bnb-telcom-3", trust_remote_code=True)


def generator(text):
  inputs = tokenizer(
  [
      alpaca_prompt.format(
          f" {context}ุงู†ุช ู…ู…ุซู„ ุฎุฏู…ุฉ ุงู„ุนู…ู„ุงุก ู„ุฏู‰ ุดุฑูƒุฉ ููˆุฏุงููˆู†.ูˆ ุฏูŠ ู…ุนู„ูˆู…ุงุช ู…ู…ูƒู† ุชููŠุฏูƒ", # instruction
          text, # input
          "", # output - leave this blank for generation!
      )
  ], return_tensors = "pt").to("cuda")
  outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
  return tokenizer.batch_decode(outputs)
text = st.text_area('enter some text!')
if text:
  out = generator(text)
  st.json(out)