Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -13,28 +13,21 @@ from transformers import pipeline as hf_pipeline
|
|
13 |
##############################################################################
|
14 |
# 1) ZeroGPU ํ๊ฒฝ ์ฒ๋ฆฌ + device, dtype ์ค์
|
15 |
##############################################################################
|
16 |
-
##############################################################################
|
17 |
-
# 1) ZeroGPU ํ๊ฒฝ ์ฒ๋ฆฌ + device, dtype ์ค์
|
18 |
-
##############################################################################
|
19 |
-
# ZeroGPU ์ด๊ธฐํ ์๋
|
20 |
try:
|
21 |
import zerogpu
|
22 |
zerogpu.init()
|
23 |
print("ZeroGPU initialized successfully")
|
24 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
25 |
except ImportError:
|
26 |
-
# ZeroGPU๊ฐ ์ค์น๋์ง ์์ ๊ฒฝ์ฐ
|
27 |
print("ZeroGPU package not installed, continuing without it")
|
28 |
if os.getenv("ZERO_GPU"):
|
29 |
print("ZeroGPU environment variable is set but zerogpu package is not installed.")
|
30 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
31 |
except Exception as e:
|
32 |
-
# ZeroGPU ์ด๊ธฐํ ์ค ๋ค๋ฅธ ์ค๋ฅ๊ฐ ๋ฐ์ํ ๊ฒฝ์ฐ
|
33 |
print(f"Error initializing ZeroGPU: {e}")
|
34 |
print("Continuing without ZeroGPU")
|
35 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
36 |
|
37 |
-
# GPU์ผ ๋๋ง bfloat16, ๊ทธ ์ธ์๋ float32
|
38 |
dtype = torch.bfloat16 if device == "cuda" else torch.float32
|
39 |
|
40 |
print(f"Using device: {device}, dtype: {dtype}")
|
@@ -57,7 +50,6 @@ try:
|
|
57 |
print("Models loaded successfully")
|
58 |
except Exception as e:
|
59 |
print(f"Error loading models: {e}")
|
60 |
-
# ๋ชจ๋ธ ๋ก๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ์ํ ๋๋ฏธ ํจ์๋ค
|
61 |
def dummy_translator(text):
|
62 |
return [{'translation_text': text}]
|
63 |
|
@@ -90,20 +82,14 @@ def contains_korean(text):
|
|
90 |
# ์ด๋ฏธ์ง ์์ฑ ํจ์
|
91 |
##############################################################################
|
92 |
def generate_design_image(prompt, seed=42, randomize_seed=True, width=1024, height=1024, num_inference_steps=4):
|
93 |
-
"""
|
94 |
-
์์ฑ๋ ํ์ฅ ์์ด๋์ด ํ
์คํธ(prompt)๋ฅผ ์
๋ ฅ๋ฐ์,
|
95 |
-
ํ์์ ํ๊ตญ์ด๋ฅผ ์์ด๋ก ๋ฒ์ญํ ํ DiffusionPipeline์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.
|
96 |
-
"""
|
97 |
original_prompt = prompt
|
98 |
translated = False
|
99 |
|
100 |
-
# ํ๊ตญ์ด๊ฐ ํฌํจ๋์ด ์์ผ๋ฉด ์์ด๋ก ๋ฒ์ญ
|
101 |
if contains_korean(prompt):
|
102 |
translation = translator(prompt)
|
103 |
prompt = translation[0]['translation_text']
|
104 |
translated = True
|
105 |
|
106 |
-
# ๋๋ค ์๋ ์ค์
|
107 |
if randomize_seed:
|
108 |
seed = random.randint(0, MAX_SEED)
|
109 |
|
@@ -420,7 +406,6 @@ def process_inputs(text1, text2, text3, selected_category, progress=gr.Progress(
|
|
420 |
time.sleep(0.3)
|
421 |
progress(0.1, desc="์ฐฝ์์ ์ธ ์์ด๋์ด ์์ฑ ์์...")
|
422 |
|
423 |
-
# ์นดํ
๊ณ ๋ฆฌ์ ํด๋นํ๋ ์์ด๋์ด ์์ฑ
|
424 |
results = generate_transformations(text1, text2, text3, selected_category)
|
425 |
|
426 |
progress(0.8, desc="๊ฒฐ๊ณผ ํฌ๋งทํ
์ค...")
|
@@ -507,7 +492,8 @@ with gr.Blocks(
|
|
507 |
text_input1 = gr.Textbox(label="ํค์๋ 1 (ํ์)", placeholder="์: ์ค๋งํธํฐ")
|
508 |
text_input2 = gr.Textbox(label="ํค์๋ 2 (์ ํ)", placeholder="์: ์ธ๊ณต์ง๋ฅ")
|
509 |
text_input3 = gr.Textbox(label="ํค์๋ 3 (์ ํ)", placeholder="์: ํฌ์ค์ผ์ด")
|
510 |
-
|
|
|
511 |
label="์นดํ
๊ณ ๋ฆฌ ์ ํ",
|
512 |
choices=list(physical_transformation_categories.keys()),
|
513 |
value=list(physical_transformation_categories.keys())[0],
|
@@ -534,34 +520,31 @@ with gr.Blocks(
|
|
534 |
idea_output = gr.Markdown(label="์์ด๋์ด ๊ฒฐ๊ณผ")
|
535 |
generated_image = gr.Image(label="์์ฑ๋ ๋์์ธ ์ด๋ฏธ์ง", type="pil")
|
536 |
|
537 |
-
# ์์
|
538 |
gr.Examples(
|
539 |
examples=[
|
540 |
-
["์ค๋งํธํฐ", "", "",
|
541 |
-
["์๋์ฐจ", "", "",
|
542 |
-
["์๋์ฐจ", "์ธ๊ณต์ง๋ฅ", "",
|
543 |
-
["๋๋ก ", "์ธ๊ณต์ง๋ฅ", "",
|
544 |
-
["์ด๋ํ", "์จ์ด๋ฌ๋ธ", "๊ฑด๊ฐ",
|
545 |
],
|
546 |
-
inputs=[text_input1, text_input2, text_input3,
|
547 |
)
|
548 |
|
549 |
-
# ์ฒ๋ฆฌ์ค ์์ด์ฝ ๋ณด์ด๊ธฐ
|
550 |
def show_processing_indicator():
|
551 |
return gr.update(visible=True)
|
552 |
|
553 |
-
# ์ฒ๋ฆฌ์ค ์์ด์ฝ ์จ๊ธฐ๊ธฐ
|
554 |
def hide_processing_indicator():
|
555 |
return gr.update(visible=False)
|
556 |
|
557 |
-
# ๋ฒํผ ํด๋ฆญ ์ ์ฒ๋ฆฌ ๋ก์ง
|
558 |
submit_button.click(
|
559 |
fn=show_processing_indicator,
|
560 |
inputs=None,
|
561 |
outputs=processing_indicator
|
562 |
).then(
|
563 |
fn=process_all,
|
564 |
-
inputs=[text_input1, text_input2, text_input3,
|
565 |
outputs=[idea_output, generated_image]
|
566 |
).then(
|
567 |
fn=hide_processing_indicator,
|
@@ -569,6 +552,5 @@ with gr.Blocks(
|
|
569 |
outputs=processing_indicator
|
570 |
)
|
571 |
|
572 |
-
# ๋ฉ์ธ ์คํ
|
573 |
if __name__ == "__main__":
|
574 |
demo.launch(debug=True)
|
|
|
13 |
##############################################################################
|
14 |
# 1) ZeroGPU ํ๊ฒฝ ์ฒ๋ฆฌ + device, dtype ์ค์
|
15 |
##############################################################################
|
|
|
|
|
|
|
|
|
16 |
try:
|
17 |
import zerogpu
|
18 |
zerogpu.init()
|
19 |
print("ZeroGPU initialized successfully")
|
20 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
21 |
except ImportError:
|
|
|
22 |
print("ZeroGPU package not installed, continuing without it")
|
23 |
if os.getenv("ZERO_GPU"):
|
24 |
print("ZeroGPU environment variable is set but zerogpu package is not installed.")
|
25 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
26 |
except Exception as e:
|
|
|
27 |
print(f"Error initializing ZeroGPU: {e}")
|
28 |
print("Continuing without ZeroGPU")
|
29 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
30 |
|
|
|
31 |
dtype = torch.bfloat16 if device == "cuda" else torch.float32
|
32 |
|
33 |
print(f"Using device: {device}, dtype: {dtype}")
|
|
|
50 |
print("Models loaded successfully")
|
51 |
except Exception as e:
|
52 |
print(f"Error loading models: {e}")
|
|
|
53 |
def dummy_translator(text):
|
54 |
return [{'translation_text': text}]
|
55 |
|
|
|
82 |
# ์ด๋ฏธ์ง ์์ฑ ํจ์
|
83 |
##############################################################################
|
84 |
def generate_design_image(prompt, seed=42, randomize_seed=True, width=1024, height=1024, num_inference_steps=4):
|
|
|
|
|
|
|
|
|
85 |
original_prompt = prompt
|
86 |
translated = False
|
87 |
|
|
|
88 |
if contains_korean(prompt):
|
89 |
translation = translator(prompt)
|
90 |
prompt = translation[0]['translation_text']
|
91 |
translated = True
|
92 |
|
|
|
93 |
if randomize_seed:
|
94 |
seed = random.randint(0, MAX_SEED)
|
95 |
|
|
|
406 |
time.sleep(0.3)
|
407 |
progress(0.1, desc="์ฐฝ์์ ์ธ ์์ด๋์ด ์์ฑ ์์...")
|
408 |
|
|
|
409 |
results = generate_transformations(text1, text2, text3, selected_category)
|
410 |
|
411 |
progress(0.8, desc="๊ฒฐ๊ณผ ํฌ๋งทํ
์ค...")
|
|
|
492 |
text_input1 = gr.Textbox(label="ํค์๋ 1 (ํ์)", placeholder="์: ์ค๋งํธํฐ")
|
493 |
text_input2 = gr.Textbox(label="ํค์๋ 2 (์ ํ)", placeholder="์: ์ธ๊ณต์ง๋ฅ")
|
494 |
text_input3 = gr.Textbox(label="ํค์๋ 3 (์ ํ)", placeholder="์: ํฌ์ค์ผ์ด")
|
495 |
+
# ๋๋กญ๋ค์ด ๋์ ๋ผ๋์ค ๋ฒํผ์ผ๋ก ์นดํ
๊ณ ๋ฆฌ ์ ํ (๋ชจ๋ ์ต์
์ด ํผ์ณ์ง)
|
496 |
+
category_radio = gr.Radio(
|
497 |
label="์นดํ
๊ณ ๋ฆฌ ์ ํ",
|
498 |
choices=list(physical_transformation_categories.keys()),
|
499 |
value=list(physical_transformation_categories.keys())[0],
|
|
|
520 |
idea_output = gr.Markdown(label="์์ด๋์ด ๊ฒฐ๊ณผ")
|
521 |
generated_image = gr.Image(label="์์ฑ๋ ๋์์ธ ์ด๋ฏธ์ง", type="pil")
|
522 |
|
523 |
+
# ๋ค์ํ ์นดํ
๊ณ ๋ฆฌ๊ฐ ํฌํจ๋ ์์ (๋ผ๋์ค ๋ฒํผ ์
๋ ฅ)
|
524 |
gr.Examples(
|
525 |
examples=[
|
526 |
+
["์ค๋งํธํฐ", "", "", "๊ณต๊ฐ ์ด๋"],
|
527 |
+
["์๋์ฐจ", "", "", "ํฌ๊ธฐ์ ํํ ๋ณํ"],
|
528 |
+
["์๋์ฐจ", "์ธ๊ณต์ง๋ฅ", "", "ํ๋ฉด ๋ฐ ์ธ๊ด ๋ณํ"],
|
529 |
+
["๋๋ก ", "์ธ๊ณต์ง๋ฅ", "", "๋ฌผ์ง์ ์ํ ๋ณํ"],
|
530 |
+
["์ด๋ํ", "์จ์ด๋ฌ๋ธ", "๊ฑด๊ฐ", "์ ๊ธฐ ๋ฐ ์๊ธฐ ๋ณํ"],
|
531 |
],
|
532 |
+
inputs=[text_input1, text_input2, text_input3, category_radio],
|
533 |
)
|
534 |
|
|
|
535 |
def show_processing_indicator():
|
536 |
return gr.update(visible=True)
|
537 |
|
|
|
538 |
def hide_processing_indicator():
|
539 |
return gr.update(visible=False)
|
540 |
|
|
|
541 |
submit_button.click(
|
542 |
fn=show_processing_indicator,
|
543 |
inputs=None,
|
544 |
outputs=processing_indicator
|
545 |
).then(
|
546 |
fn=process_all,
|
547 |
+
inputs=[text_input1, text_input2, text_input3, category_radio],
|
548 |
outputs=[idea_output, generated_image]
|
549 |
).then(
|
550 |
fn=hide_processing_indicator,
|
|
|
552 |
outputs=processing_indicator
|
553 |
)
|
554 |
|
|
|
555 |
if __name__ == "__main__":
|
556 |
demo.launch(debug=True)
|