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