Leen172 commited on
Commit
e2fd94e
·
verified ·
1 Parent(s): a5d1869

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -34
app.py CHANGED
@@ -205,7 +205,7 @@ def render(rec, user=None, revealed=False):
205
  fb = "✅ إجابة صحيحة" if user == correct_letter(rec) else f"❌ إجابة خاطئة — الصحيح: {correct_letter(rec)}"
206
  elif user:
207
  fb = f"تم اختيار: {user}"
208
- # لا نضبط value حتى لا يطلب منك مطابقة نص الخيار بالضبط
209
  ch_update = gr.update(choices=ch_list, value=None, interactive=True)
210
  return q_md, ch_update, exp, fb
211
 
@@ -213,11 +213,16 @@ def show(state):
213
  if not state:
214
  return "", gr.update(choices=[], value=None), "", "", ""
215
  rec = state["records"][state["idx"]]
216
- q, ch_update, exp, fb = render(rec, state["answers"].get(rec["id"]), rec["id"] in state["revealed"])
 
 
 
 
217
  pos = f"{state['idx']+1} / {len(state['records'])}"
218
  return q, ch_update, exp, fb, pos
219
 
220
 
 
221
  def choose(state, label):
222
  if not state or not label: return state, ""
223
  rec = state["records"][state["idx"]]
@@ -275,21 +280,60 @@ def build_quiz(text_area, file_path, n, model_id, zoom):
275
 
276
  # ---------- الثيم (CSS مطابق للصورة تقريبًا) ----------
277
  CSS = """
278
- body {direction:rtl; font-family: system-ui,'Cairo','IBM Plex Arabic',sans-serif; background: radial-gradient(1200px 500px at 50% -100px,#fff7ef,#e9d8c9);}
279
- .gradio-container {max-width: 980px; margin: 0 auto;}
280
- .card {background:#fff; border-radius:20px; padding:22px; box-shadow:0 25px 45px rgba(0,0,0,.07); color:#2b211a;}
281
- .card * {color:#2b211a !important;}
282
- .card h1,.card h2,.card h3 {margin-top:0; color:#2b211a !important;}
283
- .card p {font-size:1.05rem; line-height:1.8; word-wrap:break-word; overflow-wrap:anywhere;}
284
- .button-primary > button {background: linear-gradient(180deg,#d9a978,#c98f65); border:none; color:#22150d;}
285
- .button-primary > button:hover {filter:brightness(0.95);}
286
- .soft {opacity:.8;}
287
- .upload-like {border:2px dashed #d9a97855; background:#fffaf3; border-radius:16px; padding:14px;}
288
- .progress {text-align:left; opacity:.75}
289
- .radio .wrap label {text-align:right; justify-content:flex-end;}
290
- .radio .wrap label span {font-size:1.02rem;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  """
292
 
 
293
  # ---------- واجهة Gradio ----------
294
  with gr.Blocks(title="Question Generator", css=CSS) as demo:
295
  gr.Markdown("<h2 style='text-align:center;margin-top:8px;'>Question Generator</h2>", elem_classes=["soft"])
@@ -320,25 +364,25 @@ with gr.Blocks(title="Question Generator", css=CSS) as demo:
320
  toast = gr.Markdown("", elem_classes=["soft"])
321
  input_card = gr.Markdown("", visible=False) # placeholder
322
 
323
- # القسم B: الاختبار
324
- quiz_group = gr.Group(visible=False)
325
- with quiz_group:
326
- with gr.Row():
327
- progress = gr.Label("", elem_classes=["progress"])
328
- with gr.Row():
329
- with gr.Column():
330
- q_md = gr.Markdown("", elem_classes=["card"])
331
- choices = gr.Radio(choices=[], label="اختر الإجابة", interactive=True, elem_classes=["radio"])
332
- feedback = gr.Markdown("")
333
- exp_md = gr.Markdown("")
334
- with gr.Row():
335
- btn_prev = gr.Button("السابق")
336
- btn_next = gr.Button("التالي")
337
- btn_reveal = gr.Button("إظهار الإجابة")
338
- btn_finish = gr.Button("إنهاء الاختبار", elem_classes=["button-primary"])
339
- btn_reset = gr.Button("العودة للواجهة", variant="secondary")
340
-
341
- state = gr.State(None)
342
 
343
  # بناء الاختبار من الإدخال
