CoolFace
Apppublic

seoheepqrk/philosophyprogram

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
app.py80 linesDownload Raw Back to root
1import random2import gradio as gr3 4# ------------------------------------------------5# 1) 여기부터 네가 만든 코드 그대로 붙여넣기6#    (PHILOSOPHERS, CATEGORIES, build_category_index 등)7# ------------------------------------------------8 9PHILOSOPHERS = {10    # 👉 여기에 네가 보내줬던 PHILOSOPHERS 내용 전체를 그대로 복붙11}12 13CATEGORIES = [14    "학업",15    "사고",16    "열정",17    "자아",18    "성찰",19    "인간관계",20    "행복",21    "자유",22    "진로",23    "감정",24    "존재",25    "신앙",26]27 28def build_category_index():29    index = {cat: [] for cat in CATEGORIES}30    for name, info in PHILOSOPHERS.items():31        for q in info["quotes"]:32            topic_str = q["topic"]33            parts = [p.strip() for p in topic_str.split("/")]34            for part in parts:35                for cat in CATEGORIES:36                    if cat in part:37                        index[cat].append((name, q["text"]))38    index = {cat: quotes for cat, quotes in index.items() if quotes}39    return index40 41category_index = build_category_index()42available_categories = list(category_index.keys())43 44# ------------------------------------------------45# 2) 여기부터가 "웹사이트용 껍데기" 부분 (새로 추가되는 부분)46# ------------------------------------------------47 48def counseling_for_web(category):49    """웹에서 카테고리를 하나 선택하면, 그에 맞는 명언/철학자/요약을 문자열로 반환"""50    name, text = random.choice(category_index[category])51    summary = PHILOSOPHERS[name]["summary"]52 53    result = []54    result.append(f"[고민 카테고리] {category}")55    result.append("")56    result.append(f"명언: {text}")57    result.append(f"철학자: {name}")58    result.append("")59    result.append(f"[{name}] 사상 요약")60    result.append(summary)61 62    return "\n".join(result)63 64# Gradio 인터페이스 정의65iface = gr.Interface(66    fn=counseling_for_web,67    inputs=gr.Dropdown(68        choices=available_categories,69        label="어떤 고민 카테고리에 대해 조언을 받고 싶으신가요?"70    ),71    outputs=gr.Textbox(72        lines=10,73        label="철학자의 상담 결과"74    ),75    title="철학 상담 프로그램 (웹)",76    description="고민 카테고리를 고르면, 그에 맞는 철학자의 명언과 사상을 보여줍니다."77)78 79if __name__ == "__main__":80    iface.launch()