Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
6 |
|
7 |
-
# Load model
|
8 |
-
|
9 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def generate_text(prompt):
|
12 |
-
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
13 |
|
14 |
# Generate text (you might need to adjust generation parameters)
|
15 |
output = model.generate(
|
@@ -30,7 +39,7 @@ iface = gr.Interface(
|
|
30 |
inputs=gr.Textbox(lines=5, placeholder="Enter your story prompt here..."),
|
31 |
outputs=gr.Textbox(),
|
32 |
title="Arabic Story Teller",
|
33 |
-
description="A Qwen2.5-7B model finetuned for Arabic story generation.",
|
34 |
)
|
35 |
|
36 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
from peft import PeftModel, PeftConfig
|
4 |
|
5 |
+
# Base model and adapter model names
|
6 |
+
base_model_name = "unsloth/Qwen2.5-7B-Instruct-bnb-4bit"
|
7 |
+
adapter_model_name = "djmax13/qween7.5-arabic-story-teller-bnb-4bit"
|
8 |
|
9 |
+
# Load base model
|
10 |
+
base_model = AutoModelForCausalLM.from_pretrained(base_model_name)
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
|
12 |
+
|
13 |
+
# Load LoRA configuration
|
14 |
+
config = PeftConfig.from_pretrained(adapter_model_name)
|
15 |
+
|
16 |
+
# Load LoRA adapter and merge it with the base model
|
17 |
+
model = PeftModel.from_pretrained(base_model, adapter_model_name)
|
18 |
+
model = model.merge_and_unload() # Optional: Merge adapter weights into base model for potential speedup
|
19 |
|
20 |
def generate_text(prompt):
|
21 |
+
input_ids = tokenizer.encode(prompt, return_tensors="pt").to(model.device) # Move input to model's device
|
22 |
|
23 |
# Generate text (you might need to adjust generation parameters)
|
24 |
output = model.generate(
|
|
|
39 |
inputs=gr.Textbox(lines=5, placeholder="Enter your story prompt here..."),
|
40 |
outputs=gr.Textbox(),
|
41 |
title="Arabic Story Teller",
|
42 |
+
description="A Qwen2.5-7B model finetuned for Arabic story generation using LoRA.",
|
43 |
)
|
44 |
|
45 |
iface.launch()
|