Update everything
Browse files
app.py
CHANGED
@@ -5,57 +5,55 @@ import random
|
|
5 |
import os
|
6 |
from PIL import Image
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def select_model(model_name):
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
"stabilityai/stable-diffusion-xl-base-1.0",
|
20 |
-
"prompthero/openjourney-v4",
|
21 |
-
"nerijs/pixel-art-xl",
|
22 |
-
"Linaqruf/anything-v3.0"
|
23 |
-
]
|
24 |
|
25 |
-
def query(prompt, is_negative=False, steps=1, cfg_scale=6, seed=None):
|
26 |
payload = {
|
27 |
"inputs": prompt,
|
28 |
"is_negative": is_negative,
|
29 |
"steps": steps,
|
30 |
"cfg_scale": cfg_scale,
|
31 |
"seed": seed if seed is not None else random.randint(-1, 2147483647)
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
36 |
return image
|
37 |
|
38 |
-
|
39 |
with gr.Blocks(theme="soft") as playground:
|
40 |
gr.HTML(
|
41 |
"""
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
>
|
51 |
-
<h1 style="font-weight: 900; margin-bottom: 7px;margin-top:5px">
|
52 |
-
Play with SD Models
|
53 |
-
</h1>
|
54 |
-
</div>
|
55 |
-
<p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">
|
56 |
-
Create your AI art with Stable Diffusion models!
|
57 |
-
</p>
|
58 |
-
</div>
|
59 |
"""
|
60 |
)
|
61 |
|
@@ -63,11 +61,12 @@ with gr.Blocks(theme="soft") as playground:
|
|
63 |
image_output = gr.Image(type="pil", label="Output Image", elem_id="gallery")
|
64 |
with gr.Column(elem_id="prompt-container"):
|
65 |
text_prompt = gr.Textbox(label="Prompt", placeholder="a cute cat", lines=1, elem_id="prompt-text-input")
|
|
|
66 |
text_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
|
67 |
|
68 |
with gr.Accordion("Advanced settings", open=False):
|
69 |
negative_prompt = gr.Textbox(label="Negative Prompt", value="text, blurry, fuzziness", lines=1, elem_id="negative-prompt-text-input")
|
70 |
|
71 |
-
text_button.click(query, inputs=[text_prompt, negative_prompt], outputs=image_output)
|
72 |
|
73 |
playground.launch(show_api=False)
|
|
|
5 |
import os
|
6 |
from PIL import Image
|
7 |
|
8 |
+
API_BASE_URL = "https://api-inference.huggingface.co/models/"
|
9 |
+
MODEL_LIST = [
|
10 |
+
"openskyml/dalle-3-xl",
|
11 |
+
"Linaqruf/animagine-xl-2.0",
|
12 |
+
"Lykon/dreamshaper-7",
|
13 |
+
"Linaqruf/animagine-xl",
|
14 |
+
"runwayml/stable-diffusion-v1-5",
|
15 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
16 |
+
"prompthero/openjourney-v4",
|
17 |
+
"nerijs/pixel-art-xl",
|
18 |
+
"Linaqruf/anything-v3.0"
|
19 |
+
]
|
20 |
+
API_TOKEN = os.getenv("HF_READ_TOKEN") # Make sure to set your Hugging Face token
|
21 |
+
HEADERS = {"Authorization": f"Bearer {API_TOKEN}"}
|
22 |
|
23 |
def select_model(model_name):
|
24 |
+
if model_name in MODEL_LIST:
|
25 |
+
return API_BASE_URL + model_name
|
26 |
+
|
27 |
+
def query(prompt, selected_model, is_negative=False, steps=1, cfg_scale=6, seed=None):
|
28 |
+
model_url = select_model(selected_model)
|
29 |
+
API_URL = f"{model_url}"
|
|
|
|
|
|
|
|
|
|
|
30 |
|
|
|
31 |
payload = {
|
32 |
"inputs": prompt,
|
33 |
"is_negative": is_negative,
|
34 |
"steps": steps,
|
35 |
"cfg_scale": cfg_scale,
|
36 |
"seed": seed if seed is not None else random.randint(-1, 2147483647)
|
37 |
+
}
|
38 |
|
39 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
40 |
+
response.raise_for_status()
|
41 |
+
|
42 |
+
image_bytes = io.BytesIO(response.content)
|
43 |
+
image = Image.open(image_bytes)
|
44 |
return image
|
45 |
|
|
|
46 |
with gr.Blocks(theme="soft") as playground:
|
47 |
gr.HTML(
|
48 |
"""
|
49 |
+
<div style="text-align: center; margin: 0 auto;">
|
50 |
+
<div style="display: inline-flex; align-items: center; gap: 0.8rem; font-size: 1.75rem;">
|
51 |
+
<h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;">Play with SD Models</h1>
|
52 |
+
</div>
|
53 |
+
<p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">
|
54 |
+
Create your AI art with Stable Diffusion models!
|
55 |
+
</p>
|
56 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
"""
|
58 |
)
|
59 |
|
|
|
61 |
image_output = gr.Image(type="pil", label="Output Image", elem_id="gallery")
|
62 |
with gr.Column(elem_id="prompt-container"):
|
63 |
text_prompt = gr.Textbox(label="Prompt", placeholder="a cute cat", lines=1, elem_id="prompt-text-input")
|
64 |
+
model_dropdown = gr.Dropdown(label="Select Model", choices=MODEL_LIST, elem_id="model-dropdown")
|
65 |
text_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
|
66 |
|
67 |
with gr.Accordion("Advanced settings", open=False):
|
68 |
negative_prompt = gr.Textbox(label="Negative Prompt", value="text, blurry, fuzziness", lines=1, elem_id="negative-prompt-text-input")
|
69 |
|
70 |
+
text_button.click(query, inputs=[text_prompt, model_dropdown, negative_prompt], outputs=image_output)
|
71 |
|
72 |
playground.launch(show_api=False)
|