methodya commited on
Commit
cc3cf42
·
verified ·
1 Parent(s): 2cb60e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -27
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 = "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()
 
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()