seawolf2357 commited on
Commit
415b9f1
ยท
verified ยท
1 Parent(s): 42d9192

Update app-backup1.py

Browse files
Files changed (1) hide show
  1. app-backup1.py +94 -27
app-backup1.py CHANGED
@@ -131,20 +131,19 @@ with gr.Blocks(css_paths="app.css") as demo:
131
  except Exception as e:
132
  print(f"Error details: {str(e)}") # ๋””๋ฒ„๊น…์„ ์œ„ํ•œ ์—๋Ÿฌ ์ถœ๋ ฅ
133
  raise ValueError(f'Error calling Claude API: {str(e)}')
134
-
135
-
136
 
137
  with ms.Application() as app:
138
  with antd.ConfigProvider():
 
139
  with antd.Row(gutter=[32, 12]) as layout:
140
-
141
- # ์ขŒ์ธก ํŒจ๋„ ๋ถ€๋ถ„ ์ˆ˜์ •
142
  with antd.Col(span=24, md=8):
143
  with antd.Flex(vertical=True, gap="middle", wrap=True):
144
  header = gr.HTML(f"""
145
  <div class="left_header">
146
  <img src="data:image/gif;base64,{get_image_base64('mouse.gif')}" width="360px" />
147
- <h1 style="font-size: 20px;">AI ์ฝ”๋”ฉ ์ฝ”ํŒŒ์ผ๋Ÿฟ: MOUSE(WEB)</h2>
 
148
  </div>
149
  """)
150
  input = antd.InputTextarea(
@@ -153,28 +152,44 @@ with gr.Blocks(css_paths="app.css") as demo:
153
  placeholder=random.choice(DEMO_LIST)['description']
154
  )
155
 
156
- btn = antd.Button("send", type="primary", size="large")
157
- clear_btn = antd.Button("clear history", type="default", size="large")
 
 
 
 
 
 
158
 
159
- # Examples ๋ฒ„ํŠผ ์ถ”๊ฐ€
160
- antd.Divider("Try this example")
 
 
 
 
 
 
 
 
 
 
161
 
162
- example_btn = antd.Button(
 
163
  "๋‹ค์ด๋‚˜๋ฏน ์ฐจํŠธ ๋Œ€์‰ฌ๋ณด๋“œ",
164
  type="default",
165
- block=True, # ์ „์ฒด ๋„ˆ๋น„ ์‚ฌ์šฉ
166
  size="large"
167
  )
168
- example_btn.click(
169
  fn=lambda: "Create an interactive dashboard with Chart.js showing different types of charts (line, bar, pie) with smooth animations. Include buttons to switch between different data views.",
170
  inputs=[],
171
  outputs=[input]
172
  )
173
 
174
-
175
- # ๋‘ ๋ฒˆ์งธ ์˜ˆ์ œ ๋ฒ„ํŠผ
176
  example_btn2 = antd.Button(
177
- "์นด๋“œ ๊ธฐ์–ต ๊ฒŒ์ž„",
178
  type="default",
179
  block=True,
180
  size="large"
@@ -185,22 +200,55 @@ with gr.Blocks(css_paths="app.css") as demo:
185
  outputs=[input]
186
  )
187
 
188
-
189
- with antd.Modal(open=False, title="set system Prompt", width="800px") as system_prompt_modal:
190
- systemPromptInput = antd.InputTextarea(
191
- SystemPrompt, auto_size=True)
 
 
 
 
 
 
 
 
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  with antd.Drawer(open=False, title="code", placement="left", width="750px") as code_drawer:
194
  code_output = legacy.Markdown()
195
 
196
  with antd.Drawer(open=False, title="history", placement="left", width="900px") as history_drawer:
197
  history_output = legacy.Chatbot(show_label=False, flushing=False, height=960, elem_classes="history_chatbot")
198
 
 
199
  with antd.Col(span=24, md=16):
200
  with ms.Div(elem_classes="right_panel"):
201
  with antd.Flex(gap="small", elem_classes="setting-buttons"):
