Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import HfApi
|
| 3 |
import requests
|
| 4 |
-
|
| 5 |
import os
|
| 6 |
-
HUGGINGFACE_TOKEN = os.environ.get("HUGGINGFACE_TOKEN")
|
| 7 |
-
|
| 8 |
-
def summarize(text: str) -> str:
|
| 9 |
-
if not text:
|
| 10 |
-
return "يرجى إدخال نص للتلخيص"
|
| 11 |
-
|
| 12 |
-
api_url = "https://api-inference.huggingface.co/models/methodya/arabicPhiloV3"
|
| 13 |
-
headers = {"Authorization": f"Bearer {HUGGINGFACE_TOKEN}"}
|
| 14 |
-
payload = {
|
| 15 |
-
"inputs": f"""قم بتلخيص النص التالي:
|
| 16 |
-
{text}
|
| 17 |
-
""",
|
| 18 |
-
"parameters": {
|
| 19 |
-
"max_new_tokens": 2000,
|
| 20 |
-
"temperature": 0.7
|
| 21 |
-
}
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
try:
|
| 25 |
-
response = requests.post(api_url, headers=headers, json=payload)
|
| 26 |
-
return response.json()[0]["generated_text"]
|
| 27 |
-
except Exception as e:
|
| 28 |
-
return f"حدث خطأ: {str(e)}"
|
| 29 |
-
|
| 30 |
-
interface = gr.Interface(
|
| 31 |
-
fn=summarize,
|
| 32 |
-
inputs=gr.Textbox(label="النص الفلسفي", lines=8, text_align="right"),
|
| 33 |
-
outputs=gr.Textbox(label="الملخص", lines=6, text_align="right"),
|
| 34 |
-
title="ملخص النصوص الفلسفية",
|
| 35 |
-
description="أداة لتلخيص النصوص الفلسفية باللغة العربية"
|
| 36 |
-
)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
from huggingface_hub import HfApi
|
| 40 |
-
import requests
|
| 41 |
-
|
| 42 |
-
# توكن النموذج
|
| 43 |
-
HUGGINGFACE_TOKEN = "YOUR_TOKEN" # يجب إضافة التوكن في إعدادات Space
|
| 44 |
|
| 45 |
def summarize(text: str) -> str:
|
| 46 |
if not text:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import HfApi
|
| 3 |
import requests
|
|
|
|
| 4 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
HUGGINGFACE_TOKEN = os.environ.get("HUGGINGFACE_TOKEN")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def summarize(text: str) -> str:
|
| 9 |
if not text:
|