Spaces:
Running
Running
first
Browse files- README.md +5 -5
- app.py +133 -0
- examples/newton_man/newton_0.jpg +0 -0
- examples/newton_man/newton_1.jpg +0 -0
- examples/newton_man/newton_3.jpg +0 -0
- examples/scarletthead_woman/scarlett_0.jpg +0 -0
- examples/scarletthead_woman/scarlett_1.jpg +0 -0
- examples/scarletthead_woman/scarlett_2.jpg +0 -0
- examples/scarletthead_woman/scarlett_3.jpg +0 -0
- requirements.txt +2 -0
- style_template.py +59 -0
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.29.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
|
|
1 |
---
|
2 |
+
title: photo-maker
|
3 |
+
emoji: 📷
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: blue
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.29.0fir
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
app.py
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from prodiapy import Prodia
|
3 |
+
import gradio as gr
|
4 |
+
from style_template import styles
|
5 |
+
import base64
|
6 |
+
|
7 |
+
prodia = Prodia()
|
8 |
+
STYLE_NAMES = list(styles.keys())
|
9 |
+
DEFAULT_STYLE_NAME = "Photographic (Default)"
|
10 |
+
|
11 |
+
|
12 |
+
def generate_image(upload_images, prompt, negative_prompt, style_name, steps, progress=gr.Progress(track_tqdm=True)):
|
13 |
+
p, n = apply_style(style_name, prompt, negative_prompt)
|
14 |
+
|
15 |
+
job = prodia.create("/photomaker",
|
16 |
+
imageData=[file_to_base64(img) for img in upload_images],
|
17 |
+
prompt=p,
|
18 |
+
negative_prompt=n,
|
19 |
+
steps=steps
|
20 |
+
)
|
21 |
+
result = prodia.wait(job)
|
22 |
+
|
23 |
+
return result.image_url
|
24 |
+
|
25 |
+
|
26 |
+
def swap_to_gallery(images):
|
27 |
+
return gr.update(value=images, visible=True), gr.update(visible=True), gr.update(visible=False)
|
28 |
+
|
29 |
+
|
30 |
+
def upload_example_to_gallery(images, prompt, style, negative_prompt):
|
31 |
+
return gr.update(value=images, visible=True), gr.update(visible=True), gr.update(visible=False)
|
32 |
+
|
33 |
+
|
34 |
+
def remove_back_to_files():
|
35 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
36 |
+
|
37 |
+
|
38 |
+
def apply_style(style_name: str, positive: str, negative: str = "") -> tuple[str, str]:
|
39 |
+
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
40 |
+
return p.replace("{prompt}", positive), n + ' ' + negative
|
41 |
+
|
42 |
+
|
43 |
+
def get_image_path_list(folder_name):
|
44 |
+
image_basename_list = os.listdir(folder_name)
|
45 |
+
image_path_list = sorted([os.path.join(folder_name, basename) for basename in image_basename_list])
|
46 |
+
return image_path_list
|
47 |
+
|
48 |
+
|
49 |
+
def file_to_base64(file_path):
|
50 |
+
with open(file_path, "rb") as file:
|
51 |
+
file_data = file.read()
|
52 |
+
base64_string = base64.b64encode(file_data).decode('utf-8')
|
53 |
+
return base64_string
|
54 |
+
|
55 |
+
|
56 |
+
def get_example():
|
57 |
+
case = [
|
58 |
+
[
|
59 |
+
get_image_path_list('./examples/scarletthead_woman'),
|
60 |
+
"instagram photo, portrait photo of a woman img, colorful, perfect face, natural skin, hard shadows, film grain",
|
61 |
+
"(No style)",
|
62 |
+
"(asymmetry, worst quality, low quality, illustration, 3d, 2d, painting, cartoons, sketch), open mouth",
|
63 |
+
],
|
64 |
+
[
|
65 |
+
get_image_path_list('./examples/newton_man'),
|
66 |
+
"sci-fi, closeup portrait photo of a man img wearing the sunglasses in Iron man suit, face, slim body, high quality, film grain",
|
67 |
+
"(No style)",
|
68 |
+
"(asymmetry, worst quality, low quality, illustration, 3d, 2d, painting, cartoons, sketch), open mouth",
|
69 |
+
],
|
70 |
+
]
|
71 |
+
return case
|
72 |
+
|
73 |
+
|
74 |
+
title = r"""
|
75 |
+
<h1 align="center">PhotoMaker: Customizing Realistic Human Photos via Stacked ID Embedding</h1>
|
76 |
+
"""
|
77 |
+
|
78 |
+
css = '''
|
79 |
+
.gradio-container {width: 85% !important}
|
80 |
+
'''
|
81 |
+
with gr.Blocks(css=css) as demo:
|
82 |
+
gr.Markdown(title)
|
83 |
+
|
84 |
+
with gr.Row():
|
85 |
+
with gr.Column():
|
86 |
+
files = gr.File(
|
87 |
+
label="Drag (Select) 1 or more photos of your face",
|
88 |
+
file_types=["image"],
|
89 |
+
file_count="multiple"
|
90 |
+
)
|
91 |
+
uploaded_files = gr.Gallery(label="Your images", visible=False, columns=5, rows=1, height=200)
|
92 |
+
with gr.Column(visible=False) as clear_button:
|
93 |
+
remove_and_reupload = gr.ClearButton(value="Remove and upload new ones", components=files, size="sm")
|
94 |
+
prompt = gr.Textbox(label="Prompt",
|
95 |
+
info="Try something like 'a photo of a man/woman img', 'img' is the trigger word.",
|
96 |
+
placeholder="A photo of a [man/woman img]...")
|
97 |
+
style = gr.Dropdown(label="Style template", choices=STYLE_NAMES, value=DEFAULT_STYLE_NAME)
|
98 |
+
submit = gr.Button("Submit")
|
99 |
+
|
100 |
+
with gr.Accordion(open=False, label="Advanced Options"):
|
101 |
+
negative_prompt = gr.Textbox(
|
102 |
+
label="Negative Prompt",
|
103 |
+
placeholder="low quality",
|
104 |
+
value="nsfw, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry",
|
105 |
+
)
|
106 |
+
steps = gr.Slider(
|
107 |
+
label="Number of sample steps",
|
108 |
+
minimum=20,
|
109 |
+
maximum=50,
|
110 |
+
step=1,
|
111 |
+
value=40,
|
112 |
+
)
|
113 |
+
with gr.Column():
|
114 |
+
result_image = gr.Image(label="Generated Image")
|
115 |
+
|
116 |
+
files.upload(fn=swap_to_gallery, inputs=files, outputs=[uploaded_files, clear_button, files])
|
117 |
+
remove_and_reupload.click(fn=remove_back_to_files, outputs=[uploaded_files, clear_button, files])
|
118 |
+
|
119 |
+
submit.click(
|
120 |
+
fn=generate_image,
|
121 |
+
inputs=[files, prompt, negative_prompt, style, steps],
|
122 |
+
outputs=[result_image]
|
123 |
+
)
|
124 |
+
|
125 |
+
gr.Examples(
|
126 |
+
examples=get_example(),
|
127 |
+
inputs=[files, prompt, style, negative_prompt],
|
128 |
+
run_on_click=True,
|
129 |
+
fn=upload_example_to_gallery,
|
130 |
+
outputs=[uploaded_files, clear_button, files],
|
131 |
+
)
|
132 |
+
|
133 |
+
demo.queue(max_size=20).launch(show_api=False)
|
examples/newton_man/newton_0.jpg
ADDED
examples/newton_man/newton_1.jpg
ADDED
examples/newton_man/newton_3.jpg
ADDED
examples/scarletthead_woman/scarlett_0.jpg
ADDED
examples/scarletthead_woman/scarlett_1.jpg
ADDED
examples/scarletthead_woman/scarlett_2.jpg
ADDED
examples/scarletthead_woman/scarlett_3.jpg
ADDED
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
prodiapy==5.1.2
|
2 |
+
gradio==4.29.0
|
style_template.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
style_list = [
|
2 |
+
{
|
3 |
+
"name": "(No style)",
|
4 |
+
"prompt": "{prompt}",
|
5 |
+
"negative_prompt": "",
|
6 |
+
},
|
7 |
+
{
|
8 |
+
"name": "Cinematic",
|
9 |
+
"prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
|
10 |
+
"negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
|
11 |
+
},
|
12 |
+
{
|
13 |
+
"name": "Disney Charactor",
|
14 |
+
"prompt": "A Pixar animation character of {prompt} . pixar-style, studio anime, Disney, high-quality",
|
15 |
+
"negative_prompt": "lowres, bad anatomy, bad hands, text, bad eyes, bad arms, bad legs, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, blurry, grayscale, noisy, sloppy, messy, grainy, highly detailed, ultra textured, photo",
|
16 |
+
},
|
17 |
+
{
|
18 |
+
"name": "Digital Art",
|
19 |
+
"prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed",
|
20 |
+
"negative_prompt": "photo, photorealistic, realism, ugly",
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"name": "Photographic (Default)",
|
24 |
+
"prompt": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed",
|
25 |
+
"negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly",
|
26 |
+
},
|
27 |
+
{
|
28 |
+
"name": "Fantasy art",
|
29 |
+
"prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
|
30 |
+
"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",
|
31 |
+
},
|
32 |
+
{
|
33 |
+
"name": "Neonpunk",
|
34 |
+
"prompt": "neonpunk style {prompt} . cyberpunk, vaporwave, neon, vibes, vibrant, stunningly beautiful, crisp, detailed, sleek, ultramodern, magenta highlights, dark purple shadows, high contrast, cinematic, ultra detailed, intricate, professional",
|
35 |
+
"negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured",
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"name": "Enhance",
|
39 |
+
"prompt": "breathtaking {prompt} . award-winning, professional, highly detailed",
|
40 |
+
"negative_prompt": "ugly, deformed, noisy, blurry, distorted, grainy",
|
41 |
+
},
|
42 |
+
{
|
43 |
+
"name": "Comic book",
|
44 |
+
"prompt": "comic {prompt} . graphic illustration, comic art, graphic novel art, vibrant, highly detailed",
|
45 |
+
"negative_prompt": "photograph, deformed, glitch, noisy, realistic, stock photo",
|
46 |
+
},
|
47 |
+
{
|
48 |
+
"name": "Lowpoly",
|
49 |
+
"prompt": "low-poly style {prompt} . low-poly game art, polygon mesh, jagged, blocky, wireframe edges, centered composition",
|
50 |
+
"negative_prompt": "noisy, sloppy, messy, grainy, highly detailed, ultra textured, photo",
|
51 |
+
},
|
52 |
+
{
|
53 |
+
"name": "Line art",
|
54 |
+
"prompt": "line art drawing {prompt} . professional, sleek, modern, minimalist, graphic, line art, vector graphics",
|
55 |
+
"negative_prompt": "anime, photorealistic, 35mm film, deformed, glitch, blurry, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, mutated, realism, realistic, impressionism, expressionism, oil, acrylic",
|
56 |
+
}
|
57 |
+
]
|
58 |
+
|
59 |
+
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|