Spaces:
Running
Running
johnpaulbin
commited on
Commit
•
dcb4152
1
Parent(s):
d5977e3
Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,6 @@ def flashcard_ui(week, index):
|
|
17 |
if error:
|
18 |
return f"Error: {error}", None
|
19 |
question = data[index]["question"]
|
20 |
-
answer = data[index]["answer"]
|
21 |
total = len(data)
|
22 |
return f"Question {index + 1}/{total}: {question}", ""
|
23 |
|
@@ -39,7 +38,7 @@ def change_question(week, index, direction):
|
|
39 |
# Gradio interface
|
40 |
with gr.Blocks() as demo:
|
41 |
week = gr.Number(label="Enter CAM Week to Study", value=1)
|
42 |
-
index = gr.
|
43 |
question_output = gr.Textbox(label="Flashcard", interactive=False)
|
44 |
answer_output = gr.Textbox(label="Answer", interactive=False)
|
45 |
|
@@ -51,8 +50,8 @@ with gr.Blocks() as demo:
|
|
51 |
# Event handling
|
52 |
week.change(flashcard_ui, inputs=[week, index], outputs=[question_output, answer_output])
|
53 |
reveal_btn.click(reveal_answer, inputs=[week, index], outputs=answer_output)
|
54 |
-
prev_btn.click(change_question, inputs=[week, index, gr.Number(-1)], outputs=[index, question_output, answer_output])
|
55 |
-
next_btn.click(change_question, inputs=[week, index, gr.Number(1)], outputs=[index, question_output, answer_output])
|
56 |
|
57 |
# Launch the app
|
58 |
demo.launch()
|
|
|
17 |
if error:
|
18 |
return f"Error: {error}", None
|
19 |
question = data[index]["question"]
|
|
|
20 |
total = len(data)
|
21 |
return f"Question {index + 1}/{total}: {question}", ""
|
22 |
|
|
|
38 |
# Gradio interface
|
39 |
with gr.Blocks() as demo:
|
40 |
week = gr.Number(label="Enter CAM Week to Study", value=1)
|
41 |
+
index = gr.State(0) # State to keep track of the current index
|
42 |
question_output = gr.Textbox(label="Flashcard", interactive=False)
|
43 |
answer_output = gr.Textbox(label="Answer", interactive=False)
|
44 |
|
|
|
50 |
# Event handling
|
51 |
week.change(flashcard_ui, inputs=[week, index], outputs=[question_output, answer_output])
|
52 |
reveal_btn.click(reveal_answer, inputs=[week, index], outputs=answer_output)
|
53 |
+
prev_btn.click(change_question, inputs=[week, index, gr.Number(-1, visible=False)], outputs=[index, question_output, answer_output])
|
54 |
+
next_btn.click(change_question, inputs=[week, index, gr.Number(1, visible=False)], outputs=[index, question_output, answer_output])
|
55 |
|
56 |
# Launch the app
|
57 |
demo.launch()
|