202
- settingPromptBtn = antd.Button(
203
- "โš™๏ธ set system Prompt", type="default")
204
  codeBtn = antd.Button("๐Ÿง‘โ€๐Ÿ’ป view code", type="default")
205
  historyBtn = antd.Button("๐Ÿ“œ history", type="default")
206
 
@@ -213,12 +261,31 @@ with gr.Blocks(css_paths="app.css") as demo:
213
  with antd.Tabs.Item(key="render"):
214
  sandbox = gr.HTML(elem_classes="html_content")
215
 
216
- settingPromptBtn.click(lambda: gr.update(
217
- open=True), inputs=[], outputs=[system_prompt_modal])
218
- system_prompt_modal.ok(lambda input: ({"system": input}, gr.update(
219
- open=False)), inputs=[systemPromptInput], outputs=[setting, system_prompt_modal])
220
- system_prompt_modal.cancel(lambda: gr.update(
221
- open=False), outputs=[system_prompt_modal])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
 
223
  codeBtn.click(lambda: gr.update(open=True),
224
  inputs=[], outputs=[code_drawer])
 
131
  except Exception as e:
132
  print(f"Error details: {str(e)}") # ๋””๋ฒ„๊น…์„ ์œ„ํ•œ ์—๋Ÿฌ ์ถœ๋ ฅ
133
  raise ValueError(f'Error calling Claude API: {str(e)}')
 
 
134
 
135
  with ms.Application() as app:
136
  with antd.ConfigProvider():
137
+ # ๋ฉ”์ธ ์ปจํ…์ธ ๋ฅผ ์œ„ํ•œ Row
138
  with antd.Row(gutter=[32, 12]) as layout:
139
+ # ์ขŒ์ธก ํŒจ๋„
 
140
  with antd.Col(span=24, md=8):
141
  with antd.Flex(vertical=True, gap="middle", wrap=True):
142
  header = gr.HTML(f"""
143
  <div class="left_header">
144
  <img src="data:image/gif;base64,{get_image_base64('mouse.gif')}" width="360px" />
145
+ <h1 style="font-size: 18px;">๊ณ ์–‘์ด๋„ ๋ฐœ๋กœ ์ฝ”๋”ฉํ•˜๋Š” 'MOUSE-I'</h2>
146
+ <h1 style="font-size: 10px;">์ž…๋ ฅ์—†์ด 'Send' ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ๋žœ๋คํ•œ ์˜ˆ์ œ ์ฝ”๋“œ ์ƒ์„ฑ. ์ƒ์„ฑ๋œ ์ฝ”๋“œ๋งŒ ํ”„๋กฌํ”„ํŠธ์— ๋ถ™์—ฌ๋„ฃ๊ณ  'Code ์‹คํ–‰' ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ํ™”๋ฉด์— ์ฆ‰์‹œ ์„œ๋น„์Šค๊ฐ€ ์‹คํ–‰. ๋ฌธ์˜: [email protected] </h2>
147
  </div>
148
  """)
149
  input = antd.InputTextarea(
 
152
  placeholder=random.choice(DEMO_LIST)['description']
153
  )
154
 
155
+ # ๋ฒ„ํŠผ๋“ค์„ ๊ฐ€๋กœ๋กœ ๋ฐฐ์น˜ํ•˜๊ธฐ ์œ„ํ•œ Flex ์ปจํ…Œ์ด๋„ˆ
156
+ with antd.Flex(gap="small", justify="space-between"):
157
+ btn = antd.Button("Send", type="primary", size="large")
158
+ execute_btn = antd.Button("Code ์‹คํ–‰", type="default", size="large")
159
+ clear_btn = antd.Button("Clear", type="default", size="large")
160
+
161
+ # Examples ๋ฒ„ํŠผ๋“ค ์ถ”๊ฐ€
162
+ antd.Divider("Try these examples")
163
 
