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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -198,21 +198,25 @@ def init_state(records):
198
 
199
  def render(rec, user=None, revealed=False):
200
  q_md = f"### السؤال\n{rec['question']}"
201
- ch = [f"{o['id']}) {o['text']}" for o in rec["options"]]
202
  exp = rec["explanation"] if revealed else ""
203
- fb=""
204
  if user and revealed:
205
- fb = "✅ إجابة صحيحة" if user==correct_letter(rec) else f"❌ إجابة خاطئة — الصحيح: {correct_letter(rec)}"
206
  elif user:
207
  fb = f"تم اختيار: {user}"
208
- return q_md, ch, exp, fb
 
 
209
 
210
  def show(state):
211
- if not state: return "", [], "", "", ""
 
212
  rec = state["records"][state["idx"]]
213
- q, ch, exp, fb = render(rec, state["answers"].get(rec["id"]), rec["id"] in state["revealed"])
214
  pos = f"{state['idx']+1} / {len(state['records'])}"
215
- return q, ch, exp, fb, pos
 
216
 
217
  def choose(state, label):
218
  if not state or not label: return state, ""
@@ -273,14 +277,17 @@ def build_quiz(text_area, file_path, n, model_id, zoom):
273
  CSS = """
274
  body {direction:rtl; font-family: system-ui,'Cairo','IBM Plex Arabic',sans-serif; background: radial-gradient(1200px 500px at 50% -100px,#fff7ef,#e9d8c9);}
275
  .gradio-container {max-width: 980px; margin: 0 auto;}
276
- .card {background:#fff; border-radius:20px; padding:22px; box-shadow:0 25px 45px rgba(0,0,0,.07);}
277
- h1,h2,h3,.gr-markdown h1,.gr-markdown h2,.gr-markdown h3 {color:#6c4b34;}
 
 
278
  .button-primary > button {background: linear-gradient(180deg,#d9a978,#c98f65); border:none; color:#22150d;}
279
  .button-primary > button:hover {filter:brightness(0.95);}
280
  .soft {opacity:.8;}
281
  .upload-like {border:2px dashed #d9a97855; background:#fffaf3; border-radius:16px; padding:14px;}
282
  .progress {text-align:left; opacity:.75}
283
- .radio .wrap.svelte-1ipelgc label{border-radius:12px}
 
284
  """
285
 
286
  # ---------- واجهة Gradio ----------
 
198
 
199
  def render(rec, user=None, revealed=False):
200
  q_md = f"### السؤال\n{rec['question']}"
201
+ ch_list = [f"{o['id']}) {o['text']}" for o in rec["options"]]
202
  exp = rec["explanation"] if revealed else ""
203
+ fb = ""
204
  if user and revealed:
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
 
212
  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, ""
 
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 ----------