Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,7 @@ model_options = {
|
|
| 14 |
"PonyRealism": "John6666/pony-realism-v21main-sdxl"
|
| 15 |
}
|
| 16 |
|
| 17 |
-
#
|
| 18 |
style_list = [
|
| 19 |
{
|
| 20 |
"name": "(No style)",
|
|
@@ -33,7 +33,7 @@ style_list = [
|
|
| 33 |
},
|
| 34 |
{
|
| 35 |
"name": "Anime",
|
| 36 |
-
"prompt": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime,
|
| 37 |
"negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast",
|
| 38 |
},
|
| 39 |
{
|
|
@@ -53,7 +53,7 @@ style_list = [
|
|
| 53 |
},
|
| 54 |
{
|
| 55 |
"name": "Fantasy art",
|
| 56 |
-
"prompt": "ethereal fantasy concept art of
|
| 57 |
"negative_prompt": "photographic, realistic, realism, 35mm film, dslr, cropped, frame, text, deformed, glitch, noise, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, sloppy, duplicate, mutated, black and white",
|
| 58 |
},
|
| 59 |
{
|
|
@@ -68,10 +68,12 @@ style_list = [
|
|
| 68 |
},
|
| 69 |
]
|
| 70 |
|
|
|
|
| 71 |
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
| 72 |
STYLE_NAMES = list(styles.keys())
|
| 73 |
DEFAULT_STYLE_NAME = "(No style)"
|
| 74 |
|
|
|
|
| 75 |
def apply_style(style_name: str, positive: str, negative: str = "") -> tuple[str, str]:
|
| 76 |
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
| 77 |
return p.replace("{prompt}", positive), n + negative
|
|
@@ -128,12 +130,12 @@ def generate_image(images, model_choice, style_name, prompt, negative_prompt, fa
|
|
| 128 |
faceid_all_embeds.append(faceid_embed)
|
| 129 |
|
| 130 |
average_embedding = torch.mean(torch.stack(faceid_all_embeds, dim=0), dim=0)
|
| 131 |
-
|
| 132 |
-
# Apply
|
| 133 |
-
|
| 134 |
-
|
| 135 |
image = ip_model.generate(
|
| 136 |
-
prompt=
|
| 137 |
scale=likeness_strength, width=width, height=height, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps
|
| 138 |
)
|
| 139 |
|
|
@@ -155,7 +157,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 155 |
with gr.Row():
|
| 156 |
with gr.Column():
|
| 157 |
model_dropdown = gr.Dropdown(label="Select Model", choices=list(model_options.keys()), value="PonyRealism")
|
| 158 |
-
style_dropdown = gr.Dropdown(label="
|
| 159 |
files = gr.Files(label="Drag 1 or more photos of your face", file_types=["image"])
|
| 160 |
uploaded_files = gr.Gallery(label="Your images", visible=False, columns=5, rows=1, height=250)
|
| 161 |
with gr.Column(visible=False) as clear_button:
|
|
|
|
| 14 |
"PonyRealism": "John6666/pony-realism-v21main-sdxl"
|
| 15 |
}
|
| 16 |
|
| 17 |
+
# Full style list for applying styles to the prompt
|
| 18 |
style_list = [
|
| 19 |
{
|
| 20 |
"name": "(No style)",
|
|
|
|
| 33 |
},
|
| 34 |
{
|
| 35 |
"name": "Anime",
|
| 36 |
+
"prompt": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed",
|
| 37 |
"negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast",
|
| 38 |
},
|
| 39 |
{
|
|
|
|
| 53 |
},
|
| 54 |
{
|
| 55 |
"name": "Fantasy art",
|
| 56 |
+
"prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
|
| 57 |
"negative_prompt": "photographic, realistic, realism, 35mm film, dslr, cropped, frame, text, deformed, glitch, noise, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, sloppy, duplicate, mutated, black and white",
|
| 58 |
},
|
| 59 |
{
|
|
|
|
| 68 |
},
|
| 69 |
]
|
| 70 |
|
| 71 |
+
# Styles dictionary to map style names to prompts and negative prompts
|
| 72 |
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
| 73 |
STYLE_NAMES = list(styles.keys())
|
| 74 |
DEFAULT_STYLE_NAME = "(No style)"
|
| 75 |
|
| 76 |
+
# Function to apply the selected style
|
| 77 |
def apply_style(style_name: str, positive: str, negative: str = "") -> tuple[str, str]:
|
| 78 |
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
| 79 |
return p.replace("{prompt}", positive), n + negative
|
|
|
|
| 130 |
faceid_all_embeds.append(faceid_embed)
|
| 131 |
|
| 132 |
average_embedding = torch.mean(torch.stack(faceid_all_embeds, dim=0), dim=0)
|
| 133 |
+
|
| 134 |
+
# Apply the selected style
|
| 135 |
+
styled_prompt, styled_negative_prompt = apply_style(style_name, prompt, negative_prompt)
|
| 136 |
+
|
| 137 |
image = ip_model.generate(
|
| 138 |
+
prompt=styled_prompt, negative_prompt=styled_negative_prompt, faceid_embeds=average_embedding,
|
| 139 |
scale=likeness_strength, width=width, height=height, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps
|
| 140 |
)
|
| 141 |
|
|
|
|
| 157 |
with gr.Row():
|
| 158 |
with gr.Column():
|
| 159 |
model_dropdown = gr.Dropdown(label="Select Model", choices=list(model_options.keys()), value="PonyRealism")
|
| 160 |
+
style_dropdown = gr.Dropdown(label="Style", choices=STYLE_NAMES, value=DEFAULT_STYLE_NAME)
|
| 161 |
files = gr.Files(label="Drag 1 or more photos of your face", file_types=["image"])
|
| 162 |
uploaded_files = gr.Gallery(label="Your images", visible=False, columns=5, rows=1, height=250)
|
| 163 |
with gr.Column(visible=False) as clear_button:
|