Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
| 3 |
-
import torch
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
use_safetensors=True,
|
| 11 |
-
low_cpu_mem_usage=False
|
| 12 |
)
|
| 13 |
|
| 14 |
-
# تقليل طول المخرجات وتحسين السرعة
|
| 15 |
def generate_response(prompt):
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
inputs = tokenizer(full_prompt, return_tensors="pt", truncation=True, max_length=256)
|
| 20 |
-
|
| 21 |
-
outputs = model.generate(
|
| 22 |
-
**inputs,
|
| 23 |
-
max_length=256, # تقليل الطول الأقصى
|
| 24 |
-
num_return_sequences=1,
|
| 25 |
-
temperature=0.7,
|
| 26 |
-
do_sample=False, # تعطيل العينات العشوائية
|
| 27 |
-
num_beams=1 # تعطيل beam search
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 31 |
-
response = response.split("الجواب:")[-1].strip()
|
| 32 |
-
return response
|
| 33 |
|
| 34 |
-
# تعيين وقت timeout أطول
|
| 35 |
iface = gr.Interface(
|
| 36 |
fn=generate_response,
|
| 37 |
-
inputs=
|
| 38 |
-
outputs="text"
|
| 39 |
-
title="المساعد الفلسفي",
|
| 40 |
-
description="نموذج متخصص في الإجابة عن الأسئلة الفلسفية باللغة العربية"
|
| 41 |
)
|
| 42 |
|
| 43 |
-
iface.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
+
# استخدام النموذج مباشرة بدون LoRA
|
| 5 |
+
pipe = pipeline(
|
| 6 |
+
"text-generation",
|
| 7 |
+
model="deepseek-ai/deepseek-coder-1.3b-base",
|
| 8 |
+
device_map="auto"
|
|
|
|
|
|
|
| 9 |
)
|
| 10 |
|
|
|
|
| 11 |
def generate_response(prompt):
|
| 12 |
+
result = pipe(prompt, max_length=100)
|
| 13 |
+
return result[0]['generated_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
|
|
|
| 15 |
iface = gr.Interface(
|
| 16 |
fn=generate_response,
|
| 17 |
+
inputs="text",
|
| 18 |
+
outputs="text"
|
|
|
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
+
iface.launch()
|