Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
import gradio as gr
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
# ์์ธ ์ด๋ฏธ์ง๋ฅผ ์ ์ฅํ ๋ฆฌ์คํธ
|
6 |
+
shuffled_images = []
|
7 |
+
original_images = []
|
8 |
+
|
9 |
+
# ์ด๋ฏธ์ง ์
๋ก๋ ๋ฐ ์๊ธฐ ํจ์
|
10 |
+
def upload_and_shuffle(image1, image2, image3, image4):
|
11 |
+
global shuffled_images, original_images
|
12 |
+
images = [image1, image2, image3, image4]
|
13 |
+
original_images = images.copy()
|
14 |
+
random.shuffle(images)
|
15 |
+
shuffled_images = images
|
16 |
+
return images
|
17 |
+
|
18 |
+
# ์์ ํ์ธ ํจ์
|
19 |
+
def check_order(slot1, slot2, slot3, slot4):
|
20 |
+
user_order = [slot1 - 1, slot2 - 1, slot3 - 1, slot4 - 1] # Adjust for 1-based index
|
21 |
+
correct_order = [shuffled_images.index(img) for img in original_images] # Correct order based on original images
|
22 |
+
correct = user_order == correct_order
|
23 |
+
return (
|
24 |
+
"์ ๋ต์
๋๋ค!" if correct else "ํ๋ ธ์ต๋๋ค. ์ฌ๋ฐ๋ฅธ ์์๋:",
|
25 |
+
original_images[0], original_images[1],
|
26 |
+
original_images[2], original_images[3]
|
27 |
+
)
|
28 |
+
|
29 |
+
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
30 |
+
def create_interface():
|
31 |
+
with gr.Blocks() as demo:
|
32 |
+
with gr.Row():
|
33 |
+
image1 = gr.Image(label="์ด๋ฏธ์ง 1 ์
๋ก๋", type="pil", width=150, height=150)
|
34 |
+
image2 = gr.Image(label="์ด๋ฏธ์ง 2 ์
๋ก๋", type="pil", width=150, height=150)
|
35 |
+
image3 = gr.Image(label="์ด๋ฏธ์ง 3 ์
๋ก๋", type="pil", width=150, height=150)
|
36 |
+
image4 = gr.Image(label="์ด๋ฏธ์ง 4 ์
๋ก๋", type="pil", width=150, height=150)
|
37 |
+
|
38 |
+
upload_button = gr.Button("Upload and Shuffle Images")
|
39 |
+
output_image1 = gr.Image(label="์์ธ ์ด๋ฏธ์ง 1", width=150, height=150)
|
40 |
+
output_image2 = gr.Image(label="์์ธ ์ด๋ฏธ์ง 2", width=150, height=150)
|
41 |
+
output_image3 = gr.Image(label="์์ธ ์ด๋ฏธ์ง 3", width=150, height=150)
|
42 |
+
output_image4 = gr.Image(label="์์ธ ์ด๋ฏธ์ง 4", width=150, height=150)
|
43 |
+
|
44 |
+
with gr.Row():
|
45 |
+
slot1 = gr.Dropdown(choices=[1, 2, 3, 4], label="Slot 1")
|
46 |
+
slot2 = gr.Dropdown(choices=[1, 2, 3, 4], label="Slot 2")
|
47 |
+
slot3 = gr.Dropdown(choices=[1, 2, 3, 4], label="Slot 3")
|
48 |
+
slot4 = gr.Dropdown(choices=[1, 2, 3, 4], label="Slot 4")
|
49 |
+
|
50 |
+
submit_button = gr.Button("Submit")
|
51 |
+
result = gr.Label()
|
52 |
+
correct_order_image1 = gr.Image(label="์ ๋ต ์์ ์ด๋ฏธ์ง 1", width=150, height=150)
|
53 |
+
correct_order_image2 = gr.Image(label="์ ๋ต ์์ ์ด๋ฏธ์ง 2", width=150, height=150)
|
54 |
+
correct_order_image3 = gr.Image(label="์ ๋ต ์์ ์ด๋ฏธ์ง 3", width=150, height=150)
|
55 |
+
correct_order_image4 = gr.Image(label="์ ๋ต ์์ ์ด๋ฏธ์ง 4", width=150, height=150)
|
56 |
+
|
57 |
+
upload_button.click(upload_and_shuffle, inputs=[image1, image2, image3, image4], outputs=[output_image1, output_image2, output_image3, output_image4])
|
58 |
+
submit_button.click(check_order, inputs=[slot1, slot2, slot3, slot4], outputs=[result, correct_order_image1, correct_order_image2, correct_order_image3, correct_order_image4])
|
59 |
+
|
60 |
+
return demo
|
61 |
+
|
62 |
+
# Gradio ์ธํฐํ์ด์ค ์คํ
|
63 |
+
demo = create_interface()
|
64 |
+
demo.launch()
|