Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,67 +10,64 @@ API_URL = "https://api-inference.huggingface.co/models/cagliostrolab/animagine-x
|
|
10 |
API_TOKEN = os.getenv("HF_READ_TOKEN") # it is free
|
11 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
12 |
|
13 |
-
def query(prompt, is_negative=False, steps=37, cfg_scale=8, seed=None):
|
14 |
payload = {
|
15 |
"inputs": prompt,
|
16 |
"is_negative": is_negative,
|
17 |
"steps": steps,
|
18 |
"cfg_scale": cfg_scale,
|
19 |
-
"seed": seed if seed is not None else random.randint(-1, 2147483647)
|
|
|
|
|
20 |
}
|
21 |
|
22 |
image_bytes = requests.post(API_URL, headers=headers, json=payload).content
|
23 |
image = Image.open(io.BytesIO(image_bytes))
|
24 |
return image
|
25 |
css = """
|
26 |
-
body {
|
27 |
-
background-color: #fafafa !important;
|
28 |
-
}
|
29 |
-
.title {
|
30 |
-
font-size: 1em !important;
|
31 |
-
text-align: center;
|
32 |
-
color: #333;
|
33 |
-
font-family: 'Helvetica Neue', sans-serif;
|
34 |
-
text-transform: uppercase;
|
35 |
-
letter-spacing: 0.1em;
|
36 |
-
padding: 0.5em 0;
|
37 |
-
background: transparent;
|
38 |
-
}
|
39 |
-
|
40 |
-
.title span {
|
41 |
-
background: -webkit-linear-gradient(45deg, #7ed56f, #28b485);
|
42 |
-
-webkit-background-clip: text;
|
43 |
-
-webkit-text-fill-color: transparent;
|
44 |
-
font-size: 2.5em;
|
45 |
-
}
|
46 |
-
.primary.svelte-cmf5ev {
|
47 |
-
background: -webkit-linear-gradient(45deg, #7ed56f, #28b485) !important;
|
48 |
-
}
|
49 |
-
.svelte-15lo0d8 {
|
50 |
-
flex-direction: column !important;
|
51 |
-
}
|
52 |
.footer {
|
53 |
display: none;
|
54 |
}
|
55 |
"""
|
56 |
|
57 |
with gr.Blocks(css=css) as Animagine:
|
58 |
-
gr.HTML(
|
59 |
-
"""
|
60 |
-
<div style="text-align: center; margin: 0 auto;">
|
61 |
-
<div style="display: inline-flex; align-items: center; gap: 0.8rem;">
|
62 |
-
<h1 class="title">
|
63 |
-
<span>Animagine XL 3.1</span>
|
64 |
-
</h1>
|
65 |
-
</div>
|
66 |
-
</div>
|
67 |
-
"""
|
68 |
-
)
|
69 |
with gr.Row():
|
70 |
-
with gr.Column(
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
Animagine.queue(max_size=200).launch(show_api=False)
|
|
|
10 |
API_TOKEN = os.getenv("HF_READ_TOKEN") # it is free
|
11 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
12 |
|
13 |
+
def query(prompt, is_negative=False, width, height, steps=37, cfg_scale=8, seed=None):
|
14 |
payload = {
|
15 |
"inputs": prompt,
|
16 |
"is_negative": is_negative,
|
17 |
"steps": steps,
|
18 |
"cfg_scale": cfg_scale,
|
19 |
+
"seed": seed if seed is not None else random.randint(-1, 2147483647),
|
20 |
+
"width": width,
|
21 |
+
"height": height
|
22 |
}
|
23 |
|
24 |
image_bytes = requests.post(API_URL, headers=headers, json=payload).content
|
25 |
image = Image.open(io.BytesIO(image_bytes))
|
26 |
return image
|
27 |
css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
.footer {
|
29 |
display: none;
|
30 |
}
|
31 |
"""
|
32 |
|
33 |
with gr.Blocks(css=css) as Animagine:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
with gr.Row():
|
35 |
+
with gr.Column():
|
36 |
+
with gr.Tab("Базовые настройки"):
|
37 |
+
with gr.Row():
|
38 |
+
with gr.Column(elem_id="prompt-container"):
|
39 |
+
text_prompt = gr.Textbox(label="Prompt", placeholder="Описание изображения", lines=1, elem_id="prompt-text-input")
|
40 |
+
|
41 |
+
|
42 |
+
with gr.Tab("Расширенные настройки"):
|
43 |
+
with gr.Row():
|
44 |
+
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="Чего не должно быть на изображении", value="[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry", lines=1, elem_id="negative-prompt-text-input")
|
45 |
+
with gr.Row():
|
46 |
+
steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=70, step=1)
|
47 |
+
with gr.Row():
|
48 |
+
cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=1)
|
49 |
+
with gr.Row():
|
50 |
+
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
51 |
+
|
52 |
+
with gr.Tab("Beta"):
|
53 |
+
with gr.Row():
|
54 |
+
width = gr.Slider(label="Ширина", minimum=15, maximum=2000, value=1024, step=1)
|
55 |
+
height = gr.Slider(label="Высота", minimum=15, maximum=2000, value=1024, step=1)
|
56 |
+
|
57 |
+
with gr.Tab("Информация"):
|
58 |
+
with gr.Row():
|
59 |
+
gr.Textbox(label="Шаблон prompt", value="{prompt} | ultra detail, ultra elaboration, ultra quality, perfect.")
|
60 |
+
with gr.Row():
|
61 |
+
gr.HTML("""<button class="lg secondary svelte-cmf5ev" style="width: 100%;" onclick="window.open('http://ai-hub.rf.gd', '_blank');">AI-HUB</button>""")
|
62 |
+
gr.HTML("""<button class="lg secondary svelte-cmf5ev" style="width: 100%;" onclick="window.open('http://yufi.rf.gd', '_blank');">YUFI</button>""")
|
63 |
+
|
64 |
+
|
65 |
+
with gr.Row():
|
66 |
+
text_button = gr.Button("Генерация", variant='primary', elem_id="gen-button")
|
67 |
+
with gr.Column():
|
68 |
+
with gr.Row():
|
69 |
+
image_output = gr.Image(type="pil", label="Изображение", elem_id="gallery")
|
70 |
+
|
71 |
+
|
72 |
+
text_button.click(query, inputs=[text_prompt, negative_prompt, width, height, steps, cfg, seed], outputs=image_output)
|
73 |
Animagine.queue(max_size=200).launch(show_api=False)
|