Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,211 +8,37 @@ tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
8 |
|
9 |
# دالة التلخيص مع المعاملات الجديدة
|
10 |
def summarize(text, max_length=150, num_beams=7, length_penalty=0.8):
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
# إعداد واجهة Gradio مع
|
28 |
interface = gr.Interface(
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
max-width: 768px;
|
43 |
-
}
|
44 |
-
|
45 |
-
h1 {
|
46 |
-
font-size: 1.875rem;
|
47 |
-
font-weight: bold;
|
48 |
-
text-align: center;
|
49 |
-
margin-bottom: 1.5rem;
|
50 |
-
}
|
51 |
-
|
52 |
-
button {
|
53 |
-
background-color: #4f46e5;
|
54 |
-
color: #ffffff;
|
55 |
-
padding: 0.75rem 1rem;
|
56 |
-
border: none;
|
57 |
-
border-radius: 8px;
|
58 |
-
cursor: pointer;
|
59 |
-
transition: background-color 0.3s ease;
|
60 |
-
font-weight: bold;
|
61 |
-
}
|
62 |
-
|
63 |
-
button:hover {
|
64 |
-
background-color: #4338ca;
|
65 |
-
}
|
66 |
-
|
67 |
-
button:disabled {
|
68 |
-
background-color: #a5b4fc;
|
69 |
-
cursor: not-allowed;
|
70 |
-
}
|
71 |
-
|
72 |
-
textarea,
|
73 |
-
input[type="range"] {
|
74 |
-
width: 100%;
|
75 |
-
padding: 0.75rem;
|
76 |
-
border: 1px solid #d1d5db;
|
77 |
-
border-radius: 6px;
|
78 |
-
margin-top: 0.5rem;
|
79 |
-
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
80 |
-
transition: border-color 0.3s ease, box-shadow 0.3s ease;
|
81 |
-
}
|
82 |
-
|
83 |
-
textarea:focus,
|
84 |
-
input[type="range"]:focus {
|
85 |
-
outline: none;
|
86 |
-
border-color: #6366f1;
|
87 |
-
box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
|
88 |
-
}
|
89 |
-
|
90 |
-
.bg-gray-50 {
|
91 |
-
background-color: #f9fafb;
|
92 |
-
border-radius: 8px;
|
93 |
-
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
94 |
-
}
|
95 |
-
|
96 |
-
label {
|
97 |
-
font-weight: bold;
|
98 |
-
color: #333333;
|
99 |
-
}
|
100 |
-
|
101 |
-
span.text-sm {
|
102 |
-
font-size: 0.875rem;
|
103 |
-
color: #6b7280;
|
104 |
-
}
|
105 |
-
|
106 |
-
.border {
|
107 |
-
border: 1px solid #e5e7eb;
|
108 |
-
border-radius: 8px;
|
109 |
-
background-color: #ffffff;
|
110 |
-
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
111 |
-
}
|
112 |
-
|
113 |
-
h2 {
|
114 |
-
font-size: 1.25rem;
|
115 |
-
font-weight: bold;
|
116 |
-
color: #333333;
|
117 |
-
}
|
118 |
-
|
119 |
-
p.leading-relaxed {
|
120 |
-
line-height: 1.75;
|
121 |
-
color: #4b5563;
|
122 |
-
}
|
123 |
-
|
124 |
-
/* معالجة المناطق السوداء والراوندس */
|
125 |
-
.gradio-container {
|
126 |
-
background: #f9fafb !important;
|
127 |
-
color: #333333 !important;
|
128 |
-
}
|
129 |
-
|
130 |
-
.dark {
|
131 |
-
background: #f9fafb !important;
|
132 |
-
color: #333333 !important;
|
133 |
-
}
|
134 |
-
|
135 |
-
.gr-box {
|
136 |
-
background: #ffffff !important;
|
137 |
-
border-radius: 12px !important;
|
138 |
-
}
|
139 |
-
|
140 |
-
.gr-form, .gr-panel {
|
141 |
-
background: #ffffff !important;
|
142 |
-
border-radius: 12px !important;
|
143 |
-
}
|
144 |
-
|
145 |
-
.gr-input-label {
|
146 |
-
color: #333333 !important;
|
147 |
-
}
|
148 |
-
|
149 |
-
/* تنسيق النص في السلايدر */
|
150 |
-
span.svelte-1gfkn6j {
|
151 |
-
color: #5046e5 !important;
|
152 |
-
text-align: center !important;
|
153 |
-
display: block !important;
|
154 |
-
}
|
155 |
-
|
156 |
-
/* معالجة صندوق السلايدر */
|
157 |
-
div.svelte-633qhp {
|
158 |
-
border-radius: 12px !important;
|
159 |
-
background: transparent !important;
|
160 |
-
border: 1px solid #e5e7eb !important;
|
161 |
-
box-shadow: none !important;
|
162 |
-
}
|
163 |
-
|
164 |
-
/* لون السلايدر */
|
165 |
-
input[type="range"] {
|
166 |
-
accent-color: #5046e5 !important;
|
167 |
-
}
|
168 |
-
|
169 |
-
/* مربع القيم */
|
170 |
-
input[type="number"].svelte-10lj3xl.svelte-10lj3xl {
|
171 |
-
background: #28ae66 !important;
|
172 |
-
color: white !important;
|
173 |
-
font-weight: bold !important;
|
174 |
-
font-size: 1.1em !important;
|
175 |
-
border-radius: 8px !important;
|
176 |
-
border: none !important;
|
177 |
-
padding: 4px 8px !important;
|
178 |
-
}
|
179 |
-
|
180 |
-
/* تصحيح خلفية البلوكات */
|
181 |
-
.block.svelte-11xb1hd.padded, .block.svelte-11xb1hd {
|
182 |
-
background: #ffffff !important;
|
183 |
-
}
|
184 |
-
.wrap.svelte-1rjydqp {
|
185 |
-
background: #ffffff !important;
|
186 |
-
}
|
187 |
-
|
188 |
-
/* تصحيح لون وشكل مربع النص */
|
189 |
-
label.container.show_textbox_border.svelte-173056l input.svelte-173056l,
|
190 |
-
label.container.show_textbox_border.svelte-173056l textarea.svelte-173056l {
|
191 |
-
background-color: #f8f9fa !important;
|
192 |
-
border: 1px solid #e9ecef !important;
|
193 |
-
border-radius: 12px !important;
|
194 |
-
}
|
195 |
-
|
196 |
-
/* تصحيح لون النص في العنوان */
|
197 |
-
.gradio-container-5-9-0 .prose h1,
|
198 |
-
.gradio-container-5-9-0 .prose h2,
|
199 |
-
.gradio-container-5-9-0 .prose h3,
|
200 |
-
.gradio-container-5-9-0 .prose h4,
|
201 |
-
.gradio-container-5-9-0 .prose h5 {
|
202 |
-
color: #000000 !important;
|
203 |
-
font-weight: bold !important;
|
204 |
-
}
|
205 |
-
""",
|
206 |
-
inputs=[
|
207 |
-
gr.Textbox(lines=8, label="النص"),
|
208 |
-
gr.Slider(50, 250, value=150, label="طول الملخص"),
|
209 |
-
gr.Slider(1, 10, value=7, step=1, label="دقة التلخيص (num_beams)"),
|
210 |
-
gr.Slider(0.1, 2.0, value=0.8, step=0.1, label="معامل الطول (length_penalty)")
|
211 |
-
],
|
212 |
-
outputs=gr.Textbox(label="الملخص"),
|
213 |
-
title="ملخص النصوص الفلسفية",
|
214 |
-
submit_btn="تلخيص",
|
215 |
-
clear_btn="مسح"
|
216 |
)
|
217 |
|
218 |
# تشغيل التطبيق
|
|
|
8 |
|
9 |
# دالة التلخيص مع المعاملات الجديدة
|
10 |
def summarize(text, max_length=150, num_beams=7, length_penalty=0.8):
|
11 |
+
# تحويل القيم إلى النوع المناسب
|
12 |
+
max_length = int(max_length)
|
13 |
+
num_beams = int(num_beams)
|
14 |
+
length_penalty = float(length_penalty)
|
15 |
+
|
16 |
+
# تجهيز البيانات للنموذج
|
17 |
+
inputs = tokenizer(text, return_tensors="pt", max_length=2048, truncation=True)
|
18 |
+
outputs = model.generate(
|
19 |
+
**inputs,
|
20 |
+
max_length=max_length,
|
21 |
+
num_beams=num_beams,
|
22 |
+
length_penalty=length_penalty,
|
23 |
+
early_stopping=True
|
24 |
+
)
|
25 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
26 |
+
|
27 |
+
# إعداد واجهة Gradio مع ربط الستايل الخارجي
|
28 |
interface = gr.Interface(
|
29 |
+
fn=summarize,
|
30 |
+
inputs=[
|
31 |
+
gr.Textbox(lines=8, label="النص"), # النص الأصلي
|
32 |
+
gr.Slider(50, 250, value=150, label="طول الملخص"), # max_length
|
33 |
+
gr.Slider(1, 10, value=7, step=1, label="دقة التلخيص (num_beams)"), # num_beams
|
34 |
+
gr.Slider(0.1, 2.0, value=0.8, step=0.1, label="معامل الطول (length_penalty)") # length_penalty
|
35 |
+
],
|
36 |
+
outputs=gr.Textbox(label="الملخص"), # النص الملخص
|
37 |
+
title="ملخص النصوص الفلسفية",
|
38 |
+
description="نموذج لتلخيص النصوص الفلسفية باللغة العربية مع إعدادات متقدمة",
|
39 |
+
css="style.css", # ربط ملف الستايل الخارجي
|
40 |
+
submit_btn="تلخيص", # تغيير زر Submit
|
41 |
+
clear_btn="مسح" # تغيير زر Clear
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
)
|
43 |
|
44 |
# تشغيل التطبيق
|