Spaces:
Sleeping
Sleeping
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() | |