issamlaradji commited on
Commit
b808b3d
·
verified ·
1 Parent(s): 10b9fff

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+
4
+ # Sample content for flashcards and quizzes
5
+ flashcards = [
6
+ {"question": "What is the capital of France?", "answer": "Paris"},
7
+ {"question": "What is the largest planet in our solar system?", "answer": "Jupiter"},
8
+ {"question": "Who wrote '1984'?", "answer": "George Orwell"}
9
+ ]
10
+
11
+ quizzes = [
12
+ {"question": "What is 5 + 5?", "choices": ["5", "10", "15"], "answer": "10"},
13
+ {"question": "What is the square root of 16?", "choices": ["2", "4", "8"], "answer": "4"},
14
+ {"question": "Which country is known as the land of the rising sun?", "choices": ["China", "Japan", "India"], "answer": "Japan"}
15
+ ]
16
+
17
+ # Function to display a random flashcard
18
+ def get_flashcard():
19
+ flashcard = random.choice(flashcards)
20
+ return flashcard['question'], flashcard['answer']
21
+
22
+ # Function to generate a random quiz question
23
+ def get_quiz():
24
+ quiz = random.choice(quizzes)
25
+ return quiz['question'], quiz['choices'], quiz['answer']
26
+
27
+ # Function to check the answer for a quiz
28
+ def check_quiz_answer(selected_answer, correct_answer):
29
+ if selected_answer == correct_answer:
30
+ return "Correct!"
31
+ else:
32
+ return f"Incorrect! The right answer is: {correct_answer}"
33
+
34
+ # Gradio Interface
35
+ def create_gradio_interface():
36
+ with gr.Blocks() as demo:
37
+ with gr.Tab("Flashcards"):
38
+ gr.Markdown("## Flashcards Section")
39
+ flashcard_question, flashcard_answer = get_flashcard()
40
+ gr.Textbox(label="Flashcard Question", value=flashcard_question, interactive=False)
41
+ gr.Textbox(label="Answer", value=flashcard_answer, interactive=False)
42
+
43
+ with gr.Tab("Quizzes"):
44
+ gr.Markdown("## Quiz Section")
45
+ quiz_question, quiz_choices, correct_answer = get_quiz()
46
+ selected_answer = gr.Radio(choices=quiz_choices, label="Choose your answer")
47
+ submit_button = gr.Button("Submit Answer")
48
+ result = gr.Textbox(label="Result", interactive=False)
49
+
50
+ submit_button.click(check_quiz_answer, inputs=[selected_answer, correct_answer], outputs=result)
51
+
52
+ return demo
53
+
54
+ # Launch the Gradio interface
55
+ demo = create_gradio_interface()
56
+ demo.launch()