methodya commited on
Commit
cbe8696
·
verified ·
1 Parent(s): 9f1a8e1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from huggingface_hub import hf_hub_download
3
+ from llama_cpp import Llama
4
+ import os
5
+
6
+ # تحميل النموذج من Hugging Face
7
+ model_path = hf_hub_download(
8
+ repo_id="methodya/arabic-summarizer-philosophy-v3",
9
+ filename="sambalingo-arabic-chat.Q5_K_M.gguf"
10
+ )
11
+
12
+ # إعداد النموذج
13
+ llm = Llama(
14
+ model_path=model_path,
15
+ n_ctx=2048,
16
+ n_threads=4
17
+ )
18
+
19
+ # دالة تلخيص النصوص
20
+ def summarize(text: str) -> str:
21
+ if not text:
22
+ return "يرجى إدخال نص للتلخيص"
23
+
24
+ prompt = f"""أنت مساعد عربي متخصص في تلخيص النصوص الفلسفية. قم بتلخيص النص التالي:
25
+ {text}
26
+ """
27
+
28
+ try:
29
+ output = llm(
30
+ prompt,
31
+ max_tokens=2000,
32
+ temperature=0.7,
33
+ stop=["User:", "\n\n"]
34
+ )
35
+ return output['choices'][0]['text']
36
+ except Exception as e:
37
+ return f"حدث خطأ: {str(e)}"
38
+
39
+ # واجهة المستخدم باستخدام Streamlit
40
+ st.title("ملخص النصوص الفلسفية")
41
+ st.markdown("أداة لتلخيص النصوص الفلسفية باللغة العربية")
42
+
43
+ # إنشاء واجهة الإدخال والإخراج
44
+ text_input = st.text_area("النص الفلسفي", height=200)
45
+ if st.button("تلخيص"):
46
+ summary = summarize(text_input)
47
+ st.text_area("الملخص", value=summary, height=150, disabled=True)