methodya commited on
Commit
6aee512
·
verified ·
1 Parent(s): 32c594e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ interface.launch()import gradio as gr
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:
47
+ return "يرجى إدخال نص للتلخيص"
48
+
49
+ api_url = "https://api-inference.huggingface.co/models/methodya/arabicPhiloV3"
50
+ headers = {"Authorization": f"Bearer {HUGGINGFACE_TOKEN}"}
51
+ payload = {
52
+ "inputs": f"""قم بتلخيص النص التالي:
53
+ {text}
54
+ """,
55
+ "parameters": {
56
+ "max_new_tokens": 2000,
57
+ "temperature": 0.7
58
+ }
59
+ }
60
+
61
+ try:
62
+ response = requests.post(api_url, headers=headers, json=payload)
63
+ return response.json()[0]["generated_text"]
64
+ except Exception as e:
65
+ return f"حدث خطأ: {str(e)}"
66
+
67
+ interface = gr.Interface(
68
+ fn=summarize,
69
+ inputs=gr.Textbox(label="النص الفلسفي", lines=8, text_align="right"),
70
+ outputs=gr.Textbox(label="الملخص", lines=6, text_align="right"),
71
+ title="ملخص النصوص الفلسفية",
72
+ description="أداة لتلخيص النصوص الفلسفية باللغة العربية"
73
+ )
74
+
75
+ interface.launch()