164
+ # ๋‘ ๋ฒˆ์งธ ์˜ˆ์ œ ๋ฒ„ํŠผ
165
+ example_btn0 = antd.Button(
166
+ "MBTI ์ง„๋‹จ ์„œ๋น„์Šค",
167
+ type="default",
168
+ block=True,
169
+ size="large"
170
+ )
171
+ example_btn0.click(
172
+ fn=lambda: "MBTI ์ง„๋‹จ์„ ์œ„ํ•ด 15๊ฐœ์˜ ์งˆ๋ฌธ๊ณผ ๊ฐ๊ด€์‹ ๋‹ต๋ณ€์„ ํ†ตํ•ด MBTI ์ง„๋‹จ ๊ฒฐ๊ณผ ๋ฐ ํ•ด๋‹น ์„ฑ๊ฒฉ์— ๋Œ€ํ•œ ์ƒ์„ธํ•œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๋ผ",
173
+ inputs=[],
174
+ outputs=[input]
175
+ )
176
 
177
+ # ์ฒซ ๋ฒˆ์งธ ์˜ˆ์ œ ๋ฒ„ํŠผ
178
+ example_btn1 = antd.Button(
179
  "๋‹ค์ด๋‚˜๋ฏน ์ฐจํŠธ ๋Œ€์‰ฌ๋ณด๋“œ",
180
  type="default",
181
+ block=True,
182
  size="large"
183
  )
184
+ example_btn1.click(
185
  fn=lambda: "Create an interactive dashboard with Chart.js showing different types of charts (line, bar, pie) with smooth animations. Include buttons to switch between different data views.",
186
  inputs=[],
187
  outputs=[input]
188
  )
189
 
190
+ # ๋‘ ๋ฒˆ์งธ ์˜ˆ์ œ ๋ฒ„ํŠผ
 
191
  example_btn2 = antd.Button(
192
+ "[๊ฒŒ์ž„] ์นด๋“œ ๊ธฐ์–ต๋ ฅ",
193
  type="default",
194
  block=True,
195
  size="large"
 
200
  outputs=[input]
201
  )
202
 
203
+ # ๋‘ ๋ฒˆ์งธ ์˜ˆ์ œ ๋ฒ„ํŠผ
204
+ example_btn3 = antd.Button(
205
+ "ํƒ€๋กœ์นด๋“œ ์šด์ƒˆ",
206
+ type="default",
207
+ block=True,
208
+ size="large"
209
+ )
210
+ example_btn3.click(
211
+ fn=lambda: "ํƒ€๋กœ์นด๋“œ ์šด์„ธ๋ฅผ ์ ์น˜๋Š”๊ฒƒ์„ ์ƒ์„ฑํ•˜๋ผ. ์•„์ฃผ ์ƒ์„ธํ•˜๊ณ  ์ „๋ฌธ์ ์ด๋ฉด์„œ ์‰ฝ๊ณ  ๊ธธ๊ฒŒ ๋‹ต๋ณ€ํ•˜๋ผ. ๋ชจ๋“  ๋‹ต๋ณ€๊ณผ ์„ค๋ช…์€ ํ•œ๊ธ€๋กœ ํ•˜๋ผ",
212
+ inputs=[],
213
+ outputs=[input]
214
+ )
215
 
