seawolf2357 commited on
Commit
1fffc2c
ยท
verified ยท
1 Parent(s): 263eaf7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -88
app.py CHANGED
@@ -143,10 +143,11 @@ with gr.Blocks(css_paths="app.css") as demo:
143
  except Exception as e:
144
  raise ValueError(f'Error calling Claude API: {str(e)}')
145
 
 
146
  with ms.Application() as app:
147
  with antd.ConfigProvider():
148
- # ๋ฉ”์ธ ์ปจํ…์ธ  ์˜์—ญ
149
- with antd.Row(gutter=[32, 12], elem_classes="main-content") as layout:
150
  # ์ขŒ์ธก ํŒจ๋„
151
  with antd.Col(span=24, md=8):
152
  with antd.Flex(vertical=True, gap="middle", wrap=True):
@@ -165,109 +166,71 @@ with gr.Blocks(css_paths="app.css") as demo:
165
  btn = antd.Button("send", type="primary", size="large")
166
  clear_btn = antd.Button("clear history", type="default", size="large")
167
 
 
 
 
 
 
 
 
 
 
 
 
168
  # ์šฐ์ธก ํŒจ๋„
169
  with antd.Col(span=24, md=16):
170
- # Setting ๋ฒ„ํŠผ๋“ค์„ ์šฐ์ธก ์ƒ๋‹จ์— ๋ณ„๋„๋กœ ๋ฐฐ์น˜
171
- with antd.Row(justify="end", elem_classes="setting-buttons-row"):
172
- settingPromptBtn = antd.Button("โš™๏ธ set system Prompt", type="default")
173
- codeBtn = antd.Button("๐Ÿง‘โ€๐Ÿ’ป view code", type="default")
174
- historyBtn = antd.Button("๐Ÿ“œ history", type="default")
175
-
176
- # ์›น ์ถœ๋ ฅ ํŒจ๋„
177
  with ms.Div(elem_classes="right_panel"):
 
 
 
 
 
 
178
  gr.HTML('<div class="render_header"><span class="header_btn"></span><span class="header_btn"></span><span class="header_btn"></span></div>')
179
  with antd.Tabs(active_key="empty", render_tab_bar="() => null") as state_tab:
180
  with antd.Tabs.Item(key="empty"):
181
  empty = antd.Empty(description="empty input", elem_classes="right_content")
182
- with antd.Tabs.Item(key="loading"):
183
- loading = antd.Spin(True, tip="coding...", size="large", elem_classes="right_content")
184
- with antd.Tabs.Item(key="render"):
185
- sandbox = gr.HTML(elem_classes="html_content")
186
 
187
- # Examples ์„น์…˜
188
- with antd.Row(elem_classes="examples-section"):
189
  with antd.Col(span=24):
190
  antd.Divider("examples")
191
- with antd.Row():
192
- for idx, demo in enumerate(DEMO_LIST):
193
- with antd.Col(span=8):
194
- with antd.Card(hoverable=True) as demoCard:
195
- antd.CardMeta(title=demo.get('title', f'Example {idx + 1}'))
196
- demoCard.click(
197
- fn=lambda x, i=idx: DEMO_LIST[i]['description'],
198
- inputs=[gr.State(None)], # ๋”๋ฏธ ์ž…๋ ฅ ์ถ”๊ฐ€
199
- outputs=[input]
200
- )
201
-
202
- # Modal๊ณผ Drawer ์ปดํฌ๋„ŒํŠธ๋“ค
203
- with antd.Modal(open=False, title="set system Prompt", width="800px") as system_prompt_modal:
204
- systemPromptInput = antd.InputTextarea(
205
- SystemPrompt, auto_size=True)
206
-
207
- with antd.Drawer(open=False, title="code", placement="left", width="750px") as code_drawer:
208
- code_output = legacy.Markdown()
209
-
210
- with antd.Drawer(open=False, title="history", placement="left", width="900px") as history_drawer:
211
- history_output = legacy.Chatbot(show_label=False, flushing=False, height=960, elem_classes="history_chatbot")
212
-
213
  # ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
214
- settingPromptBtn.click(
215
- fn=lambda: gr.update(open=True),
216
- inputs=[],
217
- outputs=[system_prompt_modal]
218
- )
219
-
220
- system_prompt_modal.ok(
221
- fn=lambda x: ({"system": x}, gr.update(open=False)),
222
- inputs=[systemPromptInput],
223
- outputs=[setting, system_prompt_modal]
224
- )
225
-
226
- system_prompt_modal.cancel(
227
- fn=lambda: gr.update(open=False),
228
- inputs=[],
229
- outputs=[system_prompt_modal]
230
- )
231
-
232
- codeBtn.click(
233
- fn=lambda: gr.update(open=True),
234
- inputs=[],
235
- outputs=[code_drawer]
236
- )
237
-
238
- code_drawer.close(
239
- fn=lambda: gr.update(open=False),
240
- inputs=[],
241
- outputs=[code_drawer]
242
- )
243
-
244
- historyBtn.click(
245
- fn=history_render,
246
- inputs=[history],
247
- outputs=[history_drawer, history_output]
248
- )
249
-
250
- history_drawer.close(
251
- fn=lambda: gr.update(open=False),
252
- inputs=[],
253
- outputs=[history_drawer]
254
- )
255
 
