Spaces:
Runtime error
Runtime error
youssef227
commited on
Create app.py
Browse files
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)
|