Update app-backup1.py
Browse files- 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:
|
|
|
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 |
-
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
-
|
160 |
-
antd.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
-
|
|
|
163 |
"๋ค์ด๋๋ฏน ์ฐจํธ ๋์ฌ๋ณด๋",
|
164 |
type="default",
|
165 |
-
block=True,
|
166 |
size="large"
|
167 |
)
|
168 |
-
|
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 |
-
|
190 |
-
|
191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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])
|