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()
|