Spaces:
Sleeping
Sleeping
ใ
ใ
ใ
commited on
Commit ยท
1483c7e
1
Parent(s): 3f75209
Fix: Use default textbox in ChatInterface to show submit and clear buttons - Remove custom textbox parameter (causes buttons to not show) - Use ChatInterface default textbox - Update example buttons to use chatbot_interface.textbox - Follow official documentation pattern
Browse files- CodeWeaver/ui/app.py +16 -20
CodeWeaver/ui/app.py
CHANGED
|
@@ -134,22 +134,16 @@ def create_demo() -> gr.Blocks:
|
|
| 134 |
""")
|
| 135 |
|
| 136 |
# 2. Session ID ์
๋ ฅ์ฐฝ
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
)
|
| 144 |
|
| 145 |
# 3. ์ฑํ
์ธํฐํ์ด์ค
|
| 146 |
-
# Chatbot
|
| 147 |
chatbot = gr.Chatbot(height=550)
|
| 148 |
-
textbox = gr.Textbox(
|
| 149 |
-
placeholder="๊ฐ๋ฐ ๊ด๋ จ ์ง๋ฌธ์ ์
๋ ฅํ์ธ์... (์: 'React useEffect ๋ฌดํ ๋ฃจํ ํด๊ฒฐ๋ฒ')",
|
| 150 |
-
container=False,
|
| 151 |
-
scale=7
|
| 152 |
-
)
|
| 153 |
|
| 154 |
# Clear ๋ฒํผ ํธ๋ค๋ฌ (๋ฌธ์ ์ฐธ๊ณ : https://www.gradio.app/guides/chatbot-specific-events)
|
| 155 |
def reset_session():
|
|
@@ -158,36 +152,38 @@ def create_demo() -> gr.Blocks:
|
|
| 158 |
# chatbot.clear() ์ด๋ฒคํธ์ ์ธ์
๋ฆฌ์
ํธ๋ค๋ฌ ๋ฐ์ธ๋ฉ
|
| 159 |
chatbot.clear(reset_session, outputs=[session_id_input])
|
| 160 |
|
|
|
|
| 161 |
chatbot_interface = gr.ChatInterface(
|
| 162 |
fn=chat,
|
| 163 |
-
examples=None,
|
| 164 |
chatbot=chatbot,
|
| 165 |
-
|
|
|
|
| 166 |
additional_inputs=[session_id_input],
|
| 167 |
)
|
| 168 |
|
| 169 |
-
# 4. ์์ ์ง๋ฌธ
|
| 170 |
gr.Markdown("### ๐ก ์ถ์ฒ ์ง๋ฌธ ์์")
|
| 171 |
with gr.Row():
|
| 172 |
# ๋๋ฒ๊น
|
| 173 |
gr.Button("Python KeyError: 'data' ํด๊ฒฐ๋ฒ", variant="primary", size="sm").click(
|
| 174 |
fn=lambda: "Python ๋์
๋๋ฆฌ์์ KeyError: 'data' ์๋ฌ๊ฐ ๋๋๋ฐ ํด๊ฒฐ ๋ฐฉ๋ฒ ์๋ ค์ค",
|
| 175 |
-
outputs=[textbox]
|
| 176 |
)
|
| 177 |
# ํ๋ก ํธ์๋ ์ด์
|
| 178 |
gr.Button("React useEffect ๋ฌดํ ๋ฃจํ ์์ธ", variant="primary", size="sm").click(
|
| 179 |
fn=lambda: "React useEffect์์ ๋ฌดํ ๋ฃจํ๊ฐ ๋ฐ์ํ๋ ์ด์ ์ ํด๊ฒฐ ๋ฐฉ๋ฒ์?",
|
| 180 |
-
outputs=[textbox]
|
| 181 |
)
|
| 182 |
# ๋ค์ค ์ง๋ฌธ (๋ณ๊ฒฝ๋ ์์)
|
| 183 |
gr.Button("REST API vs GraphQL (๋ค์ค ์ง๋ฌธ)", variant="secondary", size="sm").click(
|
| 184 |
fn=lambda: "REST API๊ฐ ๋ญ์ผ? ๊ทธ๋ฆฌ๊ณ GraphQL์?",
|
| 185 |
-
outputs=[textbox]
|
| 186 |
)
|
| 187 |
# ๊ฐ๋
ํ์ต
|
| 188 |
gr.Button("Spring Boot JPA N+1 ๋ฌธ์ ", variant="secondary", size="sm").click(
|
| 189 |
fn=lambda: "Spring Boot JPA N+1 ๋ฌธ์ ํด๊ฒฐ ๋ฐฉ๋ฒ์?",
|
| 190 |
-
outputs=[textbox]
|
| 191 |
)
|
| 192 |
|
| 193 |
# 5. ์์คํ
์ ๋ณด (์
๋ฐ์ดํธ๋ ๋ฆฌํฉํ ๋ง ๋ด์ฉ ๋ฐ์)
|
|
|
|
| 134 |
""")
|
| 135 |
|
| 136 |
# 2. Session ID ์
๋ ฅ์ฐฝ
|
| 137 |
+
session_id_input = gr.Textbox(
|
| 138 |
+
label="Session ID (์ด ID๊ฐ ๊ฐ์ผ๋ฉด ๋ํ๊ฐ ์ ์ง๋ฉ๋๋ค)",
|
| 139 |
+
value=str(uuid.uuid4()),
|
| 140 |
+
interactive=True,
|
| 141 |
+
placeholder="์ธ์
ID๋ฅผ ์
๋ ฅํ๊ฑฐ๋ ๊ทธ๋๋ก ๋์ธ์"
|
| 142 |
+
)
|
|
|
|
| 143 |
|
| 144 |
# 3. ์ฑํ
์ธํฐํ์ด์ค
|
| 145 |
+
# Chatbot ๊ฐ์ฒด๋ฅผ ๋จผ์ ์์ฑํ์ฌ clear ์ด๋ฒคํธ๋ฅผ ๋ฐ์ธ๋ฉ
|
| 146 |
chatbot = gr.Chatbot(height=550)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
# Clear ๋ฒํผ ํธ๋ค๋ฌ (๋ฌธ์ ์ฐธ๊ณ : https://www.gradio.app/guides/chatbot-specific-events)
|
| 149 |
def reset_session():
|
|
|
|
| 152 |
# chatbot.clear() ์ด๋ฒคํธ์ ์ธ์
๋ฆฌ์
ํธ๋ค๋ฌ ๋ฐ์ธ๋ฉ
|
| 153 |
chatbot.clear(reset_session, outputs=[session_id_input])
|
| 154 |
|
| 155 |
+
# ChatInterface ์์ฑ (๊ณต์ ๋ฌธ์ ํจํด: textbox๋ ๊ธฐ๋ณธ๊ฐ ์ฌ์ฉ)
|
| 156 |
chatbot_interface = gr.ChatInterface(
|
| 157 |
fn=chat,
|
| 158 |
+
examples=None,
|
| 159 |
chatbot=chatbot,
|
| 160 |
+
submit_btn="์ ์ก",
|
| 161 |
+
clear_btn="๐๏ธ ๋ํ ์ด๊ธฐํ",
|
| 162 |
additional_inputs=[session_id_input],
|
| 163 |
)
|
| 164 |
|
| 165 |
+
# 4. ์์ ์ง๋ฌธ
|
| 166 |
gr.Markdown("### ๐ก ์ถ์ฒ ์ง๋ฌธ ์์")
|
| 167 |
with gr.Row():
|
| 168 |
# ๋๋ฒ๊น
|
| 169 |
gr.Button("Python KeyError: 'data' ํด๊ฒฐ๋ฒ", variant="primary", size="sm").click(
|
| 170 |
fn=lambda: "Python ๋์
๋๋ฆฌ์์ KeyError: 'data' ์๋ฌ๊ฐ ๋๋๋ฐ ํด๊ฒฐ ๋ฐฉ๋ฒ ์๋ ค์ค",
|
| 171 |
+
outputs=[chatbot_interface.textbox]
|
| 172 |
)
|
| 173 |
# ํ๋ก ํธ์๋ ์ด์
|
| 174 |
gr.Button("React useEffect ๋ฌดํ ๋ฃจํ ์์ธ", variant="primary", size="sm").click(
|
| 175 |
fn=lambda: "React useEffect์์ ๋ฌดํ ๋ฃจํ๊ฐ ๋ฐ์ํ๋ ์ด์ ์ ํด๊ฒฐ ๋ฐฉ๋ฒ์?",
|
| 176 |
+
outputs=[chatbot_interface.textbox]
|
| 177 |
)
|
| 178 |
# ๋ค์ค ์ง๋ฌธ (๋ณ๊ฒฝ๋ ์์)
|
| 179 |
gr.Button("REST API vs GraphQL (๋ค์ค ์ง๋ฌธ)", variant="secondary", size="sm").click(
|
| 180 |
fn=lambda: "REST API๊ฐ ๋ญ์ผ? ๊ทธ๋ฆฌ๊ณ GraphQL์?",
|
| 181 |
+
outputs=[chatbot_interface.textbox]
|
| 182 |
)
|
| 183 |
# ๊ฐ๋
ํ์ต
|
| 184 |
gr.Button("Spring Boot JPA N+1 ๋ฌธ์ ", variant="secondary", size="sm").click(
|
| 185 |
fn=lambda: "Spring Boot JPA N+1 ๋ฌธ์ ํด๊ฒฐ ๋ฐฉ๋ฒ์?",
|
| 186 |
+
outputs=[chatbot_interface.textbox]
|
| 187 |
)
|
| 188 |
|
| 189 |
# 5. ์์คํ
์ ๋ณด (์
๋ฐ์ดํธ๋ ๋ฆฌํฉํ ๋ง ๋ด์ฉ ๋ฐ์)
|