Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|