Rajarshi255 commited on
Commit
a4921cc
·
verified ·
1 Parent(s): 5782773

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -284,11 +284,21 @@ with gr.Blocks(title="Singerkone Quiz", theme=gr.themes.Soft()) as demo:
284
  name_in = gr.Textbox(label="Your name", placeholder="e.g. Srijan")
285
  roll_in = gr.Textbox(label="Roll number", placeholder="optional")
286
  with gr.Row():
287
- class_in = gr.Dropdown(choices=list_classes(), label="Your class")
 
 
 
 
 
288
  lang_in = gr.Radio(["English", "Bengali"], value="English", label="Quiz language")
289
 
290
  gr.Markdown("### Step 2 — Pick book & pages")
291
- book_in = gr.Dropdown(choices=[], label="Book")
 
 
 
 
 
292
  page_info = gr.Markdown("")
293
  with gr.Row():
294
  page_from_in = gr.Number(label="From page", value=1, precision=0, minimum=1)
@@ -332,6 +342,12 @@ with gr.Blocks(title="Singerkone Quiz", theme=gr.themes.Soft()) as demo:
332
  return "⚠️ Book file not found."
333
  return f"📖 This book has **{n} pages**. Pick a range up to {MAX_PAGES_PER_QUIZ} pages."
334
 
 
 
 
 
 
 
335
  class_in.change(update_books, inputs=class_in, outputs=book_in)
336
  book_in.change(update_page_info, inputs=[class_in, book_in], outputs=page_info)
337
 
 
284
  name_in = gr.Textbox(label="Your name", placeholder="e.g. Srijan")
285
  roll_in = gr.Textbox(label="Roll number", placeholder="optional")
286
  with gr.Row():
287
+ _classes = list_classes()
288
+ class_in = gr.Dropdown(
289
+ choices=_classes,
290
+ value=_classes[0] if _classes else None,
291
+ label="Your class",
292
+ )
293
  lang_in = gr.Radio(["English", "Bengali"], value="English", label="Quiz language")
294
 
295
  gr.Markdown("### Step 2 — Pick book & pages")
296
+ _initial_books = books_for_class(_classes[0]) if _classes else []
297
+ book_in = gr.Dropdown(
298
+ choices=_initial_books,
299
+ value=_initial_books[0] if _initial_books else None,
300
+ label="Book",
301
+ )
302
  page_info = gr.Markdown("")
303
  with gr.Row():
304
  page_from_in = gr.Number(label="From page", value=1, precision=0, minimum=1)
 
342
  return "⚠️ Book file not found."
343
  return f"📖 This book has **{n} pages**. Pick a range up to {MAX_PAGES_PER_QUIZ} pages."
344
 
345
+ # Also refresh books when the app first loads (in case class was auto-selected)
346
+ demo.load(
347
+ lambda: update_books(_classes[0] if _classes else None),
348
+ outputs=book_in,
349
+ )
350
+
351
  class_in.change(update_books, inputs=class_in, outputs=book_in)
352
  book_in.change(update_page_info, inputs=[class_in, book_in], outputs=page_info)
353