youssef227 commited on
Commit
d41889b
ยท
verified ยท
1 Parent(s): 715c60e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM
2
+ from peft import LoraConfig, get_peft_model
3
+ import torch
4
+
5
+ # Load the tokenizer and model
6
+ tokenizer = AutoTokenizer.from_pretrained("youssef227/llama-3-8b-Instruct-bnb-telcom-3", trust_remote_code=True)
7
+ model = AutoModelForCausalLM.from_pretrained("youssef227/llama-3-8b-Instruct-bnb-telcom-3", trust_remote_code=True)
8
+
9
+
10
+ def generator(text):
11
+ inputs = tokenizer(
12
+ [
13
+ alpaca_prompt.format(
14
+ f" {context}ุงู†ุช ู…ู…ุซู„ ุฎุฏู…ุฉ ุงู„ุนู…ู„ุงุก ู„ุฏู‰ ุดุฑูƒุฉ ููˆุฏุงููˆู†.ูˆ ุฏูŠ ู…ุนู„ูˆู…ุงุช ู…ู…ูƒู† ุชููŠุฏูƒ", # instruction
15
+ text, # input
16
+ "", # output - leave this blank for generation!
17
+ )
18
+ ], return_tensors = "pt").to("cuda")
19
+ outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
20
+ return tokenizer.batch_decode(outputs)
21
+ text = st.text_area('enter some text!')
22
+ if text:
23
+ out = generator(text)
24
+ st.json(out)