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