Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,13 @@
|
|
1 |
-
from transformers import
|
2 |
-
import
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
{"role": "system", "content": "You are a sassy, wise-cracking robot as imagined by Hollywood circa 1986."},
|
7 |
-
{"role": "user", "content": "Hey, can you tell me any fun things to do in New York?"}
|
8 |
-
]
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
print(
|
17 |
-
|
18 |
-
# 3: Tokenize the chat (This can be combined with the previous step using tokenize=True)
|
19 |
-
inputs = tokenizer(formatted_chat, return_tensors="pt", add_special_tokens=False)
|
20 |
-
# Move the tokenized inputs to the same device the model is on (GPU/CPU)
|
21 |
-
inputs = {key: tensor.to(model.device) for key, tensor in inputs.items()}
|
22 |
-
print("Tokenized inputs:\n", inputs)
|
23 |
-
|
24 |
-
# 4: Generate text from the model
|
25 |
-
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.)
|
26 |
-
print("Generated tokens:\n", outputs)
|
27 |
-
|
28 |
-
# 5: Decode the output back to a string
|
29 |
-
decoded_output = tokenizer.decode(outputs[0][inputs['input_ids'].size(1):], skip_special_tokens=True)
|
30 |
-
print("Decoded output:\n", decoded_output)
|
|
|
1 |
+
from transformers import AutoTokenizer
|
2 |
+
from transformers import AutoModelForCausalLM
|
3 |
|
4 |
+
model = AutoModelForCausalLM.from_pretrained("yanolja/EEVE-Korean-Instruct-10.8B-v1.0")
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("yanolja/EEVE-Korean-Instruct-10.8B-v1.0")
|
|
|
|
|
|
|
6 |
|
7 |
+
prompt_template = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.\nHuman: {prompt}\nAssistant:\n"
|
8 |
+
text = 'νκ΅μ μλλ μ΄λμΈκ°μ? μλ μ νμ§ μ€ κ³¨λΌμ£ΌμΈμ.\n\n(A) κ²½μ±\n(B) λΆμ°\n(C) νμ\n(D) μμΈ\n(E) μ μ£Ό'
|
9 |
+
model_inputs = tokenizer(prompt_template.format(prompt=text), return_tensors='pt')
|
10 |
|
11 |
+
outputs = model.generate(**model_inputs, max_new_tokens=256)
|
12 |
+
output_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
|
13 |
+
print(output_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|