Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit d6fd78c

Browse files
[feat] add radio button tutorial with programming language quiz
1 parent 9207d3a commit d6fd78c

File tree

1 file changed

+29
-0
lines changed
  • 7_how_to_create_a_radio_button

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
app.py
3+
4+
This file contains a simple Gradio application that demonstrates how to create a radio button for user input.
5+
"""
6+
7+
import gradio as gr
8+
9+
# This code creates a simple Gradio application with a radio button for selecting a programming language.
10+
def check_answer(selected_language):
11+
correct_answer = "Python"
12+
if selected_language == correct_answer:
13+
return "Correct! Python is known for its simplicity and readability."
14+
else:
15+
return f"Incorrect. The correct answer is {correct_answer}."
16+
17+
# Create a Gradio interface for a radio button question
18+
interface = gr.Interface(
19+
fn=check_answer,
20+
inputs=gr.Radio(
21+
choices=["Python", "JavaScript", "Java"],
22+
label="Which programming language is known for its simplicity and readability?"
23+
),
24+
outputs=gr.Textbox("Your result:"),
25+
)
26+
27+
if __name__ == "__main__":
28+
# Launch the Gradio interface
29+
interface.launch()

0 commit comments

Comments
 (0)