Create app.py
Browse files
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()
|