openfree commited on
Commit
26ca8c8
ยท
verified ยท
1 Parent(s): 9f460f3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -0
app.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Square Theory Generator (Gradio demo)
3
+ ------------------------------------
4
+ ์ด ์Šคํฌ๋ฆฝํŠธ๋Š” Adam Aaronson์˜ โ€œSquare Theoryโ€ ๊ฐœ๋…์„ ํ•œ๊ตญ์–ด ์นดํ”ผ๋ผ์ดํŒ…ยท๋ธŒ๋žœ๋“œ ๋„ค์ด๋ฐ์—
5
+ ์‹คํ—˜์ ์œผ๋กœ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๊ฐ„๋‹จํ•œ ์›น ์•ฑ์ž…๋‹ˆ๋‹ค.
6
+
7
+ ๐Ÿงฉ **๋ฌด์—‡์„ ํ•˜๋‚˜์š”?**
8
+ 1. ์‚ฌ์šฉ์ž๊ฐ€ ๋„ค ๊ฐœ์˜ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด (์œ—๋ณ€ AยทB, ์•„๋žซ๋ณ€ A'ยทB')
9
+ 2. ๋„ค ๋ณ€์ด ์™„์ „ํ•œ ์‚ฌ๊ฐํ˜•์„ ์ด๋ฃจ๋Š”์ง€ ์‹œ๊ฐ์ ์œผ๋กœ ๋ณด์—ฌ ์ค๋‹ˆ๋‹ค.
10
+ 3. ๋™์‹œ์— ๋‘ ์ค„ ์Šฌ๋กœ๊ฑด, ๋ธŒ๋žœ๋“œ ๋„ค์ž„ ํ›„๋ณด๋ฅผ ์ž๋™ ์ œ์•ˆํ•ฉ๋‹ˆ๋‹ค.
11
+
12
+ โœ๏ธ **๊ตฌํ˜„ ํฌ์ธํŠธ**
13
+ - **Gradio Blocks**๋ฅผ ์‚ฌ์šฉํ•ด ์ž…๋ ฅยท์ถœ๋ ฅ ๋ ˆ์ด์•„์›ƒ์„ ์ž์œ ๋กญ๊ฒŒ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค. (cf. gradio docs)
14
+ - **Matplotlib**๋กœ ๊ฐ„๋‹จํ•œ ์‚ฌ๊ฐํ˜• ๋„์‹์„ ๊ทธ๋ ค์„œ ์‹œ๊ฐ์  ์ดํ•ด๋ฅผ ๋•์Šต๋‹ˆ๋‹ค.
15
+ - ๋‹จ์–ด ์กฐํ•ฉ ๋กœ์ง์€ ๋ฐ๋ชจ ๋ชฉ์ ์˜ ์‹ฌํ”Œ ๋ฒ„์ „์ž…๋‹ˆ๋‹ค. ํ•„์š”ํ•˜๋ฉด WordNetยท๊ผฌ๊ผฌ๋งˆ ๋“ฑ์œผ๋กœ ํ™•์žฅ ๊ฐ€๋Šฅ.
16
+
17
+ Author: ChatGPT (OpenAI)
18
+ """
19
+
20
+ import gradio as gr
21
+ import matplotlib.pyplot as plt
22
+ from matplotlib import patches
23
+
24
+
25
+ def draw_square(a: str, b: str, a_alt: str, b_alt: str):
26
+ """Return a matplotlib Figure that visualizes the Square Theory diagram."""
27
+ # Create figure & axis
28
+ fig, ax = plt.subplots(figsize=(4, 4))
29
+ # Draw square border
30
+ square = patches.Rectangle((0, 0), 1, 1, fill=False, linewidth=2)
31
+ ax.add_patch(square)
32
+
33
+ # Corner labels
34
+ ax.text(-0.05, 1.05, a, ha="right", va="bottom", fontsize=14, fontweight="bold")
35
+ ax.text(1.05, 1.05, b, ha="left", va="bottom", fontsize=14, fontweight="bold")
36
+ ax.text(-0.05, -0.05, a_alt, ha="right", va="top", fontsize=14, fontweight="bold")
37
+ ax.text(1.05, -0.05, b_alt, ha="left", va="top", fontsize=14, fontweight="bold")
38
+
39
+ # Hide axes
40
+ ax.set_xticks([])
41
+ ax.set_yticks([])
42
+ ax.set_xlim(-0.2, 1.2)
43
+ ax.set_ylim(-0.2, 1.2)
44
+ ax.set_aspect("equal")
45
+ return fig
46
+
47
+
48
+ def generate_square(a: str, b: str, a_alt: str, b_alt: str):
49
+ """Core callback: returns diagram + text outputs."""
50
+ # Basic phrases
51
+ top_phrase = f"{a} {b}"
52
+ bottom_phrase = f"{a_alt} {b_alt}"
53
+
54
+ # Simple 2โ€‘line slogan
55
+ slogan = f"{top_phrase}!\n{bottom_phrase}!"
56
+
57
+ # Brand suggestions (kor+eng)
58
+ brand_korean = f"{a_alt}{b_alt}"
59
+ brand_english = f"{a.capitalize()}{b.capitalize()}"
60
+ brand_combo = f"{brand_korean} / {brand_english}"
61
+
62
+ # Figure
63
+ fig = draw_square(a, b, a_alt, b_alt)
64
+
65
+ return fig, top_phrase, bottom_phrase, slogan, brand_combo
66
+
67
+
68
+ with gr.Blocks(title="Square Theory Generator ๐Ÿ‡ฐ๐Ÿ‡ท") as demo:
69
+ gr.Markdown("""# โœจ Square Theory Generator\n๋„ค ๊ฐœ์˜ ๋‹จ์–ด๋กœ ์‚ฌ๊ฐํ˜•์„ ์™„์„ฑํ•ด ์นดํ”ผยท๋ธŒ๋žœ๋“œ ์•„์ด๋””์–ด๋ฅผ ๋งŒ๋“ค์–ด ๋ณด์„ธ์š”.""")
70
+
71
+ with gr.Row():
72
+ a = gr.Textbox(label="๋‹จ์–ด 1 (์™ผ์ชฝ ์œ„)")
73
+ b = gr.Textbox(label="๋‹จ์–ด 2 (์˜ค๋ฅธ์ชฝ ์œ„)")
74
+ with gr.Row():
75
+ a_alt = gr.Textbox(label="๋Œ€์‘ ๋‹จ์–ด 1 (์™ผ์ชฝ ์•„๋ž˜)")
76
+ b_alt = gr.Textbox(label="๋Œ€์‘ ๋‹จ์–ด 2 (์˜ค๋ฅธ์ชฝ ์•„๋ž˜)")
77
+
78
+ btn = gr.Button("์‚ฌ๊ฐํ˜• ์ƒ์„ฑ")
79
+
80
+ fig_out = gr.Plot(label="์‚ฌ๊ฐํ˜• ๋‹ค์ด์–ด๊ทธ๋žจ")
81
+ top_out = gr.Textbox(label="์œ—๋ณ€ ํ‘œํ˜„")
82
+ bottom_out = gr.Textbox(label="์•„๋žซ๋ณ€ ํ‘œํ˜„")
83
+ slogan_out = gr.Textbox(label="2ํ–‰ ์Šฌ๋กœ๊ฑด ์ œ์•ˆ")
84
+ brand_out = gr.Textbox(label="๋ธŒ๋žœ๋“œ ๋„ค์ž„ ์ œ์•ˆ")
85
+
86
+ btn.click(
87
+ fn=generate_square,
88
+ inputs=[a, b, a_alt, b_alt],
89
+ outputs=[fig_out, top_out, bottom_out, slogan_out, brand_out],
90
+ )
91
+
92
+ if __name__ == "__main__":
93
+ # For local testing; in production, set share=True or host on Spaces.
94
+ demo.launch()