|
""" |
|
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.""" |
|
|
|
fig, ax = plt.subplots(figsize=(4, 4)) |
|
|
|
square = patches.Rectangle((0, 0), 1, 1, fill=False, linewidth=2) |
|
ax.add_patch(square) |
|
|
|
|
|
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") |
|
|
|
|
|
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.""" |
|
|
|
top_phrase = f"{a} {b}" |
|
bottom_phrase = f"{a_alt} {b_alt}" |
|
|
|
|
|
slogan = f"{top_phrase}!\n{bottom_phrase}!" |
|
|
|
|
|
brand_korean = f"{a_alt}{b_alt}" |
|
brand_english = f"{a.capitalize()}{b.capitalize()}" |
|
brand_combo = f"{brand_korean} / {brand_english}" |
|
|
|
|
|
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__": |
|
|
|
demo.launch() |
|
|