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