344
  btn_build.click(
 
205
  fb = "✅ إجابة صحيحة" if user == correct_letter(rec) else f"❌ إجابة خاطئة — الصحيح: {correct_letter(rec)}"
206
  elif user:
207
  fb = f"تم اختيار: {user}"
208
+ # مهم: تحديث الـRadio بشكل صريح
209
  ch_update = gr.update(choices=ch_list, value=None, interactive=True)
210
  return q_md, ch_update, exp, fb
211
 
 
213
  if not state:
214
  return "", gr.update(choices=[], value=None), "", "", ""
215
  rec = state["records"][state["idx"]]
216
+ q, ch_update, exp, fb = render(
217
+ rec,
218
+ state["answers"].get(rec["id"]),
219
+ rec["id"] in state["revealed"]
220
+ )
221
  pos = f"{state['idx']+1} / {len(state['records'])}"
222
  return q, ch_update, exp, fb, pos
223
 
224
 
225
+
226
  def choose(state, label):
227
  if not state or not label: return state, ""
228
  rec = state["records"][state["idx"]]
 
280
 
281
  # ---------- الثيم (CSS مطابق للصورة تقريبًا) ----------
282
  CSS = """
283
+ /* خلفية داكنة ولمسة دافئة */
284
+ body {
285
+ direction: rtl;
286
+ font-family: system-ui,'Cairo','IBM Plex Arabic',sans-serif;
287
+ background:#0f0f0f;
288
+ }
289
+
290
+ /* عرض مناسب */
291
+ .gradio-container { max-width: 980px; margin: 0 auto; }
292
+
293
+ /* كارت رئيسي داكن ونص فاتح واضح */
294
+ .card {
295
+ background:#1b1b1b;
296
+ border-radius:20px;
297
+ padding:24px;
298
+ box-shadow:0 25px 45px rgba(0,0,0,.5);
299
+ color:#f5efe6;
300
+ }
301
+ .card * { color:#f5efe6 !important; }
302
+ .card h1,.card h2,.card h3 { margin-top:0; }
303
+
304
+ /* نص السؤال أكبر وتباعد مريح */
305
+ .card p { font-size:1.12rem; line-height:1.9; word-wrap:break-word; overflow-wrap:anywhere; }
306
+
307
+ /* زر أساسي بلون برتقالي دافئ */
308
+ .button-primary > button {
309
+ background: linear-gradient(180deg,#ff9a55,#ff7d2d);
310
+ border:none; color:#1b1b1b; font-weight:700;
311
+ }
312
+ .button-primary > button:hover { filter:brightness(0.95); }
313
+
314
+ /* صندوق الرفع */
315
+ .upload-like {
316
+ border:2px dashed #ff9a5555; background:#161616;
317
+ border-radius:16px; padding:14px; color:#ddd;
318
+ }
319
+
320
+ /* سلايدر وأزرار داكنة متناسقة */
321
+ input[type="range"]::-webkit-slider-thumb { background:#ff7d2d; }
322
+ .gr-button { background:#2a2a2a; color:#eaeaea; border:none; }
323
+ .gr-button:hover { filter:brightness(1.08); }
324
+
325
+ /* خيارات الراديو */
326
+ .radio .wrap label { text-align:right; justify-content:flex-end; }
327
+ .radio .wrap label span { font-size:1.05rem; }
328
+
329
+ /* شريط التقدم */
330
+ .progress { text-align:left; opacity:.85; color:#cfcfcf; }
331
+
332
+ /* عنوان أعلى الصفحة */
333
+ .top-title { color:#e9ded6; }
334
  """
335
 
336
+
337
  # ---------- واجهة Gradio ----------
338
  with gr.Blocks(title="Question Generator", css=CSS) as demo:
339
  gr.Markdown("<h2 style='text-align:center;margin-top:8px;'>Question Generator</h2>", elem_classes=["soft"])
 
364
  toast = gr.Markdown("", elem_classes=["soft"])
365
  input_card = gr.Markdown("", visible=False) # placeholder
366
 
367
+ # القسم B: الاختبار
368
+ quiz_group = gr.Group(visible=False)
369
+ with quiz_group:
370
+ with gr.Row():
371
+ progress = gr.Label("", elem_classes=["progress"])
372
+ with gr.Row():
373
+ with gr.Column():
374
+ # ---------- مكونات عرض السؤال ----------
375
+ q_md = gr.Markdown("", elem_classes=["card"])
376
+ choices = gr.Radio(choices=[], label="اختر الإجابة", interactive=True, elem_classes=["radio"])
377
+ feedback = gr.Markdown("")
378
+ exp_md = gr.Markdown("")
379
+
380
+ with gr.Row():
381
+ btn_prev = gr.Button("السابق")
382
+ btn_next = gr.Button("التالي")
383
+ btn_reveal = gr.Button("إظهار الإجابة")
384
+ btn_finish = gr.Button("إنهاء الاختبار", elem_classes=["button-primary"])
385
+ btn_reset = gr.Button("العودة للواجهة", variant="secondary")
386
 
387
  # بناء الاختبار من الإدخال
388
  btn_build.click(