Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
import re
|
| 4 |
+
from typing import Dict, List, Any
|
| 5 |
+
|
| 6 |
+
# نفس الفئات السابقة PhilosophicalTerms و TextProcessor
|
| 7 |
+
# [يمكنني تقديمها إذا أردت]
|
| 8 |
+
|
| 9 |
+
def validate_language(text: str) -> bool:
|
| 10 |
+
arabic_pattern = re.compile(r'[\u0600-\u06FF]')
|
| 11 |
+
english_pattern = re.compile('[a-zA-Z]')
|
| 12 |
+
return len(arabic_pattern.findall(text)) > len(english_pattern.findall(text))
|
| 13 |
+
|
| 14 |
+
def summarize(text: str) -> Dict[str, str]:
|
| 15 |
+
client = InferenceClient("methodya/arabic-summarizer-philosophy-v3")
|
| 16 |
+
|
| 17 |
+
messages = [
|
| 18 |
+
{"role": "system", "content": "أنت مساعد عربي متخصص في تلخيص النصوص الفلسفية..."},
|
| 19 |
+
{"role": "user", "content": text}
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
response = client.text_generation(
|
| 23 |
+
text,
|
| 24 |
+
max_new_tokens=2000,
|
| 25 |
+
temperature=0.7
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
return {"summary": response, "status": "success"}
|
| 29 |
+
|
| 30 |
+
# واجهة Gradio
|
| 31 |
+
def create_interface():
|
| 32 |
+
with gr.Interface(
|
| 33 |
+
fn=summarize,
|
| 34 |
+
inputs=gr.Textbox(label="النص الفلسفي", lines=8, dir="rtl"),
|
| 35 |
+
outputs=gr.Textbox(label="الملخص", lines=6, dir="rtl"),
|
| 36 |
+
title="ملخص النصوص الفلسفية",
|
| 37 |
+
description="أداة لتلخيص النصوص الفلسفية باللغة العربية"
|
| 38 |
+
) as interface:
|
| 39 |
+
return interface
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
iface = create_interface()
|
| 43 |
+
iface.launch()
|