Update app.py
Browse files
app.py
CHANGED
|
@@ -8,9 +8,6 @@ translator = translation_pipeline("translation", model="Helsinki-NLP/opus-mt-ko-
|
|
| 8 |
# Diffusers ๋ชจ๋ธ ๋ก๋
|
| 9 |
from diffusers import DiffusionPipeline
|
| 10 |
|
| 11 |
-
# -- Stable Diffusion ๊ณ์ด ํ์ดํ๋ผ์ธ ์ค์ --
|
| 12 |
-
# (๋ชจ๋ธ ์์: black-forest-labs/FLUX.1-schnell -> ๋ง์ธ๋๋งต์ฉ์ผ๋ก ์ปค์คํ
๋ ๋ชจ๋ธ์ด์ง๋ง,
|
| 13 |
-
# ์ฌ๊ธฐ์๋ "์คํ ๋ฆฌ๋ณด๋" ์คํ์ผ ํ๋กฌํํธ๋ ์๋ ๊ฐ๋ฅ)
|
| 14 |
model_id = "black-forest-labs/FLUX.1-schnell"
|
| 15 |
|
| 16 |
pipe = DiffusionPipeline.from_pretrained(
|
|
@@ -18,10 +15,7 @@ pipe = DiffusionPipeline.from_pretrained(
|
|
| 18 |
torch_dtype=torch.float32
|
| 19 |
).to("cpu") # CPU ์ฌ์ฉ
|
| 20 |
|
| 21 |
-
# ํ๊ธ ํ๋กฌํํธ๋ฅผ ์์ด๋ก ๋ณํํ๊ธฐ ์ํ ํฌํผ ํจ์
|
| 22 |
def translate_prompt_if_korean(prompt_text: str) -> str:
|
| 23 |
-
# ๊ฐ๋จํ, ๋ฌธ์์ด ๋ด์ ํ๊ธ์ด ํฌํจ๋์ด ์๋์ง ํ์ธ ํ ๋ฒ์ญ
|
| 24 |
-
# (์์ด ์
๋ ฅ์ผ ๊ฒฝ์ฐ ๋ฒ์ญ์ ์คํต)
|
| 25 |
if any("๊ฐ" <= ch <= "ํฃ" for ch in prompt_text):
|
| 26 |
result = translator(prompt_text)
|
| 27 |
return result[0]['translation_text']
|
|
@@ -53,7 +47,6 @@ def generate_storyboard(
|
|
| 53 |
).images[0]
|
| 54 |
return result
|
| 55 |
|
| 56 |
-
|
| 57 |
# --- ๋น์ฃผ์ผ & ์ธ๋ จ๋ UI๋ฅผ ์ํ CSS ---
|
| 58 |
custom_css = """
|
| 59 |
#title {
|
|
@@ -94,7 +87,6 @@ custom_css = """
|
|
| 94 |
}
|
| 95 |
"""
|
| 96 |
|
| 97 |
-
# --- Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ ---
|
| 98 |
with gr.Blocks(css=custom_css) as demo:
|
| 99 |
gr.Markdown("<div id='title'>Gini Storyboard</div>")
|
| 100 |
gr.Markdown("<div id='subtitle'>Generate a hand-drawn style storyboard in black & white film noir or any style you wish!</div>")
|
|
@@ -152,7 +144,8 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 152 |
|
| 153 |
# ์์ ํ๋กฌํํธ
|
| 154 |
gr.Markdown("### Example Prompt")
|
| 155 |
-
|
|
|
|
| 156 |
example_text = (
|
| 157 |
"A hand-drawn storyboard style, film noir theme, black and white.\n"
|
| 158 |
"SCENE 1: A detective enters a dark alley [Frame 1]\n"
|
|
@@ -162,25 +155,23 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 162 |
gr.Markdown(f"```\n{example_text}\n```")
|
| 163 |
example_button = gr.Button("Use Example")
|
| 164 |
|
| 165 |
-
# ์์ ๋ฒํผ ํด๋ฆญ ์ ํ๋กฌํํธ์ ๋ฐ์
|
| 166 |
def load_example():
|
| 167 |
return example_text
|
| 168 |
example_button.click(fn=load_example, outputs=[prompt])
|
| 169 |
|
| 170 |
-
# ๋ฒํผ ํด๋ฆญ & ํ๋กฌํํธ Enter ์ด๋ฒคํธ ์ฒ๋ฆฌ
|
| 171 |
run_button.click(
|
| 172 |
fn=generate_storyboard,
|
| 173 |
inputs=[prompt, width, height, num_inference_steps, guidance_scale, seed],
|
| 174 |
outputs=[result]
|
| 175 |
)
|
| 176 |
|
|
|
|
| 177 |
prompt.submit(
|
| 178 |
fn=generate_storyboard,
|
| 179 |
inputs=[prompt, width, height, num_inference_steps, guidance_scale, seed],
|
| 180 |
outputs=[result]
|
| 181 |
)
|
| 182 |
|
| 183 |
-
# ์คํ
|
| 184 |
if __name__ == "__main__":
|
| 185 |
demo.queue()
|
| 186 |
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
|
|
|
| 8 |
# Diffusers ๋ชจ๋ธ ๋ก๋
|
| 9 |
from diffusers import DiffusionPipeline
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
model_id = "black-forest-labs/FLUX.1-schnell"
|
| 12 |
|
| 13 |
pipe = DiffusionPipeline.from_pretrained(
|
|
|
|
| 15 |
torch_dtype=torch.float32
|
| 16 |
).to("cpu") # CPU ์ฌ์ฉ
|
| 17 |
|
|
|
|
| 18 |
def translate_prompt_if_korean(prompt_text: str) -> str:
|
|
|
|
|
|
|
| 19 |
if any("๊ฐ" <= ch <= "ํฃ" for ch in prompt_text):
|
| 20 |
result = translator(prompt_text)
|
| 21 |
return result[0]['translation_text']
|
|
|
|
| 47 |
).images[0]
|
| 48 |
return result
|
| 49 |
|
|
|
|
| 50 |
# --- ๋น์ฃผ์ผ & ์ธ๋ จ๋ UI๋ฅผ ์ํ CSS ---
|
| 51 |
custom_css = """
|
| 52 |
#title {
|
|
|
|
| 87 |
}
|
| 88 |
"""
|
| 89 |
|
|
|
|
| 90 |
with gr.Blocks(css=custom_css) as demo:
|
| 91 |
gr.Markdown("<div id='title'>Gini Storyboard</div>")
|
| 92 |
gr.Markdown("<div id='subtitle'>Generate a hand-drawn style storyboard in black & white film noir or any style you wish!</div>")
|
|
|
|
| 144 |
|
| 145 |
# ์์ ํ๋กฌํํธ
|
| 146 |
gr.Markdown("### Example Prompt")
|
| 147 |
+
# โ Box๊ฐ ์๋ Group์ผ๋ก ๋ณ๊ฒฝ
|
| 148 |
+
with gr.Group(elem_classes="example-box"):
|
| 149 |
example_text = (
|
| 150 |
"A hand-drawn storyboard style, film noir theme, black and white.\n"
|
| 151 |
"SCENE 1: A detective enters a dark alley [Frame 1]\n"
|
|
|
|
| 155 |
gr.Markdown(f"```\n{example_text}\n```")
|
| 156 |
example_button = gr.Button("Use Example")
|
| 157 |
|
|
|
|
| 158 |
def load_example():
|
| 159 |
return example_text
|
| 160 |
example_button.click(fn=load_example, outputs=[prompt])
|
| 161 |
|
|
|
|
| 162 |
run_button.click(
|
| 163 |
fn=generate_storyboard,
|
| 164 |
inputs=[prompt, width, height, num_inference_steps, guidance_scale, seed],
|
| 165 |
outputs=[result]
|
| 166 |
)
|
| 167 |
|
| 168 |
+
# ์ํฐ๋ก ์ ์ถ ์์๋ ์คํ
|
| 169 |
prompt.submit(
|
| 170 |
fn=generate_storyboard,
|
| 171 |
inputs=[prompt, width, height, num_inference_steps, guidance_scale, seed],
|
| 172 |
outputs=[result]
|
| 173 |
)
|
| 174 |
|
|
|
|
| 175 |
if __name__ == "__main__":
|
| 176 |
demo.queue()
|
| 177 |
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|