ใ……ใ…Žใ…‡ 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
Files changed (1) hide show
  1. 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
- with gr.Row():
138
- session_id_input = gr.Textbox(
139
- label="Session ID (์ด ID๊ฐ€ ๊ฐ™์œผ๋ฉด ๋Œ€ํ™”๊ฐ€ ์œ ์ง€๋ฉ๋‹ˆ๋‹ค)",
140
- value=str(uuid.uuid4()),
141
- interactive=True,
142
- placeholder="์„ธ์…˜ ID๋ฅผ ์ž…๋ ฅํ•˜๊ฑฐ๋‚˜ ๊ทธ๋Œ€๋กœ ๋‘์„ธ์š”"
143
- )
144
 
145
  # 3. ์ฑ„ํŒ… ์ธํ„ฐํŽ˜์ด์Šค
146
- # Chatbot๊ณผ Textbox ๊ฐ์ฒด๋ฅผ ๋จผ์ € ์ƒ์„ฑํ•˜์—ฌ ์ด๋ฒคํŠธ ๋ฐ”์ธ๋”ฉ ๋ฐ ์˜ˆ์‹œ ๋ฒ„ํŠผ์—์„œ ์ฐธ์กฐ ๊ฐ€๋Šฅํ•˜๋„๋ก ํ•จ
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
- textbox=textbox,
 
166
  additional_inputs=[session_id_input],
167
  )
168
 
169
- # 4. ์˜ˆ์‹œ ์งˆ๋ฌธ (๊ณต์‹ ๋ฌธ์„œ ํŒจํ„ด: textbox๋ฅผ ๋จผ์ € ์ƒ์„ฑํ•˜๊ณ  ChatInterface์— ์ „๋‹ฌ)
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. ์‹œ์Šคํ…œ ์ •๋ณด (์—…๋ฐ์ดํŠธ๋œ ๋ฆฌํŒฉํ† ๋ง ๋‚ด์šฉ ๋ฐ˜์˜)