216
+ # ๋‘ ๋ฒˆ์งธ ์˜ˆ์ œ ๋ฒ„ํŠผ
217
+ example_btn4 = antd.Button(
218
+ "[๊ฒŒ์ž„] ํ…ŒํŠธ๋ฆฌ์Šค",
219
+ type="default",
220
+ block=True,
221
+ size="large"
222
+ )
223
+ example_btn4.click(
224
+ fn=lambda: "Classic Tetris Game: Start๊ณผ ReStart ๋ฒ„ํŠผ๊ณผ ๊ธฐ๋Šฅ ์ ์šฉ, Game Over(๋ง‰๋Œ€๊ฐ€ ๊ฐ€์žฅ ์ƒ๋‹จ๊นŒ์ง€ ๋ˆ„์ ํ•ด์„œ ์Œ“์˜€์„๋•Œ), ๋ง‰๋Œ€๊ฐ€ ํ•œ์ค„ ๊ฐ€๋“ ์ฑ„์›Œ์กŒ์„๋•Œ ํ•œ์ค„์ด ์‚ญ์ œ, ๋–จ์–ด์ง„ ๋ง‰๋Œ€๋Š” ์‚ฌ๋ผ์ง€์ง€ ์•Š๊ณ  ๋ฐ˜๋“œ์‹œ ๋ˆ„์ ํ•ด์„œ ์Œ“์„๊ฒƒ. ๋ง‰๋Œ€ ์šฐ์ธก/์ขŒ์ธก/๋‚ด๋ฆฌ๊ธฐ(space)/๋ง‰๋Œ€์˜ ์ž์ฒด ๋ชจ์–‘๋งŒ ๋ฐ”๊ฟˆ(up) ๋ฒ„ํŠผ ์ง€์›, ๋‚˜๋จธ์ง€๋Š” Tetris ๊ธฐ๋ณธ ๊ทœ์น™์„ ๋”ฐ๋ฆ„",
225
+ inputs=[],
226
+ outputs=[input]
227
+ )
228
+
229
+ example_btn5 = antd.Button(
230
+ "ํ…์ŠคํŠธ๋กœ ์Œ์„ฑ ์ƒ์„ฑ ๋ฐ ์กฐ์ •",
231
+ type="default",
232
+ block=True,
233
+ size="large"
234
+ )
235
+ example_btn5.click(
236
+ fn=lambda: "ํ…์ŠคํŠธ๋ฅผ ์Œ์„ฑ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ , ์Œ์„ฑ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ๋Š” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•˜์„ธ์š”.",
237
+ inputs=[],
238
+ outputs=[input]
239
+ )
240
+
241
+ # Drawer ์ปดํฌ๋„ŒํŠธ๋“ค
242
  with antd.Drawer(open=False, title="code", placement="left", width="750px") as code_drawer:
243
  code_output = legacy.Markdown()
244
 
245
  with antd.Drawer(open=False, title="history", placement="left", width="900px") as history_drawer:
246
  history_output = legacy.Chatbot(show_label=False, flushing=False, height=960, elem_classes="history_chatbot")
247
 
248
+ # ์šฐ์ธก ํŒจ๋„
249
  with antd.Col(span=24, md=16):
250
  with ms.Div(elem_classes="right_panel"):
251
  with antd.Flex(gap="small", elem_classes="setting-buttons"):
 
 
252
  codeBtn = antd.Button("๐Ÿง‘โ€๐Ÿ’ป view code", type="default")
253
  historyBtn = antd.Button("๐Ÿ“œ history", type="default")
254
 
 
261
  with antd.Tabs.Item(key="render"):
262
  sandbox = gr.HTML(elem_classes="html_content")
263
 
264
+ # Code ์‹คํ–‰ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
265
+ def execute_code(query: str):
266
+ if not query or query.strip() == '':
267
+ return None, gr.update(active_key="empty")
268
+
269
+ try:
270
+ # HTML ์ฝ”๋“œ ๋ธ”๋ก ํ™•์ธ
271
+ if '```html' in query and '```' in query:
272
+ # HTML ์ฝ”๋“œ ๋ธ”๋ก ์ถ”์ถœ
273
+ code = remove_code_block(query)
274
+ else:
275
+ # ์ž…๋ ฅ๋œ ํ…์ŠคํŠธ๋ฅผ ๊ทธ๋Œ€๋กœ ์ฝ”๋“œ๋กœ ์‚ฌ์šฉ
276
+ code = query.strip()
277
+
278
+ return send_to_sandbox(code), gr.update(active_key="render")
279
+ except Exception as e:
280
+ print(f"Error executing code: {str(e)}")
281
+ return None, gr.update(active_key="empty")
282
+
283
+ # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ๋“ค
284
+ execute_btn.click(
285
+ fn=execute_code,
286
+ inputs=[input],
287
+ outputs=[sandbox, state_tab]
288
+ )
289
 
290
  codeBtn.click(lambda: gr.update(open=True),
291
  inputs=[], outputs=[code_drawer])