JM0410 commited on
Commit
ba20d92
โ€ข
1 Parent(s): f362eb7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
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()