Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
-
# صفحتان ثابتتان + Submit لكل سؤال يعمل فعليًا + واجهة إدخال واسعة وثابتة الأبعاد
|
| 3 |
|
| 4 |
import os, json, uuid, random, unicodedata
|
| 5 |
from dataclasses import dataclass
|
|
@@ -82,7 +82,7 @@ def strip_headers(t:str)->str:
|
|
| 82 |
out=[]
|
| 83 |
for ln in t.splitlines():
|
| 84 |
if re2.match(r"^\s*--- \[Page \d+\] ---\s*$", ln): continue
|
| 85 |
-
if re2.match(r"^\s*(Page\s*\d+|صفحة\s
|
| 86 |
if re2.match(r"^\s*[-–—_*]{3,}\s*$", ln): continue
|
| 87 |
out.append(ln)
|
| 88 |
return "\n".join(out)
|
|
@@ -157,7 +157,7 @@ def make_mcqs(text:str, n:int=6)->List[MCQ]:
|
|
| 157 |
sent_for[kw]=s
|
| 158 |
items=[]; used=set()
|
| 159 |
for kw in [k for k in kws if k in sent_for]:
|
| 160 |
-
if len(items)
|
| 161 |
s=sent_for[kw]
|
| 162 |
if s in used: continue
|
| 163 |
q=re2.sub(rf"(?<!\p{{L}}){re2.escape(kw)}(?!\p{{L}})", "_____", s, count=1)
|
|
@@ -248,42 +248,37 @@ h2.top{color:#eaeaf2;margin:8px 0 18px}
|
|
| 248 |
display:flex; flex-direction:column; gap:14px;
|
| 249 |
}
|
| 250 |
|
| 251 |
-
/*
|
| 252 |
-
|
| 253 |
position:relative;
|
| 254 |
-
height:140px;
|
| 255 |
min-height:140px; max-height:140px;
|
| 256 |
-
overflow:hidden;
|
| 257 |
border:2px dashed #3b3f52;
|
| 258 |
background:#121318;
|
| 259 |
border-radius:12px;
|
| 260 |
padding:12px;
|
| 261 |
color:#cfd5e3;
|
| 262 |
}
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
.drop-wrap [data-testid="file"]{
|
| 266 |
-
position:absolute; inset:0;
|
| 267 |
-
height:100%; width:100%;
|
| 268 |
overflow:hidden !important;
|
| 269 |
}
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
/* إخفاء كل أشكال
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
display:none !important;
|
| 283 |
}
|
| 284 |
-
|
| 285 |
-
/* إبقاء مساحة النقر فعّالة بالكامل */
|
| 286 |
-
.drop-wrap input[type="file"]{
|
| 287 |
position:absolute; inset:0; height:100%; width:100%;
|
| 288 |
opacity:0; cursor:pointer;
|
| 289 |
}
|
|
@@ -302,7 +297,7 @@ textarea{min-height:120px}
|
|
| 302 |
.q-badge.ok{background:#083a2a;color:#b6f4db;border:1px solid #145b44}
|
| 303 |
.q-badge.err{background:#3a0d14;color:#ffd1d6;border:1px solid #6a1e2b}
|
| 304 |
|
| 305 |
-
.q-text{color
|
| 306 |
.opts{display:flex;flex-direction:column;gap:8px}
|
| 307 |
.opt{display:flex;gap:10px;align-items:center;background:#14161c;border:1px solid #2a2d3a;border-radius:12px;padding:10px;transition:background .15s,border-color .15s}
|
| 308 |
.opt input{accent-color:var(--accent2)}
|
|
@@ -375,8 +370,8 @@ with gr.Blocks(title="Question Generator", css=CSS) as demo:
|
|
| 375 |
gr.Markdown("اختر **أحد** الخيارين ثم اضغط الزر.", elem_classes=["small"])
|
| 376 |
text_area = gr.Textbox(lines=6, placeholder="ألصق نصك هنا...", label="لصق نص")
|
| 377 |
|
| 378 |
-
#
|
| 379 |
-
with gr.
|
| 380 |
file_comp = gr.File(
|
| 381 |
label=None, file_count="single",
|
| 382 |
file_types=[".pdf",".txt"], type="filepath"
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
+
# صفحتان ثابتتان + Submit لكل سؤال يعمل فعليًا + واجهة إدخال واسعة وثابتة الأبعاد (بدون gr.Box)
|
| 3 |
|
| 4 |
import os, json, uuid, random, unicodedata
|
| 5 |
from dataclasses import dataclass
|
|
|
|
| 82 |
out=[]
|
| 83 |
for ln in t.splitlines():
|
| 84 |
if re2.match(r"^\s*--- \[Page \d+\] ---\s*$", ln): continue
|
| 85 |
+
if re2.match(r"^\s*(Page\s*\d+|صفحة\s*\د+)\s*$", ln): continue
|
| 86 |
if re2.match(r"^\s*[-–—_*]{3,}\s*$", ln): continue
|
| 87 |
out.append(ln)
|
| 88 |
return "\n".join(out)
|
|
|
|
| 157 |
sent_for[kw]=s
|
| 158 |
items=[]; used=set()
|
| 159 |
for kw in [k for k in kws if k in sent_for]:
|
| 160 |
+
if len(items)>=ن: break
|
| 161 |
s=sent_for[kw]
|
| 162 |
if s in used: continue
|
| 163 |
q=re2.sub(rf"(?<!\p{{L}}){re2.escape(kw)}(?!\p{{L}})", "_____", s, count=1)
|
|
|
|
| 248 |
display:flex; flex-direction:column; gap:14px;
|
| 249 |
}
|
| 250 |
|
| 251 |
+
/* ✅ استبدال gr.Box بـ gr.Group(elem_id='drop_wrap') والتنسيق حسب الـID */
|
| 252 |
+
#drop_wrap{
|
| 253 |
position:relative;
|
| 254 |
+
height:140px;
|
| 255 |
min-height:140px; max-height:140px;
|
| 256 |
+
overflow:hidden;
|
| 257 |
border:2px dashed #3b3f52;
|
| 258 |
background:#121318;
|
| 259 |
border-radius:12px;
|
| 260 |
padding:12px;
|
| 261 |
color:#cfd5e3;
|
| 262 |
}
|
| 263 |
+
#drop_wrap [data-testid="file"]{
|
| 264 |
+
position:absolute; inset:0; height:100%; width:100%;
|
|
|
|
|
|
|
|
|
|
| 265 |
overflow:hidden !important;
|
| 266 |
}
|
| 267 |
+
#drop_wrap [data-testid="file"] *{ max-height:100% !important; }
|
| 268 |
+
|
| 269 |
+
/* إخفاء كل أشكال المعاينة/الشبكات/الأسماء الطويلة */
|
| 270 |
+
#drop_wrap [class*="preview"],
|
| 271 |
+
#drop_wrap [class*="file-preview"],
|
| 272 |
+
#drop_wrap .file-preview,
|
| 273 |
+
#drop_wrap .file-preview *,
|
| 274 |
+
#drop_wrap .upload-preview,
|
| 275 |
+
#drop_wrap .grid, #drop_wrap .grid-wrap,
|
| 276 |
+
#drop_wrap .thumbnail, #drop_wrap .thumbnails,
|
| 277 |
+
#drop_wrap .label, #drop_wrap .hidden,
|
| 278 |
+
#drop_wrap .file-name, #drop_wrap .file-info, #drop_wrap .file-size {
|
| 279 |
display:none !important;
|
| 280 |
}
|
| 281 |
+
#drop_wrap input[type="file"]{
|
|
|
|
|
|
|
| 282 |
position:absolute; inset:0; height:100%; width:100%;
|
| 283 |
opacity:0; cursor:pointer;
|
| 284 |
}
|
|
|
|
| 297 |
.q-badge.ok{background:#083a2a;color:#b6f4db;border:1px solid #145b44}
|
| 298 |
.q-badge.err{background:#3a0d14;color:#ffd1d6;border:1px solid #6a1e2b}
|
| 299 |
|
| 300 |
+
.q-text{color:#text;font-size:1.06rem;line-height:1.8;margin:8px 0 12px}
|
| 301 |
.opts{display:flex;flex-direction:column;gap:8px}
|
| 302 |
.opt{display:flex;gap:10px;align-items:center;background:#14161c;border:1px solid #2a2d3a;border-radius:12px;padding:10px;transition:background .15s,border-color .15s}
|
| 303 |
.opt input{accent-color:var(--accent2)}
|
|
|
|
| 370 |
gr.Markdown("اختر **أحد** الخيارين ثم اضغط الزر.", elem_classes=["small"])
|
| 371 |
text_area = gr.Textbox(lines=6, placeholder="ألصق نصك هنا...", label="لصق نص")
|
| 372 |
|
| 373 |
+
# ✅ استبدال gr.Box بـ gr.Group(elem_id="drop_wrap")
|
| 374 |
+
with gr.Group(elem_id="drop_wrap"):
|
| 375 |
file_comp = gr.File(
|
| 376 |
label=None, file_count="single",
|
| 377 |
file_types=[".pdf",".txt"], type="filepath"
|