Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,25 @@ import random
|
|
5 |
import os
|
6 |
from PIL import Image
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
list_models = [
|
9 |
"SDXL-1.0",
|
10 |
"SD-1.5",
|
@@ -39,6 +58,8 @@ def generate_txt2img(current_model, prompt, is_negative=False, image_style="None
|
|
39 |
API_TOKEN = os.environ.get("HF_READ_TOKEN")
|
40 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
41 |
|
|
|
|
|
42 |
|
43 |
if image_style == "None style":
|
44 |
payload = {
|
@@ -181,7 +202,7 @@ with gr.Blocks(css=css) as demo:
|
|
181 |
|
182 |
favicon = '<img src="" width="48px" style="display: inline">'
|
183 |
gr.Markdown(
|
184 |
-
f"""<h1><center
|
185 |
"""
|
186 |
)
|
187 |
|
@@ -189,8 +210,15 @@ with gr.Blocks(css=css) as demo:
|
|
189 |
current_model = gr.Dropdown(label="Current Model", choices=list_models, value=list_models[1])
|
190 |
|
191 |
with gr.Row(elem_id="prompt-container"):
|
192 |
-
text_prompt = gr.Textbox(label="Prompt", placeholder="a cute dog", lines=1, elem_id="prompt-text-input")
|
193 |
text_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
|
195 |
with gr.Row():
|
196 |
image_output = gr.Image(type="pil", label="Output Image", elem_id="gallery")
|
@@ -200,5 +228,7 @@ with gr.Blocks(css=css) as demo:
|
|
200 |
image_style = gr.Dropdown(label="Style", choices=["None style", "Cinematic", "Digital Art", "Portrait"], value="None style", allow_custom_value=False)
|
201 |
|
202 |
text_button.click(generate_txt2img, inputs=[current_model, text_prompt, negative_prompt, image_style], outputs=image_output)
|
|
|
|
|
203 |
|
204 |
demo.launch(show_api=False)
|
|
|
5 |
import os
|
6 |
from PIL import Image
|
7 |
|
8 |
+
from datasets import load_dataset
|
9 |
+
|
10 |
+
dataset = load_dataset("Gustavosta/Stable-Diffusion-Prompts")
|
11 |
+
prompt_df = dataset["train"].to_pandas()
|
12 |
+
|
13 |
+
#DEFAULT_MODEL = "stabilityai/stable-diffusion-2-1"
|
14 |
+
DEFAULT_PROMPT = "1girl, aqua eyes, baseball cap, blonde hair, closed mouth, earrings, green background, hat, hoop earrings, jewelry, looking at viewer, shirt, short hair, simple background, solo, upper body, yellow shirt"
|
15 |
+
|
16 |
+
def get_samples():
|
17 |
+
prompt_list = prompt_df.sample(n = 10)["Prompt"].map(lambda x: x).values.tolist()
|
18 |
+
return prompt_list
|
19 |
+
|
20 |
+
def get_params(request: gr.Request):
|
21 |
+
params = request.query_params
|
22 |
+
ip = request.client.host
|
23 |
+
req = {"params": params,
|
24 |
+
"ip": ip}
|
25 |
+
return get_samples()
|
26 |
+
|
27 |
list_models = [
|
28 |
"SDXL-1.0",
|
29 |
"SD-1.5",
|
|
|
58 |
API_TOKEN = os.environ.get("HF_READ_TOKEN")
|
59 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
60 |
|
61 |
+
if type(prompt) != type(""):
|
62 |
+
prompt = DEFAULT_PROMPT
|
63 |
|
64 |
if image_style == "None style":
|
65 |
payload = {
|
|
|
202 |
|
203 |
favicon = '<img src="" width="48px" style="display: inline">'
|
204 |
gr.Markdown(
|
205 |
+
f"""<h1><center>🌻{favicon} AI Diffusion</center></h1>
|
206 |
"""
|
207 |
)
|
208 |
|
|
|
210 |
current_model = gr.Dropdown(label="Current Model", choices=list_models, value=list_models[1])
|
211 |
|
212 |
with gr.Row(elem_id="prompt-container"):
|
213 |
+
text_prompt = gr.Textbox(label="Prompt", placeholder="a cute dog", lines=1, elem_id="prompt-text-input", value = DEFAULT_PROMPT)
|
214 |
text_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
|
215 |
+
|
216 |
+
with gr.Row("prompt-container"):
|
217 |
+
select_prompt = gr.Dropdown(label="Prompt selected", choices=list_prompts,
|
218 |
+
value = "1girl, aqua eyes, baseball cap, blonde hair, closed mouth, earrings, green background, hat, hoop earrings, jewelry, looking at viewer, shirt, short hair, simple background, solo, upper body, yellow shirt",
|
219 |
+
info = "default prompt: {}".format(DEFAULT_PROMPT)
|
220 |
+
)
|
221 |
+
select_button = gr.Button("Select Prompt Generate", variant='primary', elem_id="gen-button")
|
222 |
|
223 |
with gr.Row():
|
224 |
image_output = gr.Image(type="pil", label="Output Image", elem_id="gallery")
|
|
|
228 |
image_style = gr.Dropdown(label="Style", choices=["None style", "Cinematic", "Digital Art", "Portrait"], value="None style", allow_custom_value=False)
|
229 |
|
230 |
text_button.click(generate_txt2img, inputs=[current_model, text_prompt, negative_prompt, image_style], outputs=image_output)
|
231 |
+
select_button.click(generate_txt2img, inputs=[current_model, select_prompt, negative_prompt, image_style], outputs=image_output)
|
232 |
+
demo.load(get_params, None, select_prompt)
|
233 |
|
234 |
demo.launch(show_api=False)
|