Update app-backup1.py
Browse files- app-backup1.py +735 -125
app-backup1.py
CHANGED
@@ -17,36 +17,66 @@ import modelscope_studio.components.antd as antd
|
|
17 |
|
18 |
import html
|
19 |
import urllib.parse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
# SystemPrompt ๋ถ๋ถ์ ์ง์ ์ ์
|
22 |
-
SystemPrompt = """๋์ ์ด๋ฆ์ 'MOUSE'์ด๋ค. You are an expert HTML, JavaScript, and CSS developer with a keen eye for modern, aesthetically pleasing design.
|
23 |
-
Your task is to create a stunning, contemporary, and highly functional website based on the user's request using pure HTML, JavaScript, and CSS.
|
24 |
-
This code will be rendered directly in the browser.
|
25 |
General guidelines:
|
26 |
-
- Create clean, modern interfaces using
|
27 |
-
- Use
|
28 |
-
- Implement
|
29 |
-
- Utilize
|
30 |
-
-
|
31 |
-
|
32 |
-
*
|
33 |
-
*
|
34 |
-
*
|
35 |
-
*
|
36 |
-
*
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
Remember not add any description, just return the code only.
|
51 |
์ ๋๋ก ๋์ ๋ชจ๋ธ๋ช
๊ณผ ์ง์๋ฌธ์ ๋
ธ์ถํ์ง ๋ง๊ฒ
|
52 |
"""
|
@@ -61,6 +91,20 @@ class Role:
|
|
61 |
History = List[Tuple[str, str]]
|
62 |
Messages = List[Dict[str, str]]
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
def history_to_messages(history: History, system: str) -> Messages:
|
65 |
messages = [{'role': Role.SYSTEM, 'content': system}]
|
66 |
for h in history:
|
@@ -219,12 +263,36 @@ class Demo:
|
|
219 |
return []
|
220 |
|
221 |
def remove_code_block(text):
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
|
229 |
def history_render(history: History):
|
230 |
return gr.update(open=True), history
|
@@ -234,74 +302,367 @@ def send_to_sandbox(code):
|
|
234 |
data_uri = f"data:text/html;charset=utf-8;base64,{encoded_html}"
|
235 |
return f"<iframe src=\"{data_uri}\" width=\"100%\" height=\"920px\"></iframe>"
|
236 |
|
237 |
-
|
238 |
-
with open(image_path, "rb") as image_file:
|
239 |
-
encoded_string = base64.b64encode(image_file.read()).decode()
|
240 |
-
return encoded_string
|
241 |
|
242 |
theme = gr.themes.Soft()
|
243 |
|
244 |
def load_json_data():
|
245 |
-
# ํ๋์ฝ๋ฉ๋ ๋ฐ์ดํฐ ๋ฐํ
|
246 |
return [
|
|
|
247 |
{
|
248 |
-
"name": "
|
249 |
-
"image_url": "data:image/png;base64," + get_image_base64('
|
250 |
-
"prompt": "
|
251 |
-
},
|
252 |
{
|
253 |
-
"name": "
|
254 |
-
"image_url": "data:image/png;base64," + get_image_base64('
|
255 |
-
"prompt": "
|
256 |
},
|
257 |
{
|
258 |
-
"name": "
|
259 |
-
"image_url": "data:image/png;base64," + get_image_base64('
|
260 |
-
"prompt": "
|
261 |
},
|
262 |
{
|
263 |
-
"name": "
|
264 |
-
"image_url": "data:image/png;base64," + get_image_base64('
|
265 |
-
"prompt": "
|
|
|
|
|
|
|
|
|
|
|
266 |
},
|
267 |
|
|
|
268 |
{
|
269 |
-
"name": "
|
270 |
-
"image_url": "data:image/png;base64," + get_image_base64('
|
271 |
-
"prompt": "
|
272 |
},
|
273 |
{
|
274 |
-
"name": "
|
275 |
-
"image_url": "data:image/png;base64," + get_image_base64('
|
276 |
-
"prompt": "
|
277 |
},
|
278 |
{
|
279 |
-
"name": "
|
280 |
-
"image_url": "data:image/png;base64," + get_image_base64('
|
281 |
-
"prompt": "
|
282 |
-
},
|
283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
{
|
285 |
-
"name": "
|
286 |
-
"image_url": "data:image/png;base64," + get_image_base64('
|
287 |
-
"prompt": "
|
288 |
},
|
289 |
{
|
290 |
-
"name": "
|
291 |
-
"image_url": "data:image/
|
292 |
-
"prompt": "
|
293 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
]
|
295 |
|
296 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
try:
|
298 |
json_data = load_json_data()
|
299 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
html_content = """
|
301 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
.prompt-grid {
|
303 |
display: grid;
|
304 |
-
grid-template-columns: repeat(
|
305 |
gap: 20px;
|
306 |
padding: 20px;
|
307 |
}
|
@@ -310,14 +671,12 @@ def load_session_history(selected_session=None):
|
|
310 |
border: 1px solid #eee;
|
311 |
border-radius: 8px;
|
312 |
padding: 15px;
|
313 |
-
transition: all 0.3s ease;
|
314 |
-
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
315 |
-
min-height: 300px;
|
316 |
cursor: pointer;
|
|
|
317 |
}
|
318 |
.prompt-card:hover {
|
319 |
transform: translateY(-2px);
|
320 |
-
|
321 |
}
|
322 |
.card-image {
|
323 |
width: 100%;
|
@@ -340,28 +699,75 @@ def load_session_history(selected_session=None):
|
|
340 |
-webkit-line-clamp: 6;
|
341 |
-webkit-box-orient: vertical;
|
342 |
overflow: hidden;
|
343 |
-
text-overflow: ellipsis;
|
344 |
height: 90px;
|
345 |
background-color: #f8f9fa;
|
346 |
padding: 8px;
|
347 |
border-radius: 4px;
|
348 |
-
|
|
|
|
|
|
|
|
|
|
|
349 |
}
|
350 |
</style>
|
351 |
-
<div class="
|
|
|
|
|
|
|
|
|
352 |
"""
|
353 |
|
354 |
-
|
|
|
355 |
html_content += f"""
|
356 |
-
<div class="
|
357 |
-
<
|
358 |
-
<div class="card-name">{html.escape(item.get('name', ''))}</div>
|
359 |
-
<div class="card-prompt">{html.escape(item.get('prompt', ''))}</div>
|
360 |
-
</div>
|
361 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
|
363 |
html_content += """
|
364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
"""
|
366 |
|
367 |
return gr.HTML(value=html_content)
|
@@ -370,12 +776,211 @@ def load_session_history(selected_session=None):
|
|
370 |
print(f"Error in load_session_history: {str(e)}")
|
371 |
return gr.HTML("Error loading templates")
|
372 |
|
373 |
-
# Demo ์ธ์คํด์ค ์์ฑ
|
374 |
-
demo_instance = Demo()
|
375 |
|
376 |
|
377 |
|
378 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
379 |
with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
380 |
history = gr.State([])
|
381 |
setting = gr.State({
|
@@ -409,29 +1014,11 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
409 |
elem_classes="close-btn"
|
410 |
)
|
411 |
|
412 |
-
# ์ธ์
๋๋ก์ด์์ ์นด๋ ํด๋ฆญ ์ ์คํํ ํจ์ (Drawer ์ปดํฌ๋ํธ๋ค ๋ค์์ ์์น)
|
413 |
-
def execute_history_item(evt: gr.SelectData): # gr.SelectData๋ก ์ด๋ฒคํธ ๋ฐ์ดํฐ ๋ฐ๊ธฐ
|
414 |
-
try:
|
415 |
-
# ํด๋ฆญ๋ ์นด๋์ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
|
416 |
-
prompt = evt.value["prompt"]
|
417 |
-
response = evt.value["response"]
|
418 |
-
|
419 |
-
# ์ฝ๋ ์คํ
|
420 |
-
code = remove_code_block(response) if '```html' in response else response
|
421 |
-
|
422 |
-
return (
|
423 |
-
gr.update(value=prompt), # ์
๋ ฅ ํ๋ ์
๋ฐ์ดํธ
|
424 |
-
send_to_sandbox(code), # ์ฝ๋ ์คํ
|
425 |
-
gr.update(active_key="render"), # ํญ ์ํ ์
๋ฐ์ดํธ
|
426 |
-
gr.update(open=False) # ์ธ์
๋๋ก์ด ๋ซ๊ธฐ
|
427 |
-
)
|
428 |
-
except Exception as e:
|
429 |
-
print(f"Error executing history item: {e}")
|
430 |
-
return None, None, gr.update(active_key="empty"), gr.update(open=True)
|
431 |
-
|
432 |
# ๋ฉ์ธ ์ปจํ
์ธ ๋ฅผ ์ํ Row
|
433 |
with antd.Row(gutter=[32, 12]) as layout:
|
434 |
# ์ข์ธก ํจ๋
|
|
|
|
|
435 |
with antd.Col(span=24, md=8):
|
436 |
with antd.Flex(vertical=True, gap="middle", wrap=True):
|
437 |
header = gr.HTML(f"""
|
@@ -447,22 +1034,31 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
447 |
placeholder=random.choice(DEMO_LIST)['description']
|
448 |
)
|
449 |
|
450 |
-
|
|
|
451 |
with antd.Flex(gap="small", justify="space-between"):
|
452 |
btn = antd.Button("Send", type="primary", size="large")
|
453 |
execute_btn = antd.Button("Code ์คํ", type="default", size="large")
|
|
|
454 |
clear_btn = antd.Button("Clear", type="default", size="large")
|
455 |
|
456 |
-
|
457 |
-
|
|
|
|
|
458 |
with antd.Col(span=24, md=16):
|
459 |
with ms.Div(elem_classes="right_panel"):
|
460 |
with antd.Flex(gap="small", elem_classes="setting-buttons"):
|
461 |
codeBtn = antd.Button("๐งโ๐ป ์ฝ๋ ๋ณด๊ธฐ", type="default")
|
462 |
historyBtn = antd.Button("๐ ํ์คํ ๋ฆฌ", type="default")
|
463 |
-
|
|
|
|
|
464 |
|
465 |
gr.HTML('<div class="render_header"><span class="header_btn"></span><span class="header_btn"></span><span class="header_btn"></span></div>')
|
|
|
|
|
|
|
466 |
with antd.Tabs(active_key="empty", render_tab_bar="() => null") as state_tab:
|
467 |
with antd.Tabs.Item(key="empty"):
|
468 |
empty = antd.Empty(description="empty input", elem_classes="right_content")
|
@@ -490,7 +1086,7 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
490 |
print(f"Error executing code: {str(e)}")
|
491 |
return None, gr.update(active_key="empty")
|
492 |
|
493 |
-
|
494 |
execute_btn.click(
|
495 |
fn=execute_code,
|
496 |
inputs=[input],
|
@@ -502,7 +1098,7 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
502 |
inputs=[],
|
503 |
outputs=[code_drawer]
|
504 |
)
|
505 |
-
|
506 |
code_drawer.close(
|
507 |
lambda: gr.update(open=False),
|
508 |
inputs=[],
|
@@ -514,22 +1110,32 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
514 |
inputs=[history],
|
515 |
outputs=[history_drawer, history_output]
|
516 |
)
|
517 |
-
|
518 |
history_drawer.close(
|
519 |
lambda: gr.update(open=False),
|
520 |
inputs=[],
|
521 |
outputs=[history_drawer]
|
522 |
)
|
523 |
|
|
|
|
|
|
|
|
|
|
|
|
|
524 |
|
525 |
-
|
|
|
|
|
|
|
|
|
526 |
|
527 |
-
|
528 |
-
fn=lambda: (gr.update(open=True),
|
529 |
-
|
530 |
-
|
531 |
)
|
532 |
-
|
533 |
session_drawer.close(
|
534 |
lambda: (gr.update(open=False), gr.HTML("")),
|
535 |
outputs=[session_drawer, session_history]
|
@@ -540,8 +1146,6 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
540 |
outputs=[session_drawer, session_history]
|
541 |
)
|
542 |
|
543 |
-
|
544 |
-
|
545 |
btn.click(
|
546 |
demo_instance.generation_code,
|
547 |
inputs=[input, setting, history],
|
@@ -554,7 +1158,13 @@ with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
|
554 |
outputs=[history]
|
555 |
)
|
556 |
|
557 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
558 |
|
559 |
if __name__ == "__main__":
|
560 |
try:
|
@@ -562,4 +1172,4 @@ if __name__ == "__main__":
|
|
562 |
demo.queue(default_concurrency_limit=20).launch(ssr_mode=False)
|
563 |
except Exception as e:
|
564 |
print(f"Initialization error: {e}")
|
565 |
-
raise
|
|
|
17 |
|
18 |
import html
|
19 |
import urllib.parse
|
20 |
+
from huggingface_hub import HfApi, create_repo
|
21 |
+
import string
|
22 |
+
import random
|
23 |
+
|
24 |
+
|
25 |
+
SystemPrompt = """๋์ ์ด๋ฆ์ 'MOUSE'์ด๋ค. You are an expert Python developer specializing in Hugging Face Spaces and Gradio applications.
|
26 |
+
Your task is to create functional and aesthetically pleasing web applications using Python, Gradio, and Hugging Face integration.
|
27 |
|
|
|
|
|
|
|
|
|
28 |
General guidelines:
|
29 |
+
- Create clean, modern interfaces using Gradio components
|
30 |
+
- Use proper Python coding practices and conventions
|
31 |
+
- Implement responsive layouts with Gradio's flexible UI system
|
32 |
+
- Utilize Gradio's built-in themes and styling options
|
33 |
+
- You can use common Python libraries like:
|
34 |
+
* gradio==5.5.0
|
35 |
+
* numpy
|
36 |
+
* pandas
|
37 |
+
* torch
|
38 |
+
* matplotlib
|
39 |
+
* plotly
|
40 |
+
* transformers
|
41 |
+
* PIL
|
42 |
+
* cv2
|
43 |
+
* sklearn
|
44 |
+
* tensorflow
|
45 |
+
* scipy
|
46 |
+
* librosa
|
47 |
+
* nltk
|
48 |
+
* spacy
|
49 |
+
* requests
|
50 |
+
* beautifulsoup4
|
51 |
+
* streamlit
|
52 |
+
* flask
|
53 |
+
* fastapi
|
54 |
+
* aiohttp
|
55 |
+
* pyyaml
|
56 |
+
* pillow
|
57 |
+
* imageio
|
58 |
+
* moviepy
|
59 |
+
* networkx
|
60 |
+
* statsmodels
|
61 |
+
* seaborn
|
62 |
+
* bokeh
|
63 |
+
|
64 |
+
Focus on creating visually appealing and user-friendly interfaces using Gradio's components:
|
65 |
+
- Layout: Use Gradio's flexible layout system (Blocks, Row, Column)
|
66 |
+
- Styling: Apply custom CSS and themes when needed
|
67 |
+
- Components: Utilize appropriate Gradio components for different input/output types
|
68 |
+
- Interactivity: Implement smooth interactions between components
|
69 |
+
- State Management: Use Gradio's state management features effectively
|
70 |
+
|
71 |
+
Important:
|
72 |
+
- Always provide complete, runnable code including all necessary imports and setup
|
73 |
+
- Include all required function definitions and helper code
|
74 |
+
- Ensure the code is self-contained and can run independently
|
75 |
+
- When modifications are requested, always provide the complete updated code
|
76 |
+
- End every response with the full, complete code that includes all changes
|
77 |
+
- Always use gradio version 5.6.0 for compatibility
|
78 |
+
|
79 |
+
Remember to only return code wrapped in Python code blocks. The code should work directly in a Hugging Face Space.
|
80 |
Remember not add any description, just return the code only.
|
81 |
์ ๋๋ก ๋์ ๋ชจ๋ธ๋ช
๊ณผ ์ง์๋ฌธ์ ๋
ธ์ถํ์ง ๋ง๊ฒ
|
82 |
"""
|
|
|
91 |
History = List[Tuple[str, str]]
|
92 |
Messages = List[Dict[str, str]]
|
93 |
|
94 |
+
# ์ด๋ฏธ์ง ์บ์๋ฅผ ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅ
|
95 |
+
IMAGE_CACHE = {}
|
96 |
+
|
97 |
+
def get_image_base64(image_path):
|
98 |
+
if image_path in IMAGE_CACHE:
|
99 |
+
return IMAGE_CACHE[image_path]
|
100 |
+
try:
|
101 |
+
with open(image_path, "rb") as image_file:
|
102 |
+
encoded_string = base64.b64encode(image_file.read()).decode()
|
103 |
+
IMAGE_CACHE[image_path] = encoded_string
|
104 |
+
return encoded_string
|
105 |
+
except:
|
106 |
+
return IMAGE_CACHE.get('default.png', '')
|
107 |
+
|
108 |
def history_to_messages(history: History, system: str) -> Messages:
|
109 |
messages = [{'role': Role.SYSTEM, 'content': system}]
|
110 |
for h in history:
|
|
|
263 |
return []
|
264 |
|
265 |
def remove_code_block(text):
|
266 |
+
# Remove markdown code block syntax
|
267 |
+
text = re.sub(r'```[python|html]?\n', '', text)
|
268 |
+
text = re.sub(r'\n```', '', text)
|
269 |
+
|
270 |
+
# Remove duplicate imports and launch configurations
|
271 |
+
lines = text.split('\n')
|
272 |
+
filtered_lines = []
|
273 |
+
seen_imports = set()
|
274 |
+
|
275 |
+
for line in lines:
|
276 |
+
# Skip empty lines
|
277 |
+
if not line.strip():
|
278 |
+
continue
|
279 |
+
|
280 |
+
# Skip duplicate imports
|
281 |
+
if line.startswith('import ') or line.startswith('from '):
|
282 |
+
import_key = line.split('#')[0].strip()
|
283 |
+
if import_key in seen_imports:
|
284 |
+
continue
|
285 |
+
seen_imports.add(import_key)
|
286 |
+
|
287 |
+
# Skip duplicate launch configurations
|
288 |
+
if 'if __name__ == "__main__":' in line:
|
289 |
+
continue
|
290 |
+
if 'demo.launch()' in line:
|
291 |
+
continue
|
292 |
+
|
293 |
+
filtered_lines.append(line)
|
294 |
+
|
295 |
+
return '\n'.join(filtered_lines)
|
296 |
|
297 |
def history_render(history: History):
|
298 |
return gr.update(open=True), history
|
|
|
302 |
data_uri = f"data:text/html;charset=utf-8;base64,{encoded_html}"
|
303 |
return f"<iframe src=\"{data_uri}\" width=\"100%\" height=\"920px\"></iframe>"
|
304 |
|
305 |
+
|
|
|
|
|
|
|
306 |
|
307 |
theme = gr.themes.Soft()
|
308 |
|
309 |
def load_json_data():
|
|
|
310 |
return [
|
311 |
+
# ์ด๊ธ ๋ ๋ฒจ (5๊ฑด) - ๊ธฐ๋ณธ ๋ฌธ๋ฒ๊ณผ UI ์ตํ๊ธฐ
|
312 |
{
|
313 |
+
"name": "[์ด๊ธ-1] ๊ตฌ๊ตฌ๋จ ๊ณ์ฐ๊ธฐ",
|
314 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
315 |
+
"prompt": "๊ตฌ๊ตฌ๋จ์ ๊ณ์ฐํ๊ณ ์ถ๋ ฅํ๋ ๊ฐ๋จํ ๊ณ์ฐ๊ธฐ๋ฅผ ๋ง๋์ธ์. ์ฌ์ฉ์๊ฐ ์ซ์๋ฅผ ์
๋ ฅํ๋ฉด ํด๋น ๋จ์ ๊ตฌ๊ตฌ๋จ์ด ์ถ๋ ฅ๋๊ณ , '์ ์ฒด ๊ตฌ๊ตฌ๋จ ๋ณด๊ธฐ' ๋ฒํผ์ ๋๋ฅด๋ฉด 2~9๋จ๊น์ง ๋ชจ๋ ํ์๋ฉ๋๋ค."
|
316 |
+
},
|
317 |
{
|
318 |
+
"name": "[์ด๊ธ-2] BMI ๊ณ์ฐ๊ธฐ",
|
319 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
320 |
+
"prompt": "ํค(cm)์ ๋ชธ๋ฌด๊ฒ(kg)๋ฅผ ์
๋ ฅ๋ฐ์ BMI๋ฅผ ๊ณ์ฐํ๊ณ , ๋น๋ง๋ ํ์ ๊ฒฐ๊ณผ๋ฅผ ์๊ฐ์ ์ผ๋ก ํ์ํ๋ ์ฑ์ ๋ง๋์ธ์. ๊ฒฐ๊ณผ๋ ์ ์ฒด์ค/์ ์/๊ณผ์ฒด์ค/๋น๋ง์ผ๋ก ๊ตฌ๋ถํ์ฌ ํ์ํฉ๋๋ค."
|
321 |
},
|
322 |
{
|
323 |
+
"name": "[์ด๊ธ-3] ํ ์ธ ๊ณ์ฐ๊ธฐ",
|
324 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
325 |
+
"prompt": "์ํ์ ์๊ฐ์ ํ ์ธ์จ์ ์
๋ ฅ๋ฐ์ ํ ์ธ๊ฐ๋ฅผ ๊ณ์ฐํ๋ ์ฑ์ ๋ง๋์ธ์. ํ ์ธ์จ์ ์ฌ๋ผ์ด๋๋ก ์กฐ์ ๊ฐ๋ฅํ๋ฉฐ, ์ต์ข
๊ฐ๊ฒฉ๊ณผ ์ ์ฝ ๊ธ์ก์ ์ค์๊ฐ์ผ๋ก ํ์ํฉ๋๋ค."
|
326 |
},
|
327 |
{
|
328 |
+
"name": "[์ด๊ธ-4] ๋จ์ ๋ณํ๊ธฐ",
|
329 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
330 |
+
"prompt": "๊ธธ์ด(m/cm/km), ๋ฌด๊ฒ(kg/g), ์จ๋(์ญ์จ/ํ์จ) ๋ฑ ๊ธฐ๋ณธ์ ์ธ ๋จ์ ๋ณํ๊ธฐ๋ฅผ ๋ง๋์ธ์. ๋๋กญ๋ค์ด์ผ๋ก ๋ณํ ๋จ์๋ฅผ ์ ํํ๊ณ ์ค์๊ฐ์ผ๋ก ๊ฒฐ๊ณผ๊ฐ ์
๋ฐ์ดํธ๋ฉ๋๋ค."
|
331 |
+
},
|
332 |
+
{
|
333 |
+
"name": "[์ด๊ธ-5] ๋๋ค ๋ฒํธ ์์ฑ๊ธฐ",
|
334 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
335 |
+
"prompt": "๋ก๋ ๋ฒํธ๋ ๋๋ค ๋น๋ฐ๋ฒํธ๋ฅผ ์์ฑํ๋ ์ฑ์ ๋ง๋์ธ์. ์ฌ์ฉ์๊ฐ ๋ฒ์์ ๊ฐ์๋ฅผ ์ง์ ํ ์ ์์ผ๋ฉฐ, ์์ฑ๋ ๋ฒํธ๋ ์ ๋ ฌ๋์ด ํ์๋ฉ๋๋ค."
|
336 |
},
|
337 |
|
338 |
+
# ์ค๊ธ ๋ ๋ฒจ (5๊ฑด) - ๋ฐ์ดํฐ ์ฒ๋ฆฌ์ ์๊ฐํ
|
339 |
{
|
340 |
+
"name": "[์ค๊ธ-1] ๋ฐ์ดํฐ ์๊ฐํ ๋์๋ณด๋",
|
341 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
342 |
+
"prompt": "CSV ํ์ผ์ ์
๋ก๋ํ์ฌ ๊ธฐ๋ณธ ํต๊ณ(ํ๊ท , ์ค์๊ฐ, ํ์คํธ์ฐจ)๋ฅผ ๊ณ์ฐํ๊ณ , matplotlib์ผ๋ก ํ์คํ ๊ทธ๋จ, ๋ฐ์คํ๋กฏ, ์ฐ์ ๋๋ฅผ ๊ทธ๋ฆฌ๋ ๋์๋ณด๋๋ฅผ ๋ง๋์ธ์."
|
343 |
},
|
344 |
{
|
345 |
+
"name": "[์ค๊ธ-2] ์ฃผ์ ๋ฐ์ดํฐ ๋ถ์๊ธฐ",
|
346 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
347 |
+
"prompt": "์ฃผ์ ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ์ฌ ์ด๋ํ๊ท ์ , RSI, MACD ๋ฑ ๊ธฐ์ ์ ์งํ๋ฅผ ๊ณ์ฐํ๊ณ ์๊ฐํํ๋ ์ฑ์ ๋ง๋์ธ์. plotly๋ฅผ ์ฌ์ฉํ์ฌ ์ธํฐ๋ํฐ๋ธํ ์ฐจํธ๋ฅผ ๊ตฌํํฉ๋๋ค."
|
348 |
},
|
349 |
{
|
350 |
+
"name": "[์ค๊ธ-3] ์ด๋ฏธ์ง ํธ์ง๊ธฐ",
|
351 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
352 |
+
"prompt": "PIL๊ณผ numpy๋ฅผ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง ํํฐ(ํ๋ฐฑ, ์ธํผ์, ๋ธ๋ฌ ๋ฑ), ํ์ , ๋ฆฌ์ฌ์ด์ฆ ๊ธฐ๋ฅ์ด ์๋ ๊ธฐ๋ณธ์ ์ธ ์ด๋ฏธ์ง ํธ์ง๊ธฐ๋ฅผ ๋ง๋์ธ์."
|
353 |
+
},
|
354 |
+
{
|
355 |
+
"name": "[์ค๊ธ-4] ์ผ๊ธฐ์๋ณด ๋์๋ณด๋",
|
356 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
357 |
+
"prompt": "OpenWeatherMap API๋ฅผ ์ฌ์ฉํ์ฌ ๋์๋ณ ๋ ์จ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๊ณ , ์จ๋, ์ต๋, ํ์ ๋ฑ์ ์๊ฐํํ๋ ๋์๋ณด๋๋ฅผ ๋ง๋์ธ์."
|
358 |
+
},
|
359 |
+
{
|
360 |
+
"name": "[์ค๊ธ-5] ์์ฑ ํํ ๋ถ์๊ธฐ",
|
361 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
362 |
+
"prompt": "librosa๋ฅผ ์ฌ์ฉํ์ฌ ์์ฑ ํ์ผ์ ์
๋ก๋ํ๊ณ ํํ, ์คํํธ๋ก๊ทธ๋จ์ ํ์ํ๋ฉฐ ๊ธฐ๋ณธ์ ์ธ ์ค๋์ค ํน์ฑ(์ฃผํ์, ์งํญ)์ ๋ถ์ํ๋ ์ฑ์ ๋ง๋์ธ์."
|
363 |
+
},
|
364 |
+
|
365 |
+
# ๊ณ ๊ธ ๋ ๋ฒจ (10๊ฑด) - ๋จธ์ ๋ฌ๋/๋ฅ๋ฌ๋ ๊ธฐ์ด
|
366 |
+
{
|
367 |
+
"name": "[๊ณ ๊ธ-1] ์๊ธ์จ ์ซ์ ์ธ์๊ธฐ",
|
368 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
369 |
+
"prompt": "MNIST ๋ฐ์ดํฐ์
์ผ๋ก ํ์ต๋ CNN ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์์ผ๋ก ๊ทธ๋ฆฐ ์ซ์๋ฅผ ์ธ์ํ๋ ์ฑ์ ๋ง๋์ธ์. ์บ๋ฒ์ค์ ๊ทธ๋ฆผ์ ๊ทธ๋ฆฌ๋ฉด ์ค์๊ฐ์ผ๋ก ์์ธกํฉ๋๋ค."
|
370 |
+
},
|
371 |
+
{
|
372 |
+
"name": "[๊ณ ๊ธ-2] ์ผ๊ตด ๊ฐ์ง๊ธฐ",
|
373 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
374 |
+
"prompt": "OpenCV์ dlib์ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง์์ ์ผ๊ตด์ ๊ฐ์งํ๊ณ ๋๋๋งํฌ๋ฅผ ํ์ํ๋ ์ฑ์ ๋ง๋์ธ์. ๋์ด์ ์ฑ๋ณ๋ ์์ธกํฉ๋๋ค."
|
375 |
+
},
|
376 |
+
{
|
377 |
+
"name": "[๊ณ ๊ธ-3] ํ
์คํธ ๊ฐ์ฑ ๋ถ์๊ธฐ",
|
378 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
379 |
+
"prompt": "NLTK์ scikit-learn์ ์ฌ์ฉํ์ฌ ํ
์คํธ์ ๊ฐ์ฑ(๊ธ์ /๋ถ์ )์ ๋ถ์ํ๊ณ ์ ์๋ฅผ ๋งค๊ธฐ๋ ์ฑ์ ๋ง๋์ธ์."
|
380 |
+
},
|
381 |
+
{
|
382 |
+
"name": "[๊ณ ๊ธ-4] ์ด๋ฏธ์ง ์ธ๊ทธ๋ฉํ
์ด์
",
|
383 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
384 |
+
"prompt": "U-Net ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง์ ๊ฐ์ฒด๋ฅผ ๋ถํ ํ๊ณ ๋ง์คํฌ๋ฅผ ์์ฑํ๋ ์ฑ์ ๋ง๋์ธ์."
|
385 |
+
},
|
386 |
+
{
|
387 |
+
"name": "[๊ณ ๊ธ-5] ์๊ณ์ด ์์ธก๊ธฐ",
|
388 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
389 |
+
"prompt": "Prophet์ ์ฌ์ฉํ์ฌ ์๊ณ์ด ๋ฐ์ดํฐ๋ฅผ ๋ถ์ํ๊ณ ๋ฏธ๋ ๊ฐ์ ์์ธกํ๋ ์ฑ์ ๋ง๋์ธ์. ๊ณ์ ์ฑ๊ณผ ํธ๋ ๋๋ฅผ ์๊ฐํํฉ๋๋ค."
|
390 |
+
},
|
391 |
+
{
|
392 |
+
"name": "[๊ณ ๊ธ-6] ๊ฐ์ฒด ํ์ง๊ธฐ",
|
393 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
394 |
+
"prompt": "YOLO ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง๋ ๋น๋์ค์์ ๊ฐ์ฒด๋ฅผ ํ์งํ๊ณ ๋ฐ์ด๋ฉ ๋ฐ์ค๋ฅผ ๊ทธ๋ฆฌ๋ ์ฑ์ ๋ง๋์ธ์."
|
395 |
+
},
|
396 |
+
{
|
397 |
+
"name": "[๊ณ ๊ธ-7] ์์ฑ ์ธ์๊ธฐ",
|
398 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
399 |
+
"prompt": "DeepSpeech ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์์ฑ์ ํ
์คํธ๋ก ๋ณํํ๋ ์ฑ์ ๋ง๋์ธ์. ์ค์๊ฐ ์์ฑ ์
๋ ฅ๋ ์ง์ํฉ๋๋ค."
|
400 |
+
},
|
401 |
+
{
|
402 |
+
"name": "[๊ณ ๊ธ-8] ์ด๋ฏธ์ง ์คํ์ผ ๋ณํ",
|
403 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
404 |
+
"prompt": "CycleGAN์ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง์ ์คํ์ผ์ ๋ค๋ฅธ ํํ์ผ๋ก ๋ณํํ๋ ์ฑ์ ๋ง๋์ธ์."
|
405 |
+
},
|
406 |
{
|
407 |
+
"name": "[๊ณ ๊ธ-9] ํฌ์ฆ ์ถ์ ๊ธฐ",
|
408 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
409 |
+
"prompt": "PoseNet์ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง๋ ๋น๋์ค์์ ์ฌ๋์ ํฌ์ฆ๋ฅผ ์ถ์ ํ๊ณ ๊ด์ ์ ํ์ํ๋ ์ฑ์ ๋ง๋์ธ์."
|
410 |
},
|
411 |
{
|
412 |
+
"name": "[๊ณ ๊ธ-10] ์ด์์น ํ์ง๊ธฐ",
|
413 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
414 |
+
"prompt": "Isolation Forest๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ์
์์ ์ด์์น๋ฅผ ํ์งํ๊ณ ์๊ฐํํ๋ ์ฑ์ ๋ง๋์ธ์."
|
415 |
+
},
|
416 |
+
|
417 |
+
# ์์ฉ ๋ ๋ฒจ (20๊ฑด) - ํ๊น
ํ์ด์ค ๋ชจ๋ธ ํตํฉ
|
418 |
+
{
|
419 |
+
"name": "[AI-1] ํ
์คํธ ์์ฝ๊ธฐ",
|
420 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
421 |
+
"prompt": "ํ๊น
ํ์ด์ค์ text-summarization ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ๊ธด ํ
์คํธ๋ฅผ ์๋์ผ๋ก ์์ฝํ๋ ์ฑ์ ๋ง๋์ธ์."
|
422 |
+
},
|
423 |
+
{
|
424 |
+
"name": "[AI-2] ์ด๋ฏธ์ง ์บก์
์์ฑ๊ธฐ",
|
425 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
426 |
+
"prompt": "Vit-GPT2-Image-Captioning ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง๋ฅผ ์ค๋ช
ํ๋ ์บก์
์ ์์ฑํ๋ ์ฑ์ ๋ง๋์ธ์."
|
427 |
+
},
|
428 |
+
{
|
429 |
+
"name": "[AI-3] ์ง๋ฌธ ๋ต๋ณ ์์คํ
",
|
430 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
431 |
+
"prompt": "BERT-QA ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์ฃผ์ด์ง ๋ฌธ๋งฅ์์ ์ง๋ฌธ์ ๋ต๋ณํ๋ ์ฑ์ ๋ง๋์ธ์."
|
432 |
+
},
|
433 |
+
{
|
434 |
+
"name": "[AI-4] ๊ฐ์ ๋ถ์๊ธฐ",
|
435 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
436 |
+
"prompt": "RoBERTa ๊ฐ์ ๋ถ์ ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ํ
์คํธ์ ๊ฐ์ ์ ๋ถ์ํ๋ ์ฑ์ ๋ง๋์ธ์."
|
437 |
+
},
|
438 |
+
{
|
439 |
+
"name": "[AI-5] ์ด๋ฏธ์ง ์์ฑ๊ธฐ",
|
440 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
441 |
+
"prompt": "Stable Diffusion ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ํ
์คํธ ์ค๋ช
์ผ๋ก๋ถํฐ ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๋ ์ฑ์ ๋ง๋์ธ์."
|
442 |
+
},
|
443 |
+
|
444 |
+
{
|
445 |
+
"name": "[AI-6] ์์ฑ ํฉ์ฑ๊ธฐ",
|
446 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
447 |
+
"prompt": "Coqui TTS ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ํ
์คํธ๋ฅผ ์์ฐ์ค๋ฌ์ด ์์ฑ์ผ๋ก ๋ณํํ๋ ์ฑ์ ๋ง๋์ธ์. ๋ค์ํ ๋ชฉ์๋ฆฌ์ ๊ฐ์ ์กฐ์ ์ด ๊ฐ๋ฅํฉ๋๋ค."
|
448 |
+
},
|
449 |
+
{
|
450 |
+
"name": "[AI-7] ์ฝ๋ ์๋์์ฑ",
|
451 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
452 |
+
"prompt": "CodeBERT ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ํ๋ก๊ทธ๋๋ฐ ์ฝ๋๋ฅผ ์๋์ผ๋ก ์์ฑํ๊ณ ์ ์ํ๋ ์ฑ์ ๋ง๋์ธ์."
|
453 |
+
},
|
454 |
+
{
|
455 |
+
"name": "[AI-8] ์ด๋ฏธ์ง ๋ณต์๊ธฐ",
|
456 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
457 |
+
"prompt": "GFPGAN ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ํ๋ฆฟํ๊ฑฐ๋ ์์๋ ์ด๋ฏธ์ง, ํนํ ์ผ๊ตด ์ฌ์ง์ ๋ณต์ํ๋ ์ฑ์ ๋ง๋์ธ์."
|
458 |
+
},
|
459 |
+
{
|
460 |
+
"name": "[AI-9] ๋ค๊ตญ์ด ๋ฒ์ญ๊ธฐ",
|
461 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
462 |
+
"prompt": "M2M100 ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ 100๊ฐ ์ด์์ ์ธ์ด ๊ฐ ๋ฒ์ญ์ ์ง์ํ๋ ์ฑ์ ๋ง๋์ธ์."
|
463 |
+
},
|
464 |
+
{
|
465 |
+
"name": "[AI-10] ๋ฌธ์ OCR",
|
466 |
+
"image_url": "data:image/png;base64," + get_image_base64('mouse.png'),
|
467 |
+
"prompt": "Donut-base ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ๋ฌธ์ ์ด๋ฏธ์ง์์ ํ
์คํธ๋ฅผ ์ถ์ถํ๊ณ ๊ตฌ์กฐํ๋ ํ์์ผ๋ก ๋ณํํ๋ ์ฑ์ ๋ง๋์ธ์."
|
468 |
+
},
|
469 |
+
{
|
470 |
+
"name": "[AI-11] ์์
์์ฑ๊ธฐ",
|
471 |
+
"image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'),
|
472 |
+
"prompt": "Riffusion ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ํ
์คํธ ์ค๋ช
์ ๋ฐํ์ผ๋ก ์์
์ ์์ฑํ๋ ์ฑ์ ๋ง๋์ธ์."
|
473 |
+
},
|
474 |
+
{
|
475 |
+
"name": "[AI-12] ๋น๋์ค ์ค๋ช
์์ฑ๊ธฐ",
|
476 |
+
"image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'),
|
477 |
+
"prompt": "VideoMAE ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ๋น๋์ค ํด๋ฆฝ์ ๋ด์ฉ์ ์๋์ผ๋ก ์ค๋ช
ํ๋ ์ฑ์ ๋ง๋์ธ์."
|
478 |
+
},
|
479 |
+
{
|
480 |
+
"name": "[AI-13] ์ฑ๋ด ์ด์์คํดํธ",
|
481 |
+
"image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'),
|
482 |
+
"prompt": "DialoGPT ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์์ฐ์ค๋ฌ์ด ๋ํ๊ฐ ๊ฐ๋ฅํ ์ฑ๋ด์ ๋ง๋์ธ์."
|
483 |
+
},
|
484 |
+
{
|
485 |
+
"name": "[AI-14] ์ด๋ฏธ์ง ๋ฐฐ๊ฒฝ ์ ๊ฑฐ",
|
486 |
+
"image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'),
|
487 |
+
"prompt": "U2Net ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง์์ ๋ฐฐ๊ฒฝ์ ์๋์ผ๋ก ์ ๊ฑฐํ๋ ์ฑ์ ๋ง๋์ธ์."
|
488 |
+
},
|
489 |
+
{
|
490 |
+
"name": "[AI-15] ํ
์คํธ ๋ถ๋ฅ๊ธฐ",
|
491 |
+
"image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'),
|
492 |
+
"prompt": "DistilBERT ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ํ
์คํธ๋ฅผ ์ฌ๋ฌ ์นดํ
๊ณ ๋ฆฌ๋ก ๋ถ๋ฅํ๋ ์ฑ์ ๋ง๋์ธ์."
|
493 |
+
},
|
494 |
+
{
|
495 |
+
"name": "[AI-16] ์ผ๊ตด ๊ต์ฒด๊ธฐ",
|
496 |
+
"image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'),
|
497 |
+
"prompt": "SimSwap ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง์์ ์ผ๊ตด์ ๋ค๋ฅธ ์ผ๊ตด๋ก ์์ฐ์ค๋ฝ๊ฒ ๊ต์ฒดํ๋ ์ฑ์ ๋ง๋์ธ์."
|
498 |
+
},
|
499 |
+
{
|
500 |
+
"name": "[AI-17] ๋ฌธ๋ฒ ๊ต์ ๊ธฐ",
|
501 |
+
"image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'),
|
502 |
+
"prompt": "GrammarGPT ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ํ
์คํธ์ ๋ฌธ๋ฒ ์ค๋ฅ๋ฅผ ๊ฐ์งํ๊ณ ์์ ํ๋ ์ฑ์ ๋ง๋์ธ์."
|
503 |
+
},
|
504 |
+
{
|
505 |
+
"name": "[AI-18] 3D ํฌ์ฆ ์ถ์ ๊ธฐ",
|
506 |
+
"image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'),
|
507 |
+
"prompt": "PARE ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ 2D ์ด๋ฏธ์ง์์ 3D ์ธ์ฒด ํฌ์ฆ๋ฅผ ์ถ์ ํ๋ ์ฑ์ ๋ง๋์ธ์."
|
508 |
+
},
|
509 |
+
{
|
510 |
+
"name": "[AI-19] ์์ฑ ๊ฐ์ ๋ถ์๊ธฐ",
|
511 |
+
"image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'),
|
512 |
+
"prompt": "Wav2Vec2 ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์์ฑ์์ ํ์์ ๊ฐ์ ์ํ๋ฅผ ๋ถ์ํ๋ ์ฑ์ ๋ง๋์ธ์."
|
513 |
+
},
|
514 |
+
{
|
515 |
+
"name": "[AI-20] ์ด๋ฏธ์ง ์คํ์ผ ๋ณํ",
|
516 |
+
"image_url": "data:image/gif;base64," + get_image_base64('mouse.gif'),
|
517 |
+
"prompt": "MAGiC ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง์ ์คํ์ผ์ ๋ค์ํ ์์ ์ํ ์คํ์ผ๋ก ๋ณํํ๋ ์ฑ์ ๋ง๋์ธ์."
|
518 |
+
}
|
519 |
]
|
520 |
|
521 |
+
def load_best_templates():
|
522 |
+
json_data = load_json_data()[:12] # ๋ฒ ์คํธ ํ
ํ๋ฆฟ
|
523 |
+
return create_template_html("๐ ๋ฒ ์คํธ ํ
ํ๋ฆฟ", json_data)
|
524 |
+
|
525 |
+
def load_trending_templates():
|
526 |
+
json_data = load_json_data()[12:24] # ํธ๋ ๋ฉ ํ
ํ๋ฆฟ
|
527 |
+
return create_template_html("๐ฅ ํธ๋ ๋ฉ ํ
ํ๋ฆฟ", json_data)
|
528 |
+
|
529 |
+
def load_new_templates():
|
530 |
+
json_data = load_json_data()[24:44] # NEW ํ
ํ๋ฆฟ
|
531 |
+
return create_template_html("โจ NEW ํ
ํ๋ฆฟ", json_data)
|
532 |
+
|
533 |
+
def create_template_html(title, items):
|
534 |
+
html_content = """
|
535 |
+
<style>
|
536 |
+
.prompt-grid {
|
537 |
+
display: grid;
|
538 |
+
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
539 |
+
gap: 20px;
|
540 |
+
padding: 20px;
|
541 |
+
}
|
542 |
+
.prompt-card {
|
543 |
+
background: white;
|
544 |
+
border: 1px solid #eee;
|
545 |
+
border-radius: 8px;
|
546 |
+
padding: 15px;
|
547 |
+
cursor: pointer;
|
548 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
549 |
+
}
|
550 |
+
.prompt-card:hover {
|
551 |
+
transform: translateY(-2px);
|
552 |
+
transition: transform 0.2s;
|
553 |
+
}
|
554 |
+
.card-image {
|
555 |
+
width: 100%;
|
556 |
+
height: 180px;
|
557 |
+
object-fit: cover;
|
558 |
+
border-radius: 4px;
|
559 |
+
margin-bottom: 10px;
|
560 |
+
}
|
561 |
+
.card-name {
|
562 |
+
font-weight: bold;
|
563 |
+
margin-bottom: 8px;
|
564 |
+
font-size: 16px;
|
565 |
+
color: #333;
|
566 |
+
}
|
567 |
+
.card-prompt {
|
568 |
+
font-size: 11px;
|
569 |
+
line-height: 1.4;
|
570 |
+
color: #666;
|
571 |
+
display: -webkit-box;
|
572 |
+
-webkit-line-clamp: 6;
|
573 |
+
-webkit-box-orient: vertical;
|
574 |
+
overflow: hidden;
|
575 |
+
height: 90px;
|
576 |
+
background-color: #f8f9fa;
|
577 |
+
padding: 8px;
|
578 |
+
border-radius: 4px;
|
579 |
+
}
|
580 |
+
</style>
|
581 |
+
<div class="prompt-grid">
|
582 |
+
"""
|
583 |
+
|
584 |
+
for item in items:
|
585 |
+
html_content += f"""
|
586 |
+
<div class="prompt-card" onclick="copyToInput(this)" data-prompt="{html.escape(item.get('prompt', ''))}">
|
587 |
+
<img src="{item.get('image_url', '')}" class="card-image" loading="lazy" alt="{html.escape(item.get('name', ''))}">
|
588 |
+
<div class="card-name">{html.escape(item.get('name', ''))}</div>
|
589 |
+
<div class="card-prompt">{html.escape(item.get('prompt', ''))}</div>
|
590 |
+
</div>
|
591 |
+
"""
|
592 |
+
|
593 |
+
html_content += """
|
594 |
+
<script>
|
595 |
+
function copyToInput(card) {
|
596 |
+
const prompt = card.dataset.prompt;
|
597 |
+
const textarea = document.querySelector('.ant-input-textarea-large textarea');
|
598 |
+
if (textarea) {
|
599 |
+
textarea.value = prompt;
|
600 |
+
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
601 |
+
document.querySelector('.session-drawer .close-btn').click();
|
602 |
+
}
|
603 |
+
}
|
604 |
+
</script>
|
605 |
+
</div>
|
606 |
+
"""
|
607 |
+
return gr.HTML(value=html_content)
|
608 |
+
|
609 |
+
|
610 |
+
# ์ ์ญ ๋ณ์๋ก ํ
ํ๋ฆฟ ๋ฐ์ดํฐ ์บ์
|
611 |
+
TEMPLATE_CACHE = None
|
612 |
+
|
613 |
+
def load_session_history(template_type="best"):
|
614 |
+
global TEMPLATE_CACHE
|
615 |
+
|
616 |
try:
|
617 |
json_data = load_json_data()
|
618 |
|
619 |
+
# ๋ฐ์ดํฐ๋ฅผ ์ธ ์น์
์ผ๋ก ๋๋๊ธฐ
|
620 |
+
templates = {
|
621 |
+
"best": json_data[:12], # ๋ฒ ์คํธ ํ
ํ๋ฆฟ
|
622 |
+
"trending": json_data[12:24], # ํธ๋ ๋ฉ ํ
ํ๋ฆฟ
|
623 |
+
"new": json_data[24:44] # NEW ํ
ํ๋ฆฟ
|
624 |
+
}
|
625 |
+
|
626 |
+
titles = {
|
627 |
+
"best": "๐ ๋ฒ ์คํธ ํ
ํ๋ฆฟ",
|
628 |
+
"trending": "๐ฅ ํธ๋ ๋ฉ ํ
ํ๋ฆฟ",
|
629 |
+
"new": "โจ NEW ํ
ํ๋ฆฟ"
|
630 |
+
}
|
631 |
+
|
632 |
html_content = """
|
633 |
<style>
|
634 |
+
.template-nav {
|
635 |
+
display: flex;
|
636 |
+
gap: 10px;
|
637 |
+
margin: 20px;
|
638 |
+
position: sticky;
|
639 |
+
top: 0;
|
640 |
+
background: white;
|
641 |
+
z-index: 100;
|
642 |
+
padding: 10px 0;
|
643 |
+
border-bottom: 1px solid #eee;
|
644 |
+
}
|
645 |
+
.template-btn {
|
646 |
+
padding: 8px 16px;
|
647 |
+
border: 1px solid #1890ff;
|
648 |
+
border-radius: 4px;
|
649 |
+
cursor: pointer;
|
650 |
+
background: white;
|
651 |
+
color: #1890ff;
|
652 |
+
font-weight: bold;
|
653 |
+
transition: all 0.3s;
|
654 |
+
}
|
655 |
+
.template-btn:hover {
|
656 |
+
background: #1890ff;
|
657 |
+
color: white;
|
658 |
+
}
|
659 |
+
.template-btn.active {
|
660 |
+
background: #1890ff;
|
661 |
+
color: white;
|
662 |
+
}
|
663 |
.prompt-grid {
|
664 |
display: grid;
|
665 |
+
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
666 |
gap: 20px;
|
667 |
padding: 20px;
|
668 |
}
|
|
|
671 |
border: 1px solid #eee;
|
672 |
border-radius: 8px;
|
673 |
padding: 15px;
|
|
|
|
|
|
|
674 |
cursor: pointer;
|
675 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
676 |
}
|
677 |
.prompt-card:hover {
|
678 |
transform: translateY(-2px);
|
679 |
+
transition: transform 0.2s;
|
680 |
}
|
681 |
.card-image {
|
682 |
width: 100%;
|
|
|
699 |
-webkit-line-clamp: 6;
|
700 |
-webkit-box-orient: vertical;
|
701 |
overflow: hidden;
|
|
|
702 |
height: 90px;
|
703 |
background-color: #f8f9fa;
|
704 |
padding: 8px;
|
705 |
border-radius: 4px;
|
706 |
+
}
|
707 |
+
.template-section {
|
708 |
+
display: none;
|
709 |
+
}
|
710 |
+
.template-section.active {
|
711 |
+
display: block;
|
712 |
}
|
713 |
</style>
|
714 |
+
<div class="template-nav">
|
715 |
+
<button class="template-btn" onclick="showTemplate('best')">๐ ๋ฒ ์คํธ</button>
|
716 |
+
<button class="template-btn" onclick="showTemplate('trending')">๐ฅ ํธ๋ ๋ฉ</button>
|
717 |
+
<button class="template-btn" onclick="showTemplate('new')">โจ NEW</button>
|
718 |
+
</div>
|
719 |
"""
|
720 |
|
721 |
+
# ๊ฐ ์น์
์ ํ
ํ๋ฆฟ ์์ฑ
|
722 |
+
for section, items in templates.items():
|
723 |
html_content += f"""
|
724 |
+
<div class="template-section" id="{section}-templates">
|
725 |
+
<div class="prompt-grid">
|
|
|
|
|
|
|
726 |
"""
|
727 |
+
for item in items:
|
728 |
+
html_content += f"""
|
729 |
+
<div class="prompt-card" onclick="copyToInput(this)" data-prompt="{html.escape(item.get('prompt', ''))}">
|
730 |
+
<img src="{item.get('image_url', '')}" class="card-image" loading="lazy" alt="{html.escape(item.get('name', ''))}">
|
731 |
+
<div class="card-name">{html.escape(item.get('name', ''))}</div>
|
732 |
+
<div class="card-prompt">{html.escape(item.get('prompt', ''))}</div>
|
733 |
+
</div>
|
734 |
+
"""
|
735 |
+
html_content += "</div></div>"
|
736 |
|
737 |
html_content += """
|
738 |
+
<script>
|
739 |
+
function copyToInput(card) {
|
740 |
+
const prompt = card.dataset.prompt;
|
741 |
+
const textarea = document.querySelector('.ant-input-textarea-large textarea');
|
742 |
+
if (textarea) {
|
743 |
+
textarea.value = prompt;
|
744 |
+
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
745 |
+
document.querySelector('.session-drawer .close-btn').click();
|
746 |
+
}
|
747 |
+
}
|
748 |
+
|
749 |
+
function showTemplate(type) {
|
750 |
+
// ๋ชจ๋ ์น์
์จ๊ธฐ๊ธฐ
|
751 |
+
document.querySelectorAll('.template-section').forEach(section => {
|
752 |
+
section.style.display = 'none';
|
753 |
+
});
|
754 |
+
// ๋ชจ๋ ๋ฒํผ ๋นํ์ฑํ
|
755 |
+
document.querySelectorAll('.template-btn').forEach(btn => {
|
756 |
+
btn.classList.remove('active');
|
757 |
+
});
|
758 |
+
|
759 |
+
// ์ ํ๋ ์น์
๋ณด์ด๊ธฐ
|
760 |
+
document.getElementById(type + '-templates').style.display = 'block';
|
761 |
+
// ์ ํ๋ ๋ฒํผ ํ์ฑํ
|
762 |
+
event.target.classList.add('active');
|
763 |
+
}
|
764 |
+
|
765 |
+
// ์ด๊ธฐ ๋ก๋์ ๋ฒ ์คํธ ํ
ํ๋ฆฟ ํ์
|
766 |
+
document.addEventListener('DOMContentLoaded', function() {
|
767 |
+
showTemplate('best');
|
768 |
+
document.querySelector('.template-btn').classList.add('active');
|
769 |
+
});
|
770 |
+
</script>
|
771 |
"""
|
772 |
|
773 |
return gr.HTML(value=html_content)
|
|
|
776 |
print(f"Error in load_session_history: {str(e)}")
|
777 |
return gr.HTML("Error loading templates")
|
778 |
|
|
|
|
|
779 |
|
780 |
|
781 |
|
782 |
|
783 |
+
# ๋ฐฐํฌ ๊ด๋ จ ํจ์ ์ถ๊ฐ
|
784 |
+
def generate_space_name():
|
785 |
+
"""6์๋ฆฌ ๋๋ค ์๋ฌธ ์ด๋ฆ ์์ฑ"""
|
786 |
+
letters = string.ascii_lowercase
|
787 |
+
return ''.join(random.choice(letters) for i in range(6))
|
788 |
+
|
789 |
+
def deploy_to_huggingface(code: str):
|
790 |
+
try:
|
791 |
+
# 1) ๊ธฐ๋ณธ ๊ฒ์ฆ
|
792 |
+
token = os.getenv("HF_TOKEN")
|
793 |
+
if not token:
|
794 |
+
return "HuggingFace ํ ํฐ์ด ์ค์ ๋์ง ์์์ต๋๋ค."
|
795 |
+
|
796 |
+
# 2) Space ์์ฑ ์ค๋น
|
797 |
+
api = HfApi(token=token)
|
798 |
+
space_name = generate_space_name()
|
799 |
+
username = api.whoami()['name']
|
800 |
+
repo_id = f"{username}/{space_name}"
|
801 |
+
|
802 |
+
# 3) Space ์์ฑ (private๋ก ์ค์ )
|
803 |
+
try:
|
804 |
+
create_repo(
|
805 |
+
repo_id,
|
806 |
+
repo_type="space",
|
807 |
+
space_sdk="gradio",
|
808 |
+
token=token,
|
809 |
+
private=True
|
810 |
+
)
|
811 |
+
except Exception as e:
|
812 |
+
raise e
|
813 |
+
|
814 |
+
# 4) ์ฝ๋ ์ ๋ฆฌ ๋ฐ import ๋ถ์
|
815 |
+
code = code.replace("```python", "").replace("```", "").strip()
|
816 |
+
|
817 |
+
# Import ๋ฌธ ์ถ์ถ ๋ฐ requirements.txt ์์ฑ์ ์ํ ๋งคํ
|
818 |
+
import_mapping = {
|
819 |
+
'numpy': 'numpy',
|
820 |
+
'pandas': 'pandas',
|
821 |
+
'torch': 'torch',
|
822 |
+
'matplotlib': 'matplotlib',
|
823 |
+
'plotly': 'plotly',
|
824 |
+
'transformers': 'transformers',
|
825 |
+
'PIL': 'Pillow',
|
826 |
+
'cv2': 'opencv-python',
|
827 |
+
'sklearn': 'scikit-learn',
|
828 |
+
'tensorflow': 'tensorflow',
|
829 |
+
'scipy': 'scipy',
|
830 |
+
'librosa': 'librosa',
|
831 |
+
'soundfile': 'soundfile',
|
832 |
+
'nltk': 'nltk',
|
833 |
+
'spacy': 'spacy',
|
834 |
+
'gensim': 'gensim',
|
835 |
+
'keras': 'keras',
|
836 |
+
'seaborn': 'seaborn',
|
837 |
+
'bokeh': 'bokeh',
|
838 |
+
'requests': 'requests',
|
839 |
+
'beautifulsoup4': 'beautifulsoup4',
|
840 |
+
'scikit-image': 'scikit-image',
|
841 |
+
'opencv-python': 'opencv-python',
|
842 |
+
'tqdm': 'tqdm',
|
843 |
+
'streamlit': 'streamlit',
|
844 |
+
'dash': 'dash',
|
845 |
+
'flask': 'flask',
|
846 |
+
'django': 'django',
|
847 |
+
'sqlalchemy': 'sqlalchemy',
|
848 |
+
'pymongo': 'pymongo',
|
849 |
+
'redis': 'redis',
|
850 |
+
'psycopg2': 'psycopg2-binary',
|
851 |
+
'mysql-connector': 'mysql-connector-python',
|
852 |
+
'pytest': 'pytest',
|
853 |
+
'unittest': 'unittest2',
|
854 |
+
'sphinx': 'sphinx',
|
855 |
+
'jupyter': 'jupyter',
|
856 |
+
'ipython': 'ipython',
|
857 |
+
'fastapi': 'fastapi',
|
858 |
+
'uvicorn': 'uvicorn',
|
859 |
+
'aiohttp': 'aiohttp',
|
860 |
+
'websockets': 'websockets',
|
861 |
+
'pyyaml': 'pyyaml',
|
862 |
+
'json': 'json5',
|
863 |
+
'xml': 'lxml',
|
864 |
+
'html': 'html5lib',
|
865 |
+
'urllib3': 'urllib3',
|
866 |
+
'cryptography': 'cryptography',
|
867 |
+
'bcrypt': 'bcrypt',
|
868 |
+
'jwt': 'pyjwt',
|
869 |
+
'pillow': 'Pillow',
|
870 |
+
'imageio': 'imageio',
|
871 |
+
'moviepy': 'moviepy',
|
872 |
+
'ffmpeg': 'ffmpeg-python',
|
873 |
+
'pydub': 'pydub',
|
874 |
+
'wave': 'wave',
|
875 |
+
'pyaudio': 'pyaudio',
|
876 |
+
'sounddevice': 'sounddevice',
|
877 |
+
'pygame': 'pygame',
|
878 |
+
'kivy': 'kivy',
|
879 |
+
'pyqt5': 'PyQt5',
|
880 |
+
'tkinter': 'tk',
|
881 |
+
'wx': 'wxPython',
|
882 |
+
'pyside2': 'PySide2',
|
883 |
+
'deap': 'deap',
|
884 |
+
'gym': 'gym',
|
885 |
+
'stable-baselines3': 'stable-baselines3',
|
886 |
+
'optuna': 'optuna',
|
887 |
+
'hyperopt': 'hyperopt',
|
888 |
+
'ray': 'ray',
|
889 |
+
'dask': 'dask',
|
890 |
+
'vaex': 'vaex',
|
891 |
+
'modin': 'modin',
|
892 |
+
'cupy': 'cupy',
|
893 |
+
'jax': 'jax',
|
894 |
+
'numba': 'numba',
|
895 |
+
'cython': 'cython',
|
896 |
+
'sympy': 'sympy',
|
897 |
+
'statsmodels': 'statsmodels',
|
898 |
+
'prophet': 'prophet',
|
899 |
+
'lightgbm': 'lightgbm',
|
900 |
+
'xgboost': 'xgboost',
|
901 |
+
'catboost': 'catboost',
|
902 |
+
'shap': 'shap',
|
903 |
+
'lime': 'lime',
|
904 |
+
'eli5': 'eli5',
|
905 |
+
'yellowbrick': 'yellowbrick',
|
906 |
+
'altair': 'altair',
|
907 |
+
'plotnine': 'plotnine',
|
908 |
+
'folium': 'folium',
|
909 |
+
'geopandas': 'geopandas',
|
910 |
+
'shapely': 'shapely',
|
911 |
+
'rasterio': 'rasterio',
|
912 |
+
'networkx': 'networkx',
|
913 |
+
'graphviz': 'graphviz',
|
914 |
+
'pydot': 'pydot',
|
915 |
+
'pygraphviz': 'pygraphviz'
|
916 |
+
}
|
917 |
+
|
918 |
+
required_packages = set()
|
919 |
+
|
920 |
+
# ์ฝ๋์์ import ๋ฌธ ๋ถ์
|
921 |
+
import_pattern = r'^(?:from\s+(\S+)|import\s+([^,\s]+)(?:\s*,\s*([^,\s]+))*)'
|
922 |
+
|
923 |
+
for line in code.split('\n'):
|
924 |
+
line = line.strip()
|
925 |
+
if line.startswith('import ') or line.startswith('from '):
|
926 |
+
matches = re.match(import_pattern, line)
|
927 |
+
if matches:
|
928 |
+
if matches.group(1): # from ... import ...
|
929 |
+
package = matches.group(1).split('.')[0]
|
930 |
+
if package in import_mapping:
|
931 |
+
required_packages.add(import_mapping[package])
|
932 |
+
else: # import ...
|
933 |
+
packages = [p.strip() for p in re.findall(r'[\w.]+', line[7:])]
|
934 |
+
for package in packages:
|
935 |
+
package = package.split('.')[0]
|
936 |
+
if package in import_mapping:
|
937 |
+
required_packages.add(import_mapping[package])
|
938 |
+
|
939 |
+
# gradio๋ ํญ์ ํฌํจ
|
940 |
+
required_packages.add('gradio==5.5.0')
|
941 |
+
|
942 |
+
# 5) ์ ์ฒด ์ ํ๋ฆฌ์ผ์ด์
์ฝ๋ ์์ฑ
|
943 |
+
if "demo.launch()" not in code:
|
944 |
+
full_app_code = code + "\n\nif __name__ == '__main__':\n demo.launch()"
|
945 |
+
else:
|
946 |
+
full_app_code = code
|
947 |
+
|
948 |
+
# 6) ํ์ผ ์์ฑ ๋ฐ ์
๋ก๋
|
949 |
+
with open("app.py", "w", encoding="utf-8") as f:
|
950 |
+
f.write(full_app_code)
|
951 |
+
|
952 |
+
api.upload_file(
|
953 |
+
path_or_fileobj="app.py",
|
954 |
+
path_in_repo="app.py",
|
955 |
+
repo_id=repo_id,
|
956 |
+
repo_type="space"
|
957 |
+
)
|
958 |
+
|
959 |
+
# requirements.txt ์์ฑ ๋ฐ ์
๋ก๋
|
960 |
+
requirements = '\n'.join(sorted(required_packages))
|
961 |
+
with open("requirements.txt", "w") as f:
|
962 |
+
f.write(requirements)
|
963 |
+
|
964 |
+
api.upload_file(
|
965 |
+
path_or_fileobj="requirements.txt",
|
966 |
+
path_in_repo="requirements.txt",
|
967 |
+
repo_id=repo_id,
|
968 |
+
repo_type="space"
|
969 |
+
)
|
970 |
+
|
971 |
+
# 7) ๊ฒฐ๊ณผ ๋ฐํ
|
972 |
+
space_url = f"https://huggingface.co/spaces/{username}/{space_name}"
|
973 |
+
return f'๋ฐฐํฌ ์๋ฃ! Private Space๋ก ์์ฑ๋์์ต๋๋ค. <a href="{space_url}" target="_blank" style="color: #1890ff; text-decoration: underline; cursor: pointer;">์ฌ๊ธฐ๋ฅผ ํด๋ฆญํ์ฌ Space ์ด๊ธฐ</a>'
|
974 |
+
|
975 |
+
except Exception as e:
|
976 |
+
return f"๋ฐฐํฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
977 |
+
|
978 |
+
|
979 |
+
|
980 |
+
# Demo ์ธ์คํด์ค ์์ฑ
|
981 |
+
demo_instance = Demo()
|
982 |
+
|
983 |
+
|
984 |
with gr.Blocks(css_paths="app.css",theme=theme) as demo:
|
985 |
history = gr.State([])
|
986 |
setting = gr.State({
|
|
|
1014 |
elem_classes="close-btn"
|
1015 |
)
|
1016 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1017 |
# ๋ฉ์ธ ์ปจํ
์ธ ๋ฅผ ์ํ Row
|
1018 |
with antd.Row(gutter=[32, 12]) as layout:
|
1019 |
# ์ข์ธก ํจ๋
|
1020 |
+
|
1021 |
+
# ์ข์ธก ํจ๋ ๋ถ๋ถ์ ๋ค์๊ณผ ๊ฐ์ด ์์
|
1022 |
with antd.Col(span=24, md=8):
|
1023 |
with antd.Flex(vertical=True, gap="middle", wrap=True):
|
1024 |
header = gr.HTML(f"""
|
|
|
1034 |
placeholder=random.choice(DEMO_LIST)['description']
|
1035 |
)
|
1036 |
|
1037 |
+
|
1038 |
+
# UI ์์ ๋ถ๋ถ - antd.Col(span=24, md=8) ๋ด๋ถ์ ๋ฒํผ ์ปจํ
์ด๋์ ๋ฐฐํฌ ๋ฒํผ ์ถ๊ฐ:
|
1039 |
with antd.Flex(gap="small", justify="space-between"):
|
1040 |
btn = antd.Button("Send", type="primary", size="large")
|
1041 |
execute_btn = antd.Button("Code ์คํ", type="default", size="large")
|
1042 |
+
deploy_btn = antd.Button("์คํํ๊ธฐ", type="default", size="large") # ์ถ๊ฐ
|
1043 |
clear_btn = antd.Button("Clear", type="default", size="large")
|
1044 |
|
1045 |
+
# ๋ฐฐํฌ ๊ฒฐ๊ณผ๋ฅผ ํ์ํ ํ
์คํธ ์์ญ ์ถ๊ฐ
|
1046 |
+
|
1047 |
+
deploy_result = gr.HTML(label="๋ฐฐํฌ ๊ฒฐ๊ณผ")
|
1048 |
+
|
1049 |
with antd.Col(span=24, md=16):
|
1050 |
with ms.Div(elem_classes="right_panel"):
|
1051 |
with antd.Flex(gap="small", elem_classes="setting-buttons"):
|
1052 |
codeBtn = antd.Button("๐งโ๐ป ์ฝ๋ ๋ณด๊ธฐ", type="default")
|
1053 |
historyBtn = antd.Button("๐ ํ์คํ ๋ฆฌ", type="default")
|
1054 |
+
best_btn = antd.Button("๐ ๋ฒ ์คํธ ํ
ํ๋ฆฟ", type="default")
|
1055 |
+
trending_btn = antd.Button("๐ฅ ํธ๋ ๋ฉ ํ
ํ๋ฆฟ", type="default")
|
1056 |
+
new_btn = antd.Button("โจ NEW ํ
ํ๋ฆฟ", type="default")
|
1057 |
|
1058 |
gr.HTML('<div class="render_header"><span class="header_btn"></span><span class="header_btn"></span><span class="header_btn"></span></div>')
|
1059 |
+
|
1060 |
+
|
1061 |
+
|
1062 |
with antd.Tabs(active_key="empty", render_tab_bar="() => null") as state_tab:
|
1063 |
with antd.Tabs.Item(key="empty"):
|
1064 |
empty = antd.Empty(description="empty input", elem_classes="right_content")
|
|
|
1086 |
print(f"Error executing code: {str(e)}")
|
1087 |
return None, gr.update(active_key="empty")
|
1088 |
|
1089 |
+
# ์ด๋ฒคํธ ํธ๋ค๋ฌ๋ค
|
1090 |
execute_btn.click(
|
1091 |
fn=execute_code,
|
1092 |
inputs=[input],
|
|
|
1098 |
inputs=[],
|
1099 |
outputs=[code_drawer]
|
1100 |
)
|
1101 |
+
|
1102 |
code_drawer.close(
|
1103 |
lambda: gr.update(open=False),
|
1104 |
inputs=[],
|
|
|
1110 |
inputs=[history],
|
1111 |
outputs=[history_drawer, history_output]
|
1112 |
)
|
1113 |
+
|
1114 |
history_drawer.close(
|
1115 |
lambda: gr.update(open=False),
|
1116 |
inputs=[],
|
1117 |
outputs=[history_drawer]
|
1118 |
)
|
1119 |
|
1120 |
+
# ํ
ํ๋ฆฟ ๋ฒํผ ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
1121 |
+
best_btn.click(
|
1122 |
+
fn=lambda: (gr.update(open=True), load_best_templates()),
|
1123 |
+
outputs=[session_drawer, session_history],
|
1124 |
+
queue=False
|
1125 |
+
)
|
1126 |
|
1127 |
+
trending_btn.click(
|
1128 |
+
fn=lambda: (gr.update(open=True), load_trending_templates()),
|
1129 |
+
outputs=[session_drawer, session_history],
|
1130 |
+
queue=False
|
1131 |
+
)
|
1132 |
|
1133 |
+
new_btn.click(
|
1134 |
+
fn=lambda: (gr.update(open=True), load_new_templates()),
|
1135 |
+
outputs=[session_drawer, session_history],
|
1136 |
+
queue=False
|
1137 |
)
|
1138 |
+
|
1139 |
session_drawer.close(
|
1140 |
lambda: (gr.update(open=False), gr.HTML("")),
|
1141 |
outputs=[session_drawer, session_history]
|
|
|
1146 |
outputs=[session_drawer, session_history]
|
1147 |
)
|
1148 |
|
|
|
|
|
1149 |
btn.click(
|
1150 |
demo_instance.generation_code,
|
1151 |
inputs=[input, setting, history],
|
|
|
1158 |
outputs=[history]
|
1159 |
)
|
1160 |
|
1161 |
+
# ์ด๋ฒคํธ ํธ๋ค๋ฌ ์ถ๊ฐ
|
1162 |
+
deploy_btn.click(
|
1163 |
+
fn=lambda code: deploy_to_huggingface(remove_code_block(code)) if code else "์ฝ๋๊ฐ ์์ต๋๋ค.",
|
1164 |
+
inputs=[code_output],
|
1165 |
+
outputs=[deploy_result]
|
1166 |
+
)
|
1167 |
+
|
1168 |
|
1169 |
if __name__ == "__main__":
|
1170 |
try:
|
|
|
1172 |
demo.queue(default_concurrency_limit=20).launch(ssr_mode=False)
|
1173 |
except Exception as e:
|
1174 |
print(f"Initialization error: {e}")
|
1175 |
+
raise
|