netmouse commited on
Commit
f9a5aa7
·
verified ·
1 Parent(s): a28a1e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForCausalLM, AutoConfig
3
  from peft import PeftModel, LoraConfig
 
4
 
5
  # Define the path where the model and adapters are saved
6
  model_path = "yentinglin/Llama-3-Taiwan-8B-Instruct" # Update this to your model path
@@ -20,8 +21,14 @@ base_model = AutoModelForCausalLM.from_pretrained(model_path, config=config, ign
20
  model = PeftModel.from_pretrained(base_model, adapter_path)
21
 
22
  def generate_text(input_text):
23
- input_ids = tokenizer.encode(input_text, return_tensors='pt')
24
- outputs = model.generate(input_ids, max_length=50, num_return_sequences=1)
 
 
 
 
 
 
25
  generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
26
  return generated_text
27
 
 
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForCausalLM, AutoConfig
3
  from peft import PeftModel, LoraConfig
4
+ from unsloth.chat_templates import get_chat_template
5
 
6
  # Define the path where the model and adapters are saved
7
  model_path = "yentinglin/Llama-3-Taiwan-8B-Instruct" # Update this to your model path
 
21
  model = PeftModel.from_pretrained(base_model, adapter_path)
22
 
23
  def generate_text(input_text):
24
+ inputs = tokenizer.apply_chat_template(
25
+ messages,
26
+ tokenize = True,
27
+ add_generation_prompt = True, # Must add for generation
28
+ return_tensors = "pt",
29
+ ).to("cuda")
30
+ #input_ids = tokenizer.encode(input_text, return_tensors='pt')
31
+ outputs = model.generate(inputs, max_length=50, num_return_sequences=1)
32
  generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
33
  return generated_text
34