File size: 1,195 Bytes
6aee512
 
 
 
 
3190848
6aee512
 
 
 
 
01e669d
6aee512
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import gradio as gr
from huggingface_hub import HfApi
import requests
import os

HUGGINGFACE_TOKEN = os.environ.get("HUGGINGFACE_TOKEN")

def summarize(text: str) -> str:
   if not text:
       return "يرجى إدخال نص للتلخيص"
       
   api_url = "https://api-inference.huggingface.co/models/mradermacher/SambaLingo-Arabic-Chat-70B-GGUF"
   headers = {"Authorization": f"Bearer {HUGGINGFACE_TOKEN}"}
   payload = {
       "inputs": f"""قم بتلخيص النص التالي:
       {text}
       """,
       "parameters": {
           "max_new_tokens": 2000,
           "temperature": 0.7
       }
   }
   
   try:
       response = requests.post(api_url, headers=headers, json=payload)
       return response.json()[0]["generated_text"]
   except Exception as e:
       return f"حدث خطأ: {str(e)}"

interface = gr.Interface(
   fn=summarize,
   inputs=gr.Textbox(label="النص الفلسفي", lines=8, text_align="right"),
   outputs=gr.Textbox(label="الملخص", lines=6, text_align="right"),
   title="ملخص النصوص الفلسفية",
   description="أداة لتلخيص النصوص الفلسفية باللغة العربية"
)

interface.launch()