keerthuAi commited on
Commit
5bbe733
·
verified ·
1 Parent(s): ece9f19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -16
app.py CHANGED
@@ -1,21 +1,58 @@
1
  import gradio as gr
 
2
 
3
- def level_response(choice):
4
- if choice == "Basic":
5
- return "You chose Basic level. Let's start with the fundamentals!"
6
- elif choice == "Intermediate":
7
- return "You chose Intermediate level. Time to go deeper!"
8
- elif choice == "Advanced":
9
- return "You chose Advanced level. You're ready for expert challenges!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  else:
11
- return "Please select a valid option."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- with gr.Blocks() as demo:
14
- gr.Markdown("## Choose Your Learning Level")
15
- level = gr.Radio(choices=["Basic", "Intermediate", "Advanced"], label="Select your level")
16
- output = gr.Textbox(label="Response")
17
- submit_btn = gr.Button("Submit")
18
-
19
- submit_btn.click(fn=level_response, inputs=level, outputs=output)
20
 
21
- demo.launch()
 
1
  import gradio as gr
2
+ import random
3
 
4
+ # Sample Python code questions
5
+ questions = [
6
+ {
7
+ "code": 'print("Hello" + "World")',
8
+ "options": ["HelloWorld", "Hello World", "Hello+World"],
9
+ "answer": "HelloWorld"
10
+ },
11
+ {
12
+ "code": 'print(2 * 3)',
13
+ "options": ["6", "23", "5"],
14
+ "answer": "6"
15
+ },
16
+ {
17
+ "code": 'x = 5\nprint(x + 2)',
18
+ "options": ["7", "52", "2"],
19
+ "answer": "7"
20
+ }
21
+ ]
22
+
23
+ score = 0
24
+ current_q = random.choice(questions)
25
+
26
+ def get_question():
27
+ global current_q
28
+ current_q = random.choice(questions)
29
+ return current_q["code"], current_q["options"]
30
+
31
+ def check_answer(choice):
32
+ global score
33
+ if choice == current_q["answer"]:
34
+ score += 1
35
+ return f"✅ Correct! 🎉 Your Score: {score}"
36
  else:
37
+ return f" Oops! Try again. Correct answer was: {current_q['answer']}"
38
+
39
+ # Gradio UI
40
+ with gr.Blocks(theme=gr.themes.Soft()) as quiz:
41
+ gr.Markdown("## 🧠 Python Quiz Game for Kids 🎮")
42
+ code_display = gr.Textbox(label="👇 What will this Python code print?", lines=2, interactive=False)
43
+ options = gr.Radio(choices=[], label="Choose your answer")
44
+ result = gr.Textbox(label="Your Result")
45
+ btn_check = gr.Button("Check Answer")
46
+ btn_next = gr.Button("Next Question")
47
+
48
+ def show_question():
49
+ code, opts = get_question()
50
+ return code, gr.update(choices=opts)
51
+
52
+ btn_check.click(fn=check_answer, inputs=options, outputs=result)
53
+ btn_next.click(fn=show_question, outputs=[code_display, options])
54
 
55
+ # Load the first question on launch
56
+ quiz.load(show_question, outputs=[code_display, options])
 
 
 
 
 
57
 
58
+ quiz.launch()