Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
@@ -50,33 +50,56 @@ def updateScore(radio):
|
|
50 |
score -= 1
|
51 |
|
52 |
## gradio
|
53 |
-
|
54 |
-
def
|
55 |
global answer
|
56 |
global minPairGroup
|
57 |
global score
|
58 |
|
59 |
-
updateScore(radio)
|
60 |
setRandAnswer()
|
61 |
setMinPairGroup()
|
62 |
|
63 |
image = gr.Image(f'./assets/{answer}.jpeg', label=answer, show_label= False)
|
64 |
-
radio = gr.Radio(choices=minPairGroup, label='Which word is pictured?'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
scorebox = gr.Markdown(f"# Score: {score}")
|
66 |
-
|
|
|
67 |
|
68 |
# the interface
|
69 |
with gr.Blocks() as demo:
|
70 |
setRandAnswer()
|
71 |
setMinPairGroup()
|
72 |
|
73 |
-
|
74 |
with gr.Column():
|
75 |
scorebox = gr.Markdown(f"# Score: {score}")
|
76 |
image = gr.Image(f'./assets/{answer}.jpeg', label=answer, show_label= False)
|
77 |
radio = gr.Radio(choices=minPairGroup, label='Which word is pictured?')
|
|
|
|
|
78 |
submitButton = gr.Button("Submit")
|
79 |
-
submitButton.click(onSubmit, inputs= [image, radio, scorebox], outputs=[image, radio, scorebox])
|
80 |
-
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
demo.launch()
|
|
|
50 |
score -= 1
|
51 |
|
52 |
## gradio
|
53 |
+
|
54 |
+
def nextQuestion(image, radio, scorebox):
|
55 |
global answer
|
56 |
global minPairGroup
|
57 |
global score
|
58 |
|
|
|
59 |
setRandAnswer()
|
60 |
setMinPairGroup()
|
61 |
|
62 |
image = gr.Image(f'./assets/{answer}.jpeg', label=answer, show_label= False)
|
63 |
+
radio = gr.Radio(choices=minPairGroup, label='Which word is pictured?')
|
64 |
+
scorebox = gr.Markdown(f"# Score: {score}")
|
65 |
+
output_column = gr.Column(visible=False)
|
66 |
+
input_column = gr.Column(visible=True)
|
67 |
+
|
68 |
+
|
69 |
+
return image, radio, scorebox, output_column, input_column
|
70 |
+
|
71 |
+
# submit button function. updates everything.
|
72 |
+
def onSubmit(radio, scorebox):
|
73 |
+
global answer
|
74 |
+
global score
|
75 |
+
|
76 |
+
updateScore(radio)
|
77 |
+
input_column = gr.Column(visible=False)
|
78 |
+
output_column = gr.Column(visible=True)
|
79 |
+
results = f"{answer} is correct. Good job!" if radio==answer else f"Incorrect. The correct answer was {answer}."
|
80 |
scorebox = gr.Markdown(f"# Score: {score}")
|
81 |
+
|
82 |
+
return scorebox, output_column, results, input_column
|
83 |
|
84 |
# the interface
|
85 |
with gr.Blocks() as demo:
|
86 |
setRandAnswer()
|
87 |
setMinPairGroup()
|
88 |
|
|
|
89 |
with gr.Column():
|
90 |
scorebox = gr.Markdown(f"# Score: {score}")
|
91 |
image = gr.Image(f'./assets/{answer}.jpeg', label=answer, show_label= False)
|
92 |
radio = gr.Radio(choices=minPairGroup, label='Which word is pictured?')
|
93 |
+
|
94 |
+
with gr.Column(visible=True) as input_column:
|
95 |
submitButton = gr.Button("Submit")
|
|
|
|
|
96 |
|
97 |
+
with gr.Column(visible=False) as output_column:
|
98 |
+
results = gr.Textbox(label="Correct Answer")
|
99 |
+
nextButton = gr.Button("Next")
|
100 |
+
nextButton.click(nextQuestion, inputs= [image, radio, scorebox], outputs=[image, radio, scorebox, output_column, input_column])
|
101 |
+
|
102 |
+
|
103 |
+
submitButton.click(onSubmit, inputs= [radio, scorebox], outputs=[scorebox, output_column, results, input_column])
|
104 |
+
|
105 |
demo.launch()
|