File size: 3,052 Bytes
ba20d92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import random
import gradio as gr
from PIL import Image

# ์„ž์ธ ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•  ๋ฆฌ์ŠคํŠธ
shuffled_images = []
original_images = []

# ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ๋ฐ ์„ž๊ธฐ ํ•จ์ˆ˜
def upload_and_shuffle(image1, image2, image3, image4):
    global shuffled_images, original_images
    images = [image1, image2, image3, image4]
    original_images = images.copy()
    random.shuffle(images)
    shuffled_images = images
    return images

# ์ˆœ์„œ ํ™•์ธ ํ•จ์ˆ˜
def check_order(slot1, slot2, slot3, slot4):
    user_order = [slot1 - 1, slot2 - 1, slot3 - 1, slot4 - 1]  # Adjust for 1-based index
    correct_order = [shuffled_images.index(img) for img in original_images]  # Correct order based on original images
    correct = user_order == correct_order
    return (
        "์ •๋‹ต์ž…๋‹ˆ๋‹ค!" if correct else "ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค. ์˜ฌ๋ฐ”๋ฅธ ์ˆœ์„œ๋Š”:",
        original_images[0], original_images[1],
        original_images[2], original_images[3]
    )

# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
def create_interface():
    with gr.Blocks() as demo:
        with gr.Row():
            image1 = gr.Image(label="์ด๋ฏธ์ง€ 1 ์—…๋กœ๋“œ", type="pil", width=150, height=150)
            image2 = gr.Image(label="์ด๋ฏธ์ง€ 2 ์—…๋กœ๋“œ", type="pil", width=150, height=150)
            image3 = gr.Image(label="์ด๋ฏธ์ง€ 3 ์—…๋กœ๋“œ", type="pil", width=150, height=150)
            image4 = gr.Image(label="์ด๋ฏธ์ง€ 4 ์—…๋กœ๋“œ", type="pil", width=150, height=150)

        upload_button = gr.Button("Upload and Shuffle Images")
        output_image1 = gr.Image(label="์„ž์ธ ์ด๋ฏธ์ง€ 1", width=150, height=150)
        output_image2 = gr.Image(label="์„ž์ธ ์ด๋ฏธ์ง€ 2", width=150, height=150)
        output_image3 = gr.Image(label="์„ž์ธ ์ด๋ฏธ์ง€ 3", width=150, height=150)
        output_image4 = gr.Image(label="์„ž์ธ ์ด๋ฏธ์ง€ 4", width=150, height=150)

        with gr.Row():
            slot1 = gr.Dropdown(choices=[1, 2, 3, 4], label="Slot 1")
            slot2 = gr.Dropdown(choices=[1, 2, 3, 4], label="Slot 2")
            slot3 = gr.Dropdown(choices=[1, 2, 3, 4], label="Slot 3")
            slot4 = gr.Dropdown(choices=[1, 2, 3, 4], label="Slot 4")

        submit_button = gr.Button("Submit")
        result = gr.Label()
        correct_order_image1 = gr.Image(label="์ •๋‹ต ์ˆœ์„œ ์ด๋ฏธ์ง€ 1", width=150, height=150)
        correct_order_image2 = gr.Image(label="์ •๋‹ต ์ˆœ์„œ ์ด๋ฏธ์ง€ 2", width=150, height=150)
        correct_order_image3 = gr.Image(label="์ •๋‹ต ์ˆœ์„œ ์ด๋ฏธ์ง€ 3", width=150, height=150)
        correct_order_image4 = gr.Image(label="์ •๋‹ต ์ˆœ์„œ ์ด๋ฏธ์ง€ 4", width=150, height=150)

        upload_button.click(upload_and_shuffle, inputs=[image1, image2, image3, image4], outputs=[output_image1, output_image2, output_image3, output_image4])
        submit_button.click(check_order, inputs=[slot1, slot2, slot3, slot4], outputs=[result, correct_order_image1, correct_order_image2, correct_order_image3, correct_order_image4])

    return demo

# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
demo = create_interface()
demo.launch()