kjn1009 commited on
Commit
6f95380
β€’
1 Parent(s): 46772b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -27
app.py CHANGED
@@ -1,30 +1,13 @@
1
- from transformers import AutoModelForCausalLM, AutoTokenizer
2
- import torch
3
 
4
- # Prepare the input as before
5
- chat = [
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
- # 1: Load the model and tokenizer
11
- model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct", device_map="auto", torch_dtype=torch.bfloat16)
12
- tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct")
13
 
14
- # 2: Apply the chat template
15
- formatted_chat = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
16
- print("Formatted chat:\n", formatted_chat)
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)