File size: 3,557 Bytes
26ca8c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
Square Theory Generator (Gradio demo)
------------------------------------
์ด ์Šคํฌ๋ฆฝํŠธ๋Š” Adam Aaronson์˜ โ€œSquare Theoryโ€ ๊ฐœ๋…์„ ํ•œ๊ตญ์–ด ์นดํ”ผ๋ผ์ดํŒ…ยท๋ธŒ๋žœ๋“œ ๋„ค์ด๋ฐ์—
์‹คํ—˜์ ์œผ๋กœ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๊ฐ„๋‹จํ•œ ์›น ์•ฑ์ž…๋‹ˆ๋‹ค.

๐Ÿงฉ **๋ฌด์—‡์„ ํ•˜๋‚˜์š”?**
1. ์‚ฌ์šฉ์ž๊ฐ€ ๋„ค ๊ฐœ์˜ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด (์œ—๋ณ€ AยทB, ์•„๋žซ๋ณ€ A'ยทB')
2. ๋„ค ๋ณ€์ด ์™„์ „ํ•œ ์‚ฌ๊ฐํ˜•์„ ์ด๋ฃจ๋Š”์ง€ ์‹œ๊ฐ์ ์œผ๋กœ ๋ณด์—ฌ ์ค๋‹ˆ๋‹ค.
3. ๋™์‹œ์— ๋‘ ์ค„ ์Šฌ๋กœ๊ฑด, ๋ธŒ๋žœ๋“œ ๋„ค์ž„ ํ›„๋ณด๋ฅผ ์ž๋™ ์ œ์•ˆํ•ฉ๋‹ˆ๋‹ค.

โœ๏ธ **๊ตฌํ˜„ ํฌ์ธํŠธ**
- **Gradio Blocks**๋ฅผ ์‚ฌ์šฉํ•ด ์ž…๋ ฅยท์ถœ๋ ฅ ๋ ˆ์ด์•„์›ƒ์„ ์ž์œ ๋กญ๊ฒŒ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค. (cf. gradio docs)  
- **Matplotlib**๋กœ ๊ฐ„๋‹จํ•œ ์‚ฌ๊ฐํ˜• ๋„์‹์„ ๊ทธ๋ ค์„œ ์‹œ๊ฐ์  ์ดํ•ด๋ฅผ ๋•์Šต๋‹ˆ๋‹ค.
- ๋‹จ์–ด ์กฐํ•ฉ ๋กœ์ง์€ ๋ฐ๋ชจ ๋ชฉ์ ์˜ ์‹ฌํ”Œ ๋ฒ„์ „์ž…๋‹ˆ๋‹ค. ํ•„์š”ํ•˜๋ฉด WordNetยท๊ผฌ๊ผฌ๋งˆ ๋“ฑ์œผ๋กœ ํ™•์žฅ ๊ฐ€๋Šฅ.

Author: ChatGPT (OpenAI)
"""

import gradio as gr
import matplotlib.pyplot as plt
from matplotlib import patches


def draw_square(a: str, b: str, a_alt: str, b_alt: str):
    """Return a matplotlib Figure that visualizes the Square Theory diagram."""
    # Create figure & axis
    fig, ax = plt.subplots(figsize=(4, 4))
    # Draw square border
    square = patches.Rectangle((0, 0), 1, 1, fill=False, linewidth=2)
    ax.add_patch(square)

    # Corner labels
    ax.text(-0.05, 1.05, a, ha="right", va="bottom", fontsize=14, fontweight="bold")
    ax.text(1.05, 1.05, b, ha="left", va="bottom", fontsize=14, fontweight="bold")
    ax.text(-0.05, -0.05, a_alt, ha="right", va="top", fontsize=14, fontweight="bold")
    ax.text(1.05, -0.05, b_alt, ha="left", va="top", fontsize=14, fontweight="bold")

    # Hide axes
    ax.set_xticks([])
    ax.set_yticks([])
    ax.set_xlim(-0.2, 1.2)
    ax.set_ylim(-0.2, 1.2)
    ax.set_aspect("equal")
    return fig


def generate_square(a: str, b: str, a_alt: str, b_alt: str):
    """Core callback: returns diagram + text outputs."""
    # Basic phrases
    top_phrase = f"{a} {b}"
    bottom_phrase = f"{a_alt} {b_alt}"

    # Simple 2โ€‘line slogan
    slogan = f"{top_phrase}!\n{bottom_phrase}!"

    # Brand suggestions (kor+eng)
    brand_korean = f"{a_alt}{b_alt}"
    brand_english = f"{a.capitalize()}{b.capitalize()}"
    brand_combo = f"{brand_korean} / {brand_english}"

    # Figure
    fig = draw_square(a, b, a_alt, b_alt)

    return fig, top_phrase, bottom_phrase, slogan, brand_combo


with gr.Blocks(title="Square Theory Generator ๐Ÿ‡ฐ๐Ÿ‡ท") as demo:
    gr.Markdown("""# โœจ Square Theory Generator\n๋„ค ๊ฐœ์˜ ๋‹จ์–ด๋กœ ์‚ฌ๊ฐํ˜•์„ ์™„์„ฑํ•ด ์นดํ”ผยท๋ธŒ๋žœ๋“œ ์•„์ด๋””์–ด๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์„ธ์š”.""")

    with gr.Row():
        a = gr.Textbox(label="๋‹จ์–ด 1 (์™ผ์ชฝ ์œ„)")
        b = gr.Textbox(label="๋‹จ์–ด 2 (์˜ค๋ฅธ์ชฝ ์œ„)")
    with gr.Row():
        a_alt = gr.Textbox(label="๋Œ€์‘ ๋‹จ์–ด 1 (์™ผ์ชฝ ์•„๋ž˜)")
        b_alt = gr.Textbox(label="๋Œ€์‘ ๋‹จ์–ด 2 (์˜ค๋ฅธ์ชฝ ์•„๋ž˜)")

    btn = gr.Button("์‚ฌ๊ฐํ˜• ์ƒ์„ฑ")

    fig_out = gr.Plot(label="์‚ฌ๊ฐํ˜• ๋‹ค์ด์–ด๊ทธ๋žจ")
    top_out = gr.Textbox(label="์œ—๋ณ€ ํ‘œํ˜„")
    bottom_out = gr.Textbox(label="์•„๋žซ๋ณ€ ํ‘œํ˜„")
    slogan_out = gr.Textbox(label="2ํ–‰ ์Šฌ๋กœ๊ฑด ์ œ์•ˆ")
    brand_out = gr.Textbox(label="๋ธŒ๋žœ๋“œ ๋„ค์ž„ ์ œ์•ˆ")

    btn.click(
        fn=generate_square,
        inputs=[a, b, a_alt, b_alt],
        outputs=[fig_out, top_out, bottom_out, slogan_out, brand_out],
    )

if __name__ == "__main__":
    # For local testing; in production, set share=True or host on Spaces.
    demo.launch()