File size: 2,333 Bytes
b808b3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83e006e
b808b3d
83e006e
 
 
 
 
 
b808b3d
 
 
 
 
83e006e
b808b3d
 
 
 
 
 
83e006e
 
 
b808b3d
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import gradio as gr
import random

# Sample content for flashcards and quizzes
flashcards = [
    {"question": "What is the capital of France?", "answer": "Paris"},
    {"question": "What is the largest planet in our solar system?", "answer": "Jupiter"},
    {"question": "Who wrote '1984'?", "answer": "George Orwell"}
]

quizzes = [
    {"question": "What is 5 + 5?", "choices": ["5", "10", "15"], "answer": "10"},
    {"question": "What is the square root of 16?", "choices": ["2", "4", "8"], "answer": "4"},
    {"question": "Which country is known as the land of the rising sun?", "choices": ["China", "Japan", "India"], "answer": "Japan"}
]

# Function to display a random flashcard
def get_flashcard():
    flashcard = random.choice(flashcards)
    return flashcard['question'], flashcard['answer']

# Function to generate a random quiz question
def get_quiz():
    quiz = random.choice(quizzes)
    return quiz['question'], quiz['choices'], quiz['answer']

# Function to check the answer for a quiz
def check_quiz_answer(selected_answer, correct_answer):
    if selected_answer == correct_answer:
        return "Correct!"
    else:
        return f"Incorrect! The right answer is: {correct_answer}"

# Gradio Interface using gr.Interface for Gradio 5.20.1
def create_gradio_interface():
    flashcard_question, flashcard_answer = get_flashcard()
    quiz_question, quiz_choices, correct_answer = get_quiz()

    def quiz_interface(selected_answer):
        return check_quiz_answer(selected_answer, correct_answer)

    with gr.Blocks() as demo:
        with gr.Tab("Flashcards"):
            gr.Markdown("## Flashcards Section")
            gr.Textbox(label="Flashcard Question", value=flashcard_question, interactive=False)
            gr.Textbox(label="Answer", value=flashcard_answer, interactive=False)

        with gr.Tab("Quizzes"):
            gr.Markdown("## Quiz Section")
            selected_answer = gr.Radio(choices=quiz_choices, label="Choose your answer")
            submit_button = gr.Button("Submit Answer")
            result = gr.Textbox(label="Result", interactive=False)

            # Use the Interface for the quiz
            submit_button.click(quiz_interface, inputs=selected_answer, outputs=result)

    return demo

# Launch the Gradio interface
demo = create_gradio_interface()
demo.launch()