Update app.py
Browse files
app.py
CHANGED
|
@@ -3,15 +3,15 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
| 3 |
|
| 4 |
model_name = "MahmoudIbrahim/Meta-LLama3-Instruct-Arabic"
|
| 5 |
|
|
|
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
model = AutoModelForCausalLM.from_pretrained(
|
| 8 |
model_name,
|
| 9 |
-
device_map="cpu",
|
| 10 |
-
trust_remote_code=True
|
|
|
|
| 11 |
)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
generator = pipeline(
|
| 16 |
"text-generation",
|
| 17 |
model=model,
|
|
@@ -20,21 +20,18 @@ generator = pipeline(
|
|
| 20 |
|
| 21 |
def inspire(future, value, skill):
|
| 22 |
if not future or not value or not skill:
|
| 23 |
-
return "โ ๏ธ ุฑุฌุงุกู ุฃ
|
| 24 |
-
|
| 25 |
prompt = (
|
| 26 |
f"ุงูุชุจ ุฌู
ูุฉ ุนุฑุจูุฉ ูุตูุฑุฉ ูู
ููู
ุฉ ุชุตู ู
ุณุชูุจู ุดุฎุต ูุฑูุฏ {future}ุ "
|
| 27 |
f"ููุคู
ู ุจู {value}ุ ููู
ุชูู ู
ูุงุฑุฉ {skill}. "
|
| 28 |
-
"ูุชูู ุงูุฌู
ูุฉ
|
| 29 |
)
|
| 30 |
-
|
| 31 |
try:
|
| 32 |
result = generator(
|
| 33 |
prompt,
|
| 34 |
max_new_tokens=60,
|
| 35 |
temperature=0.8,
|
| 36 |
-
top_p=0.9
|
| 37 |
-
repetition_penalty=1.2
|
| 38 |
)
|
| 39 |
text = result[0]["generated_text"].strip()
|
| 40 |
if text.startswith(prompt):
|
|
@@ -52,7 +49,7 @@ demo = gr.Interface(
|
|
| 52 |
],
|
| 53 |
outputs=gr.Textbox(label="๐ ุฑุคูุชู ุงูู
ุณุชูุจููุฉ", lines=3),
|
| 54 |
title="ุฐูุงุก ูุตู
ู
ู
ุณุชูุจูู ุจุงูุนุฑุจูุฉ",
|
| 55 |
-
description="
|
| 56 |
theme="soft"
|
| 57 |
)
|
| 58 |
|
|
|
|
| 3 |
|
| 4 |
model_name = "MahmoudIbrahim/Meta-LLama3-Instruct-Arabic"
|
| 5 |
|
| 6 |
+
# โ
ูุญู
ู ุงููู
ูุฐุฌ ุจุฏูู 4bit ูุจุฏูู quantization (ูุดุชุบู ุนูู CPU)
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
model_name,
|
| 10 |
+
device_map="cpu", # ุชุดุบูู ุนูู CPU
|
| 11 |
+
trust_remote_code=True, # ููุณู
ุงุญ ุจุชุญู
ูู ุงูููุฏ ุงูุฎุงุต ุจุงููู
ูุฐุฌ
|
| 12 |
+
torch_dtype="float32" # ูุณุชุฎุฏู
ุฏูุฉ ุนุงุฏูุฉ ุชูุงุณุจ CPU
|
| 13 |
)
|
| 14 |
|
|
|
|
|
|
|
| 15 |
generator = pipeline(
|
| 16 |
"text-generation",
|
| 17 |
model=model,
|
|
|
|
| 20 |
|
| 21 |
def inspire(future, value, skill):
|
| 22 |
if not future or not value or not skill:
|
| 23 |
+
return "โ ๏ธ ุฑุฌุงุกู ุฃุฌูุจู ุนูู ุฌู
ูุน ุงูุญููู."
|
|
|
|
| 24 |
prompt = (
|
| 25 |
f"ุงูุชุจ ุฌู
ูุฉ ุนุฑุจูุฉ ูุตูุฑุฉ ูู
ููู
ุฉ ุชุตู ู
ุณุชูุจู ุดุฎุต ูุฑูุฏ {future}ุ "
|
| 26 |
f"ููุคู
ู ุจู {value}ุ ููู
ุชูู ู
ูุงุฑุฉ {skill}. "
|
| 27 |
+
"ูุชูู ุงูุฌู
ูุฉ ุฅูุณุงููุฉ ูุดุงุนุฑูุฉ ูู
ููุฆุฉ ุจุงูุฃู
ู."
|
| 28 |
)
|
|
|
|
| 29 |
try:
|
| 30 |
result = generator(
|
| 31 |
prompt,
|
| 32 |
max_new_tokens=60,
|
| 33 |
temperature=0.8,
|
| 34 |
+
top_p=0.9
|
|
|
|
| 35 |
)
|
| 36 |
text = result[0]["generated_text"].strip()
|
| 37 |
if text.startswith(prompt):
|
|
|
|
| 49 |
],
|
| 50 |
outputs=gr.Textbox(label="๐ ุฑุคูุชู ุงูู
ุณุชูุจููุฉ", lines=3),
|
| 51 |
title="ุฐูุงุก ูุตู
ู
ู
ุณุชูุจูู ุจุงูุนุฑุจูุฉ",
|
| 52 |
+
description="ูู
ูุฐุฌ ุนุฑุจู ู
ุชูุฏูู
ููุชุจ ุฌู
ูุฉ ู
ููู
ุฉ ุจูุงุกู ุนูู ููู
ู ูุฃุญูุงู
ู.",
|
| 53 |
theme="soft"
|
| 54 |
)
|
| 55 |
|