methodya commited on
Commit
06edfcd
·
verified ·
1 Parent(s): f482d86

Create app.py

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