burtenshaw commited on
Commit
9951d91
·
1 Parent(s): ea362a2

make image functionality optional

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -17,7 +17,7 @@ EXAM_MAX_QUESTIONS = int(
17
  os.getenv("EXAM_MAX_QUESTIONS", 5)
18
  ) # Limit quiz to max questions
19
  EXAM_PASSING_SCORE = float(os.getenv("EXAM_PASSING_SCORE", 0.8))
20
- EXAM_DATASET_ID = "burtenshaw/dummy-code-quiz"
21
 
22
  # prep the dataset for the quiz
23
  ds = load_dataset(EXAM_DATASET_ID, split="train", download_mode="force_redownload")
@@ -26,6 +26,9 @@ quiz_data = list(ds) # Convert dataset to list instead of using to_list()
26
  if EXAM_MAX_QUESTIONS:
27
  quiz_data = quiz_data[:EXAM_MAX_QUESTIONS]
28
 
 
 
 
29
 
30
  def format_python_code(code: str) -> str:
31
  """Format Python code using black."""
@@ -268,6 +271,13 @@ def handle_quiz(question_idx, user_answers, submitted_code, is_start):
268
  # Show the next question
269
  q = quiz_data[question_idx]
270
  challenge_text = f"## Question {question_idx + 1} \n### {q['challenge']}"
 
 
 
 
 
 
 
271
  return (
272
  challenge_text, # question_text
273
  gr.update(value=q["placeholder"], visible=True), # code_input
@@ -278,9 +288,7 @@ def handle_quiz(question_idx, user_answers, submitted_code, is_start):
278
  gr.update(visible=True), # next_btn visible
279
  gr.update(visible=False), # submit_btn hidden
280
  gr.update(visible=False), # final_markdown hidden
281
- gr.update(
282
- value=q["image"], visible=True if q["image"] else False
283
- ), # question_image with current question image
284
  )
285
 
286
 
@@ -302,10 +310,14 @@ with gr.Blocks() as demo:
302
  with gr.Column():
303
  question_text = gr.Markdown("")
304
  question_image = gr.Image(
305
- label="Question Image", visible=True, type="pil"
 
 
306
  ) # Add image component
307
  with gr.Column():
308
- code_input = gr.Code(language="python", label="Your Solution", visible=False)
 
 
309
 
310
  with gr.Row(variant="compact"):
311
  status_text = gr.Markdown("")
 
17
  os.getenv("EXAM_MAX_QUESTIONS", 5)
18
  ) # Limit quiz to max questions
19
  EXAM_PASSING_SCORE = float(os.getenv("EXAM_PASSING_SCORE", 0.8))
20
+ EXAM_DATASET_ID = "agents-course/smolagents-quiz-data"
21
 
22
  # prep the dataset for the quiz
23
  ds = load_dataset(EXAM_DATASET_ID, split="train", download_mode="force_redownload")
 
26
  if EXAM_MAX_QUESTIONS:
27
  quiz_data = quiz_data[:EXAM_MAX_QUESTIONS]
28
 
29
+ # Check if dataset has image feature
30
+ HAS_IMAGE_FEATURE = "image" in ds.features
31
+
32
 
33
  def format_python_code(code: str) -> str:
34
  """Format Python code using black."""
 
271
  # Show the next question
272
  q = quiz_data[question_idx]
273
  challenge_text = f"## Question {question_idx + 1} \n### {q['challenge']}"
274
+
275
+ # Only show image if the feature exists and the question has an image
276
+ show_image = HAS_IMAGE_FEATURE and q.get("image") is not None
277
+ image_update = gr.update(
278
+ value=q.get("image") if show_image else None, visible=show_image
279
+ )
280
+
281
  return (
282
  challenge_text, # question_text
283
  gr.update(value=q["placeholder"], visible=True), # code_input
 
288
  gr.update(visible=True), # next_btn visible
289
  gr.update(visible=False), # submit_btn hidden
290
  gr.update(visible=False), # final_markdown hidden
291
+ image_update, # question_image with current question image
 
 
292
  )
293
 
294
 
 
310
  with gr.Column():
311
  question_text = gr.Markdown("")
312
  question_image = gr.Image(
313
+ label="Question Image",
314
+ visible=True if HAS_IMAGE_FEATURE else False,
315
+ type="pil",
316
  ) # Add image component
317
  with gr.Column():
318
+ code_input = gr.Code(
319
+ language="python", label="Your Solution", visible=False
320
+ )
321
 
322
  with gr.Row(variant="compact"):
323
  status_text = gr.Markdown("")