-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathflash.py
More file actions
164 lines (143 loc) · 4.38 KB
/
flash.py
File metadata and controls
164 lines (143 loc) · 4.38 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import gradio as gr
# Sample flashcards
flashcards = [
{"question": "What is the capital of France?", "answer": "Paris"},
]
# HTML template with CSS animation
def get_flashcard_html(index=0):
card = flashcards[index % len(flashcards)]
html = f"""
<style>
.flashcard-container {{
perspective: 1000px;
width: 300px;
height: 200px;
margin: auto;
cursor: pointer;
}}
.flashcard {{
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}}
.flashcard.is-flipped {{
transform: rotateY(180deg);
}}
.flashcard-face {{
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.3em;
border-radius: 12px;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
background: #000ff;
}}
.flashcard-front {{
background-color: #585D59FF;
}}
.flashcard-back {{
background-color: #4caf50;
color: white;
transform: rotateY(180deg);
}}
</style>
<div class="flashcard-container" onclick="this.querySelector('.flashcard').classList.toggle('is-flipped')">
<div class="flashcard">
<div class="flashcard-face flashcard-front">{card['question']}</div>
<div class="flashcard-face flashcard-back">{card['answer']}</div>
</div>
</div>
"""
return html
def next_card(current_index):
current_index = (current_index + 1) % len(flashcards)
return get_flashcard_html(current_index), current_index
with gr.Blocks() as demo:
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### 🧠 Animated Flashcards")
html_card = gr.HTML(get_flashcard_html(0))
index_state = gr.State(0)
next_btn = gr.Button("Next ➡️")
next_btn.click(fn=next_card, inputs=index_state, outputs=[html_card, index_state])
demo.launch()
import gradio as gr
# Sample flashcards
flashcards = [
{"question": "What is the capital of France?", "answer": "Paris"},
{"question": "Who developed Python?", "answer": "Guido van Rossum"},
{"question": "What is 5 + 7?", "answer": "12"},
{"question": "What year did AI boom begin?", "answer": "Around 2012"},
]
# HTML template with CSS animation
def get_flashcard_html(index=0):
card = flashcards[index % len(flashcards)]
html = f"""
<style>
.flashcard-container {{
perspective: 1000px;
width: 300px;
height: 200px;
margin: auto;
cursor: pointer;
}}
.flashcard {{
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}}
.flashcard.is-flipped {{
transform: rotateY(180deg);
}}
.flashcard-face {{
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.3em;
border-radius: 12px;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
background: #000ff;
}}
.flashcard-front {{
background-color: #585D59FF;
}}
.flashcard-back {{
background-color: #4caf50;
color: white;
transform: rotateY(180deg);
}}
</style>
<div class="flashcard-container" onclick="this.querySelector('.flashcard').classList.toggle('is-flipped')">
<div class="flashcard">
<div class="flashcard-face flashcard-front">{card['question']}</div>
<div class="flashcard-face flashcard-back">{card['answer']}</div>
</div>
</div>
"""
return html
def next_card(current_index):
current_index = (current_index + 1) % len(flashcards)
return get_flashcard_html(current_index), current_index
with gr.Blocks() as demo:
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### 🧠 Animated Flashcards")
html_card = gr.HTML(get_flashcard_html(0))
index_state = gr.State(0)
next_btn = gr.Button("Next ➡️")
next_btn.click(fn=next_card, inputs=index_state, outputs=[html_card, index_state])
demo.launch()