dev-yuje commited on
Commit
e471528
Β·
1 Parent(s): 0b09cae

fix: dynamically assign theme parameter based on Gradio major version to support both local 6.x and remote 4.x

Browse files
Files changed (1) hide show
  1. app.py +36 -14
app.py CHANGED
@@ -116,12 +116,25 @@ def chat(message: str, history: list) -> str:
116
  # 5. Gradio UI ꡬ성
117
  # ──────────────────────────────────────────
118
 
119
- demo = gr.ChatInterface(
120
- fn=chat,
121
- chatbot=gr.Chatbot(height=500),
122
- textbox=gr.Textbox(container=False, scale=7),
123
- title="FinNode β€” AI κΈ°μ—… νŠΈλ Œλ“œ 뢄석 챗봇",
124
- description=(
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  "> μ΅œμ‹  AI λ‰΄μŠ€λ₯Ό 기반으둜 κ΅¬μΆ•λœ 지식 κ·Έλž˜ν”„(GraphRAG)μ—μ„œ λ‹΅λ³€ν•©λ‹ˆλ‹€.\n\n"
126
  "**μ˜ˆμ‹œ 질문**\n"
127
  "- μ‚Όμ„±μ „μžμ˜ 졜근 AI 기술 νŠΈλ Œλ“œλŠ”?\n"
@@ -129,18 +142,27 @@ demo = gr.ChatInterface(
129
  "- μ–΄λ–€ 기업이 LLM κΈ°μˆ μ„ κ°œλ°œν•˜λ‚˜μš”?\n"
130
  "- 졜근 AI κ΄€λ ¨ λ‰΄μŠ€ 기사λ₯Ό μš”μ•½ν•΄μ€˜"
131
  ),
132
- examples=[
133
  "μ‚Όμ„±μ „μžμ˜ 졜근 AI 기술 νŠΈλ Œλ“œλŠ”?",
134
  "μΉ΄μΉ΄μ˜€κ°€ 개발 쀑인 AI μ„œλΉ„μŠ€ λͺ©λ‘μ„ μ•Œλ €μ€˜",
135
  "μ–΄λ–€ 기업이 LLM κΈ°μˆ μ„ κ°œλ°œν•˜λ‚˜μš”?",
136
  "졜근 AI κ΄€λ ¨ λ‰΄μŠ€ 기사λ₯Ό μš”μ•½ν•΄μ€˜",
137
  ],
138
- cache_examples=False,
139
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
  if __name__ == "__main__":
142
- demo.launch(
143
- server_name="0.0.0.0",
144
- server_port=7860,
145
- theme=gr.themes.Soft(primary_hue="indigo")
146
- )
 
116
  # 5. Gradio UI ꡬ성
117
  # ──────────────────────────────────────────
118
 
119
+ # Gradio 버전 동적 감지 및 ν…Œλ§ˆ μ„€μ • λΆ„κΈ° (둜컬 6.x vs 원격 4.x ν¬λž˜μ‹œ μ™„λ²½ λ°©μ§€)
120
+ try:
121
+ gradio_major = int(gr.__version__.split(".")[0])
122
+ except Exception:
123
+ gradio_major = 4 # κΈ°λ³Έκ°’ λ°±μ—…
124
+
125
+ theme_obj = gr.themes.Soft(
126
+ primary_hue="blue",
127
+ secondary_hue="slate",
128
+ neutral_hue="slate",
129
+ font=[gr.themes.GoogleFont("Outfit"), "sans-serif"]
130
+ )
131
+
132
+ interface_kwargs = {
133
+ "fn": chat,
134
+ "chatbot": gr.Chatbot(height=500),
135
+ "textbox": gr.Textbox(container=False, scale=7),
136
+ "title": "FinNode β€” AI κΈ°μ—… νŠΈλ Œλ“œ 뢄석 챗봇",
137
+ "description": (
138
  "> μ΅œμ‹  AI λ‰΄μŠ€λ₯Ό 기반으둜 κ΅¬μΆ•λœ 지식 κ·Έλž˜ν”„(GraphRAG)μ—μ„œ λ‹΅λ³€ν•©λ‹ˆλ‹€.\n\n"
139
  "**μ˜ˆμ‹œ 질문**\n"
140
  "- μ‚Όμ„±μ „μžμ˜ 졜근 AI 기술 νŠΈλ Œλ“œλŠ”?\n"
 
142
  "- μ–΄λ–€ 기업이 LLM κΈ°μˆ μ„ κ°œλ°œν•˜λ‚˜μš”?\n"
143
  "- 졜근 AI κ΄€λ ¨ λ‰΄μŠ€ 기사λ₯Ό μš”μ•½ν•΄μ€˜"
144
  ),
145
+ "examples": [
146
  "μ‚Όμ„±μ „μžμ˜ 졜근 AI 기술 νŠΈλ Œλ“œλŠ”?",
147
  "μΉ΄μΉ΄μ˜€κ°€ 개발 쀑인 AI μ„œλΉ„μŠ€ λͺ©λ‘μ„ μ•Œλ €μ€˜",
148
  "μ–΄λ–€ 기업이 LLM κΈ°μˆ μ„ κ°œλ°œν•˜λ‚˜μš”?",
149
  "졜근 AI κ΄€λ ¨ λ‰΄μŠ€ 기사λ₯Ό μš”μ•½ν•΄μ€˜",
150
  ],
151
+ "cache_examples": False
152
+ }
153
+
154
+ launch_kwargs = {
155
+ "server_name": "0.0.0.0",
156
+ "server_port": 7860
157
+ }
158
+
159
+ # 버전에 맞좘 ν…Œλ§ˆ μ£Όμž… νŒŒμ΄ν”„λΌμΈ
160
+ if gradio_major < 5:
161
+ interface_kwargs["theme"] = theme_obj
162
+ else:
163
+ launch_kwargs["theme"] = theme_obj
164
+
165
+ demo = gr.ChatInterface(**interface_kwargs)
166
 
167
  if __name__ == "__main__":
168
+ demo.launch(**launch_kwargs)