Update app.py
Browse files
app.py
CHANGED
@@ -9,13 +9,14 @@ from typing import Tuple
|
|
9 |
from translatepy import Translator
|
10 |
|
11 |
MODEL = os.environ.get("MODEL")
|
|
|
12 |
DESCRIPTION = """
|
13 |
# IMGEN🧚♀️
|
14 |
-
<center>🧚♂️输入描述生成图片,选择喜欢的风格~<br
|
15 |
"""
|
16 |
MODEL_ID="stabilityai/sdxl-turbo"
|
17 |
-
|
18 |
-
LICENSE = "采用 " +
|
19 |
translator = Translator()
|
20 |
|
21 |
|
@@ -28,7 +29,7 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
28 |
MAX_SEED = np.iinfo(np.int32).max
|
29 |
|
30 |
client = Client(MODEL)
|
31 |
-
|
32 |
|
33 |
style_list = [
|
34 |
{
|
@@ -86,25 +87,38 @@ def generate(
|
|
86 |
steps: float = 1,
|
87 |
style: str = DEFAULT_STYLE_NAME,
|
88 |
randomize_seed: bool = False,
|
|
|
89 |
progress=gr.Progress(track_tqdm=True),
|
90 |
):
|
91 |
prompt = str(translator.translate(prompt, 'English'))
|
92 |
print(f'prompt:{prompt}')
|
93 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
94 |
-
print(client_test.view_api())
|
95 |
|
96 |
prompt = apply_style(style, prompt)
|
97 |
strength = 0.7
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
return images, seed
|
110 |
|
@@ -134,10 +148,10 @@ with gr.Blocks(css=CSS, theme="soft") as demo:
|
|
134 |
max_lines=1,
|
135 |
placeholder="画什么好呢",
|
136 |
container=False,
|
137 |
-
scale=
|
138 |
)
|
139 |
run_button = gr.Button("生成", scale=1)
|
140 |
-
result = gr.
|
141 |
with gr.Accordion("高级选项", open=False):
|
142 |
with gr.Row():
|
143 |
steps = gr.Slider(
|
@@ -156,6 +170,7 @@ with gr.Blocks(css=CSS, theme="soft") as demo:
|
|
156 |
visible=True
|
157 |
)
|
158 |
randomize_seed = gr.Checkbox(label="随机种子", value=True)
|
|
|
159 |
with gr.Row(visible=True):
|
160 |
style_selection = gr.Radio(
|
161 |
show_label=True,
|
@@ -189,6 +204,7 @@ with gr.Blocks(css=CSS, theme="soft") as demo:
|
|
189 |
steps,
|
190 |
style_selection,
|
191 |
randomize_seed,
|
|
|
192 |
],
|
193 |
outputs=[result, seed],
|
194 |
api_name="run",
|
|
|
9 |
from translatepy import Translator
|
10 |
|
11 |
MODEL = os.environ.get("MODEL")
|
12 |
+
|
13 |
DESCRIPTION = """
|
14 |
# IMGEN🧚♀️
|
15 |
+
<center>🧚♂️输入描述生成图片,选择喜欢的风格~<br>🧚默认使用Turbo快速生成,高级选项可更改。</center>
|
16 |
"""
|
17 |
MODEL_ID="stabilityai/sdxl-turbo"
|
18 |
+
|
19 |
+
LICENSE = "采用 " + SDXL +" 模型"
|
20 |
translator = Translator()
|
21 |
|
22 |
|
|
|
29 |
MAX_SEED = np.iinfo(np.int32).max
|
30 |
|
31 |
client = Client(MODEL)
|
32 |
+
client2 = Client(MODEL2)
|
33 |
|
34 |
style_list = [
|
35 |
{
|
|
|
87 |
steps: float = 1,
|
88 |
style: str = DEFAULT_STYLE_NAME,
|
89 |
randomize_seed: bool = False,
|
90 |
+
use_turbo: bool = True,
|
91 |
progress=gr.Progress(track_tqdm=True),
|
92 |
):
|
93 |
prompt = str(translator.translate(prompt, 'English'))
|
94 |
print(f'prompt:{prompt}')
|
95 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
96 |
+
# print(client_test.view_api())
|
97 |
|
98 |
prompt = apply_style(style, prompt)
|
99 |
strength = 0.7
|
100 |
+
if use_turbo:
|
101 |
+
result = client.predict(
|
102 |
+
None,
|
103 |
+
prompt,
|
104 |
+
seed,
|
105 |
+
strength,
|
106 |
+
steps,
|
107 |
+
fn_index=1
|
108 |
+
)
|
109 |
+
print(result)
|
110 |
+
images = MODEL+"file="+result
|
111 |
+
else:
|
112 |
+
seed = 0
|
113 |
+
result = client2.predict(
|
114 |
+
prompt,
|
115 |
+
None,
|
116 |
+
7.5,
|
117 |
+
"(No style)",
|
118 |
+
fn_index=3
|
119 |
+
)
|
120 |
+
print(result)
|
121 |
+
images = result["data"][0]
|
122 |
|
123 |
return images, seed
|
124 |
|
|
|
148 |
max_lines=1,
|
149 |
placeholder="画什么好呢",
|
150 |
container=False,
|
151 |
+
scale=3,
|
152 |
)
|
153 |
run_button = gr.Button("生成", scale=1)
|
154 |
+
result = gr.Gallery(label="作品", columns = 1, preview=True)
|
155 |
with gr.Accordion("高级选项", open=False):
|
156 |
with gr.Row():
|
157 |
steps = gr.Slider(
|
|
|
170 |
visible=True
|
171 |
)
|
172 |
randomize_seed = gr.Checkbox(label="随机种子", value=True)
|
173 |
+
use_turbo = gr.Checkbox(label="快速生成", value=True)
|
174 |
with gr.Row(visible=True):
|
175 |
style_selection = gr.Radio(
|
176 |
show_label=True,
|
|
|
204 |
steps,
|
205 |
style_selection,
|
206 |
randomize_seed,
|
207 |
+
use_turbo,
|
208 |
],
|
209 |
outputs=[result, seed],
|
210 |
api_name="run",
|