Spaces:
Running
on
Zero
Running
on
Zero
Create app-backup.py
Browse files- app-backup.py +126 -0
app-backup.py
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import random
|
4 |
+
import spaces
|
5 |
+
import torch
|
6 |
+
from diffusers import DiffusionPipeline
|
7 |
+
from transformers import pipeline
|
8 |
+
|
9 |
+
# ๋ฒ์ญ ํ์ดํ๋ผ์ธ ๋ฐ ํ๋์จ์ด ์ค์
|
10 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device=device)
|
12 |
+
|
13 |
+
dtype = torch.bfloat16
|
14 |
+
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype).to(device)
|
15 |
+
|
16 |
+
MAX_SEED = np.iinfo(np.int32).max
|
17 |
+
MAX_IMAGE_SIZE = 2048
|
18 |
+
|
19 |
+
@spaces.GPU()
|
20 |
+
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
|
21 |
+
if randomize_seed:
|
22 |
+
seed = random.randint(0, MAX_SEED)
|
23 |
+
generator = torch.Generator().manual_seed(seed)
|
24 |
+
|
25 |
+
# ํ๊ธ ์
๋ ฅ ๊ฐ์ง ๋ฐ ๋ฒ์ญ
|
26 |
+
if any('\uAC00' <= char <= '\uD7A3' for char in prompt):
|
27 |
+
print("Translating Korean prompt...")
|
28 |
+
translated_prompt = translator(prompt, max_length=512)[0]['translation_text']
|
29 |
+
print("Translated prompt:", translated_prompt)
|
30 |
+
prompt = translated_prompt
|
31 |
+
|
32 |
+
image = pipe(
|
33 |
+
prompt = prompt,
|
34 |
+
width = width,
|
35 |
+
height = height,
|
36 |
+
num_inference_steps = num_inference_steps,
|
37 |
+
generator = generator,
|
38 |
+
guidance_scale=0.0
|
39 |
+
).images[0]
|
40 |
+
return image, seed
|
41 |
+
|
42 |
+
examples = [
|
43 |
+
["Create a new logo for a [Color Tone: Blue] [Design Concept: ROCKET] [Text: 'WORLD'] [Background: BLUE COLOR]"],
|
44 |
+
["Create a new logo for a [Color Tone: Blue] [Design Concept: UNIVERSE] [Text: 'COCA COLA'] [Background: COLORFUL]"],
|
45 |
+
["simple futuristic logo kamikaze drone on a shield, minimalistic, vector, 2D, simple lines, White background --v 4"],
|
46 |
+
["Create a new logo for a [Color Tone: Blue] [Design Concept: MOUNTAIN] [Text: 'abc@gmail.com'] [Background: RED COLOR] "],
|
47 |
+
["Create a new logo for a [Color Tone: Blue] [Design Concept: HUMAN] [Text: 'ABC.COM'] [Background: YELLOW COLOR] "],
|
48 |
+
["Create a new logo for a [Color Tone: Blue] [Design Concept: HOUSE] [Text: 'T.010-1234-1234'] [Background: COLORFUL] "],
|
49 |
+
["Create a new logo for a [Color Tone: Blue] [Design Concept: LION] [Text: 'SOCCER CLUB'] [Background: GREEN COLOR]"]
|
50 |
+
]
|
51 |
+
|
52 |
+
css = """
|
53 |
+
footer {
|
54 |
+
visibility: hidden;
|
55 |
+
}
|
56 |
+
"""
|
57 |
+
|
58 |
+
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
59 |
+
with gr.Column(elem_id="col-container"):
|
60 |
+
with gr.Row():
|
61 |
+
prompt = gr.Text(
|
62 |
+
label="Prompt",
|
63 |
+
show_label=False,
|
64 |
+
max_lines=1,
|
65 |
+
placeholder="Enter your prompt",
|
66 |
+
container=False,
|
67 |
+
elem_id="prompt"
|
68 |
+
)
|
69 |
+
|
70 |
+
run_button = gr.Button("Run", scale=0)
|
71 |
+
|
72 |
+
result = gr.Image(label="Result", show_label=False, elem_id="result")
|
73 |
+
|
74 |
+
with gr.Accordion("Advanced Settings", open=False, elem_id="advanced-settings"):
|
75 |
+
seed = gr.Slider(
|
76 |
+
label="Seed",
|
77 |
+
minimum=0,
|
78 |
+
maximum=MAX_SEED,
|
79 |
+
step=1,
|
80 |
+
value=0,
|
81 |
+
)
|
82 |
+
|
83 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
84 |
+
|
85 |
+
with gr.Row():
|
86 |
+
width = gr.Slider(
|
87 |
+
label="Width",
|
88 |
+
minimum=256,
|
89 |
+
maximum=MAX_IMAGE_SIZE,
|
90 |
+
step=32,
|
91 |
+
value=512,
|
92 |
+
)
|
93 |
+
|
94 |
+
height = gr.Slider(
|
95 |
+
label="Height",
|
96 |
+
minimum=256,
|
97 |
+
maximum=MAX_IMAGE_SIZE,
|
98 |
+
step=32,
|
99 |
+
value=512,
|
100 |
+
)
|
101 |
+
|
102 |
+
with gr.Row():
|
103 |
+
num_inference_steps = gr.Slider(
|
104 |
+
label="Number of inference steps",
|
105 |
+
minimum=1,
|
106 |
+
maximum=50,
|
107 |
+
step=1,
|
108 |
+
value=4,
|
109 |
+
)
|
110 |
+
|
111 |
+
gr.Examples(
|
112 |
+
examples=examples,
|
113 |
+
fn=infer,
|
114 |
+
inputs=[prompt],
|
115 |
+
outputs=[result, seed],
|
116 |
+
cache_examples="lazy"
|
117 |
+
)
|
118 |
+
|
119 |
+
gr.on(
|
120 |
+
triggers=[run_button.click, prompt.submit],
|
121 |
+
fn=infer,
|
122 |
+
inputs=[prompt, seed, randomize_seed, width, height, num_inference_steps],
|
123 |
+
outputs=[result, seed]
|
124 |
+
)
|
125 |
+
|
126 |
+
demo.launch()
|