Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,3 @@
|
|
1 |
-
|
2 |
-
from transformers import
|
3 |
-
|
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(
|
25 |
-
input_ids,
|
26 |
-
max_length=150, # Adjust as needed
|
27 |
-
num_return_sequences=1,
|
28 |
-
no_repeat_ngram_size=2,
|
29 |
-
top_k=50,
|
30 |
-
top_p=0.95,
|
31 |
-
temperature=0.7,
|
32 |
-
)
|
33 |
-
|
34 |
-
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
|
35 |
-
return generated_text
|
36 |
-
|
37 |
-
iface = gr.Interface(
|
38 |
-
fn=generate_text,
|
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()
|
|
|
1 |
+
# Load model directly
|
2 |
+
from transformers import AutoModel
|
3 |
+
model = AutoModel.from_pretrained("GhadyIbra250/qwen_arabic_stories")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|