Spaces:
Running
Running
File size: 1,630 Bytes
06edfcd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# نسخة GPU - تستخدم CUDA لتسريع المعالجة
# لتشغيل هذه النسخة يجب اختيار GPU في إعدادات Space على Hugging Face
import gradio as gr
from huggingface_hub import hf_hub_download
from llama_cpp import Llama
import os
model_path = hf_hub_download(
repo_id="methodya/arabic-summarizer-philosophy-v3",
filename="sambalingo-arabic-chat.Q5_K_M.gguf"
)
llm = Llama(
model_path=model_path,
n_ctx=2048,
n_threads=4,
n_gpu_layers=-1 # تفعيل GPU
)
def summarize(text: str) -> str:
if not text:
return "يرجى إدخال نص للتلخيص"
prompt = f"""أنت مساعد متخصص في تلخيص النصوص الفلسفية العربية. المطلوب:
1. تلخيص النص بشكل مركز ومختصر
2. الحفاظ على الأفكار الرئيسية
3. عدم الخروج عن موضوع النص
النص للتلخيص:
{text}
"""
try:
output = llm(
prompt,
max_tokens=2000,
temperature=0.7,
stop=["User:", "\n\n"]
)
return output['choices'][0]['text']
except Exception as e:
return f"حدث خطأ: {str(e)}"
interface = gr.Interface(
fn=summarize,
inputs=gr.Textbox(label="النص الفلسفي", lines=8, text_align="right"),
outputs=gr.Textbox(label="الملخص", lines=6, text_align="right"),
title="ملخص النصوص الفلسفية",
description="أداة لتلخيص النصوص الفلسفية باللغة العربية"
)
if __name__ == "__main__":
interface.launch() |