256
  btn.click(
257
- fn=generation_code,
258
  inputs=[input, setting, history],
259
  outputs=[code_output, history, sandbox, state_tab, code_drawer]
260
  )
261
 
262
- clear_btn.click(
263
- fn=clear_history,
264
- inputs=[],
265
- outputs=[history]
266
- )
267
 
268
 
269
  if __name__ == "__main__":
270
- demo = gr.Blocks(css_paths="app.css")
271
- with demo:
272
- app
273
- demo.queue(default_concurrency_limit=20).launch(ssr_mode=False)
 
143
  except Exception as e:
144
  raise ValueError(f'Error calling Claude API: {str(e)}')
145
 
146
+
147
  with ms.Application() as app:
148
  with antd.ConfigProvider():
149
+ # ๋ฉ”์ธ ์ปจํ…์ธ ๋ฅผ ์œ„ํ•œ Row
150
+ with antd.Row(gutter=[32, 12]) as layout:
151
  # ์ขŒ์ธก ํŒจ๋„
152
  with antd.Col(span=24, md=8):
153
  with antd.Flex(vertical=True, gap="middle", wrap=True):
 
166
  btn = antd.Button("send", type="primary", size="large")
167
  clear_btn = antd.Button("clear history", type="default", size="large")
168
 
169
+ # Modal๊ณผ Drawer ์ปดํฌ๋„ŒํŠธ๋“ค
170
+ with antd.Modal(open=False, title="set system Prompt", width="800px") as system_prompt_modal:
171
+ systemPromptInput = antd.InputTextarea(
172
+ SystemPrompt, auto_size=True)
173
+
174
+ with antd.Drawer(open=False, title="code", placement="left", width="750px") as code_drawer:
175
+ code_output = legacy.Markdown()
176
+
177
+ with antd.Drawer(open=False, title="history", placement="left", width="900px") as history_drawer:
178
+ history_output = legacy.Chatbot(show_label=False, flushing=False, height=960, elem_classes="history_chatbot")
179
+
180
  # ์šฐ์ธก ํŒจ๋„
181
  with antd.Col(span=24, md=16):
 
 
 
 
 
 
 
182
  with ms.Div(elem_classes="right_panel"):
183
+ with antd.Flex(gap="small", elem_classes="setting-buttons"):
184
+ settingPromptBtn = antd.Button(
185
+ "โš™๏ธ set system Prompt", type="default")
186
+ codeBtn = antd.Button("๐Ÿง‘โ€๐Ÿ’ป view code", type="default")
187
+ historyBtn = antd.Button("๐Ÿ“œ history", type="default")
188
+
189
  gr.HTML('<div class="render_header"><span class="header_btn"></span><span class="header_btn"></span><span class="header_btn"></span></div>')
190
  with antd.Tabs(active_key="empty", render_tab_bar="() => null") as state_tab:
191
  with antd.Tabs.Item(key="empty"):
192
  empty = antd.Empty(description="empty input", elem_classes="right_content")
193
+ with antd.Tabs.Item(key="loading"):
194
+ loading = antd.Spin(True, tip="coding...", size="large", elem_classes="right_content")
195
+ with antd.Tabs.Item(key="render"):
196
+ sandbox = gr.HTML(elem_classes="html_content")
197
 
198
+ # Examples ์„น์…˜์„ ๋ณ„๋„์˜ Row๋กœ ์ถ”๊ฐ€ (์ „์ฒด ํ™”๋ฉด ํ•˜๋‹จ)
199
+ with antd.Row(gutter=[0, 24], elem_classes="examples-section"):
200
  with antd.Col(span=24):
201
  antd.Divider("examples")
202
+ with antd.Row(gutter=[16, 16]):
203
+ with ms.Each(DEMO_LIST):
204
+ with antd.Col(span=8): # ํ•œ ์ค„์— 3๊ฐœ์”ฉ (24/3 = 8)
205
+ with antd.Card(hoverable=True, as_item="card") as demoCard:
206
+ antd.CardMeta()
207
+ demoCard.click(demo_card_click, outputs=[input])
208
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  # ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
210
+ settingPromptBtn.click(lambda: gr.update(
211
+ open=True), inputs=[], outputs=[system_prompt_modal])
212
+ system_prompt_modal.ok(lambda input: ({"system": input}, gr.update(
213
+ open=False)), inputs=[systemPromptInput], outputs=[setting, system_prompt_modal])
214
+ system_prompt_modal.cancel(lambda: gr.update(
215
+ open=False), outputs=[system_prompt_modal])
216
+
217
+ codeBtn.click(lambda: gr.update(open=True),
218
+ inputs=[], outputs=[code_drawer])
219
+ code_drawer.close(lambda: gr.update(
220
+ open=False), inputs=[], outputs=[code_drawer])
221
+
222
+ historyBtn.click(history_render, inputs=[history], outputs=[history_drawer, history_output])
223
+ history_drawer.close(lambda: gr.update(
224
+ open=False), inputs=[], outputs=[history_drawer])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
 
226
  btn.click(
227
+ generation_code,
228
  inputs=[input, setting, history],
229
  outputs=[code_output, history, sandbox, state_tab, code_drawer]
230
  )
231
 
232
+ clear_btn.click(clear_history, inputs=[], outputs=[history])
 
 
 
 
233
 
234
 
235
  if __name__ == "__main__":
236
+ demo.queue(default_concurrency_limit=20).launch(ssr_mode=False)