shuhao
commited on
Commit
•
7cbf24f
1
Parent(s):
89cedc9
init
Browse files- README.md +7 -6
- app.py +371 -0
- assets/id_imgs/0047.jpg +0 -0
- assets/id_imgs/0048.jpg +0 -0
- assets/id_imgs/0049.jpg +0 -0
- assets/id_imgs/0050.jpg +0 -0
- assets/id_imgs/0051.jpg +0 -0
- assets/id_imgs/0053.jpg +0 -0
- assets/id_imgs/0054.jpg +0 -0
- assets/id_imgs/0055.jpg +0 -0
- assets/id_imgs/0056.jpg +0 -0
- assets/outputs/190811.jpg +0 -0
- assets/outputs/190812.jpg +0 -0
- assets/outputs/190813.jpg +0 -0
- assets/outputs/190814.jpg +0 -0
- assets/outputs/190815.jpg +0 -0
- assets/outputs/190816.jpg +0 -0
- assets/outputs/190818.jpg +0 -0
- assets/outputs/190819.jpg +0 -0
- assets/outputs/190820.jpg +0 -0
- assets/refer_imgs/0006.jpg +0 -0
- assets/refer_imgs/0007.jpg +0 -0
- assets/refer_imgs/0008.jpg +0 -0
- assets/refer_imgs/man0004.jpg +0 -0
- assets/refer_imgs/man0006.jpg +0 -0
- assets/refer_imgs/man0007.jpg +0 -0
- assets/refer_imgs/z0001.jpg +0 -0
- assets/refer_imgs/z0002.jpg +0 -0
- assets/refer_imgs/z0003.jpg +0 -0
- requirements.txt +6 -0
- title.md +11 -0
README.md
CHANGED
@@ -1,14 +1,15 @@
|
|
1 |
---
|
2 |
title: Kolors Portrait With Flux
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
app_file: app.py
|
9 |
-
pinned: false
|
10 |
license: apache-2.0
|
11 |
-
short_description:
|
|
|
|
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: Kolors Portrait With Flux
|
3 |
+
emoji: 🖼
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: red
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 5.0.1
|
8 |
app_file: app.py
|
|
|
9 |
license: apache-2.0
|
10 |
+
short_description: Flux Portrait developed by Kolors Team
|
11 |
+
pinned: true
|
12 |
+
disable_embedding: true
|
13 |
---
|
14 |
|
15 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,371 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import cv2
|
3 |
+
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
import random
|
6 |
+
import base64
|
7 |
+
import requests
|
8 |
+
import json
|
9 |
+
import time
|
10 |
+
|
11 |
+
|
12 |
+
def portrait_gen(person_img, template_img, prompt, seed, randomize_seed):
|
13 |
+
post_start_time = time.time()
|
14 |
+
if person_img is None:
|
15 |
+
gr.Warning("Empty Person image")
|
16 |
+
return None, None, "Empty image"
|
17 |
+
if randomize_seed:
|
18 |
+
seed = random.randint(0, MAX_SEED)
|
19 |
+
encoded_person_img = cv2.imencode('.jpg', cv2.cvtColor(person_img, cv2.COLOR_RGB2BGR))[1].tobytes()
|
20 |
+
encoded_person_img = base64.b64encode(encoded_person_img).decode('utf-8')
|
21 |
+
encoded_template_img = None
|
22 |
+
if template_img is not None:
|
23 |
+
# style image with fixed hidden prompt
|
24 |
+
prompt_temp = imgpath_to_prompt(template_img)
|
25 |
+
if prompt_temp is not None:
|
26 |
+
prompt = prompt_temp
|
27 |
+
encoded_template_img = cv2.imencode('.jpg', cv2.imread(template_img))[1].tobytes()
|
28 |
+
encoded_template_img = base64.b64encode(encoded_template_img).decode('utf-8')
|
29 |
+
|
30 |
+
url = "http://" + os.environ['avatar_url'] + "Submit"
|
31 |
+
token = os.environ['token']
|
32 |
+
referer = os.environ['referer']
|
33 |
+
headers = {'Content-Type': 'application/json', 'token': token, 'referer': referer}
|
34 |
+
data = {
|
35 |
+
"templateImage": encoded_template_img,
|
36 |
+
"humanImage": encoded_person_img,
|
37 |
+
"seed": seed,
|
38 |
+
"prompt": prompt
|
39 |
+
}
|
40 |
+
try:
|
41 |
+
response = requests.post(url, headers=headers, data=json.dumps(data), timeout=50)
|
42 |
+
# print("post response code", response.status_code)
|
43 |
+
if response.status_code == 200:
|
44 |
+
result = response.json()['result']
|
45 |
+
status = result['status']
|
46 |
+
if status == "success":
|
47 |
+
uuid = result['result']
|
48 |
+
# print(uuid)
|
49 |
+
except Exception as err:
|
50 |
+
print(f"Post Exception Error: {err}")
|
51 |
+
raise gr.Error("Too many users, please try again later")
|
52 |
+
post_end_time = time.time()
|
53 |
+
print(f"post time used: {post_end_time-post_start_time}")
|
54 |
+
|
55 |
+
get_start_time =time.time()
|
56 |
+
time.sleep(9)
|
57 |
+
Max_Retry = 12
|
58 |
+
result_img = None
|
59 |
+
info = ""
|
60 |
+
err_log = ""
|
61 |
+
for i in range(Max_Retry):
|
62 |
+
try:
|
63 |
+
url = "http://" + os.environ['avatar_url'] + "Query?taskId=" + uuid
|
64 |
+
response = requests.get(url, headers=headers, timeout=20)
|
65 |
+
# print("get response code", response.status_code)
|
66 |
+
if response.status_code == 200:
|
67 |
+
result = response.json()['result']
|
68 |
+
status = result['status']
|
69 |
+
if status == "success":
|
70 |
+
result = base64.b64decode(result['result'])
|
71 |
+
result_np = np.frombuffer(result, np.uint8)
|
72 |
+
result_img = cv2.imdecode(result_np, cv2.IMREAD_UNCHANGED)
|
73 |
+
result_img = cv2.cvtColor(result_img, cv2.COLOR_RGB2BGR)
|
74 |
+
info = "Success"
|
75 |
+
break
|
76 |
+
elif status == "error":
|
77 |
+
err_log = f"Status is Error"
|
78 |
+
info = "Error"
|
79 |
+
break
|
80 |
+
else:
|
81 |
+
# print(response.text)
|
82 |
+
err_log = "URL error, pleace contact the admin"
|
83 |
+
info = "URL error, pleace contact the admin"
|
84 |
+
break
|
85 |
+
except requests.exceptions.ReadTimeout:
|
86 |
+
err_log = "Http Timeout"
|
87 |
+
info = "Http Timeout, please try again later"
|
88 |
+
except Exception as err:
|
89 |
+
err_log = f"Get Exception Error: {err}"
|
90 |
+
time.sleep(1)
|
91 |
+
get_end_time = time.time()
|
92 |
+
print(f"get time used: {get_end_time-get_start_time}")
|
93 |
+
print(f"all time used: {get_end_time-get_start_time+post_end_time-post_start_time}")
|
94 |
+
if info == "":
|
95 |
+
err_log = f"No image after {Max_Retry} retries"
|
96 |
+
info = "Too many users, please try again later"
|
97 |
+
if info != "Success":
|
98 |
+
print(f"Error Log: {err_log}")
|
99 |
+
gr.Warning("Too many users, please try again later")
|
100 |
+
|
101 |
+
return result_img, seed, info
|
102 |
+
|
103 |
+
MAX_SEED = 999999
|
104 |
+
|
105 |
+
example_path = os.path.join(os.path.dirname(__file__), 'assets')
|
106 |
+
|
107 |
+
refer_list = sorted(os.listdir(os.path.join(example_path,"refer_imgs")))
|
108 |
+
refer_list_path = [os.path.join(example_path,"refer_imgs",garm) for garm in refer_list]
|
109 |
+
|
110 |
+
human_list = sorted(os.listdir(os.path.join(example_path,"id_imgs")))
|
111 |
+
human_list_path = [os.path.join(example_path,"id_imgs",human) for human in human_list]
|
112 |
+
|
113 |
+
prompt_list = [
|
114 |
+
"Half-length close-up of a beautiful girl, dressed in the Hogwarts uniform from the Harry Potter series, wearing a blue cloak with a crest that appears to be the Gryffindor house emblem, along with a white shirt and a red-and-gold striped tie. She is holding a majic wand, the hair is long and wavy, and the background consists of a wooden wall with several books and a framed picture placed on a wooden desk. This setting evokes an atmosphere similar to a cozy study room or a magical classroom.",
|
115 |
+
"WM,Anime Magic,an anime girl holding glowing blue poker cards in her hands,poker cards flying in the sky,glowing magic effects,dynamic poses,highly detailed,ultra-high resolutions,32K UHD,best quality,masterpiece..The background features a full majic moon casting a soft glow, accentuating the ethereal majic ambiance.",
|
116 |
+
"A serene beauty stands in a studio awash with soft, golden light. Her wavy brunette hair cascades over her shoulders, while her piercing blue eyes gaze into the distance, filled with quiet contemplation. She wears a delicate, flowing white dress that seems to shimmer in the gentle glow, exuding an aura of pure elegance and grace , the classic film filter applied to the image imparts a nostalgic and gritty texture,highlighting the enduring allure of youth culture and fashion. the background provide a rich,textured setting,further emphasizing the unique style and attitude of the subject. Shot with a Fujifilm X-Pro3 camera,HDR,UHD,8K,best quality,best quality,masterpiece,realistic,cute face,smug,naughty face,light blush,giggling,backlighting,rim_light,moody lighting,",
|
117 |
+
"A man wear an Argentina shirt with No. 7, holds up the World Cup, surrounded by golden rain. The man is laughing with a gold medal around their neck. The background showcases a large stadium filled with spectators, illuminated by bright lights and surrounded by a celebratory shower of confetti. The overall atmosphere is one of triumph and celebration",
|
118 |
+
"anime epic cinematic shot of dynamic, The transatlantic slave trade, dramatic lighting, Technicolor, in motion, main subject of high budget action movie, raw photo, motion blur, best quality, high resolution, aidmaMJ6.1, an angel with wings and armor holding a spear in front of him flies at a demon, the demon, spreading his arms, yells at the angel,",
|
119 |
+
"Sci-fi style digital art image showing a knight in futuristic armor riding a motorcycle on a city street. The protagonist is located in the center right position, wearing a black, metallic tight armor. The surface of the armor is covered with raindrops and water stains, indicating that it has just experienced a heavy rain. His posture is leaning forward, holding the handlebars tightly with both hands, which makes him look very focused and full of power. The design of the motorcycle is very futuristic, with smooth body lines, bright red light from the headlights, and the right side mirror also reflects the ambient light. The tires of the motorcycle are wide and the tread pattern is clearly visible, which echoes the slippery road surface. The background is a city street scene with tall buildings, and the buildings are covered with colorful neon billboards. Various words and patterns are blurred against the sky in the distance. Some larger billboards with red and blue words can be seen on the left; on the right, there are more small billboards with various colors but not very clear. There are other pedestrians on the street. Although they are far away, their figures can be distinguished. Most of them have their backs to the camera and walk towards the distant buildings. The rain-soaked ground in the entire scene reflects the surrounding lights, adding depth and three-dimensionality to the picture. The details of the buildings in the background are slightly blurred, presenting a hazy feeling, highlighting the protagonist and his motorcycle in the foreground. The overall tone of the picture is cold, mainly black and gray, supplemented by red and blue light, forming a strong contrast effect. The high color saturation, moderate brightness, and uniform exposure give the picture a strong visual impact and a sense of futuristic technology. This image successfully creates a futuristic urban scene full of dynamic and technological atmosphere through delicate detail depiction and vivid color use.",
|
120 |
+
# "a person wearing a light brown coat, a white shirt, a dark pleated short skirt, and a striped tie, showing off the long legs. The outfit is completed with knee-high white socks and black leather shoes. The individual is standing on a pathway that is covered with yellow fallen leaves, surrounded by trees that have yellow leaves still attached. The trees are planted along both sides of the pathway, creating a picturesque autumn scene. The trunks of the trees are painted white at the base. The overall setting appears to be a serene autumnal day, with bright and warm lighting",
|
121 |
+
"Chinese pretty girl, with long, dark, wavy hair cascading over the shoulders, a sleeveless, knitted blue top with a high neck. The background is a gradient of various shades of blue, with a subtle texture that gives it a studio portrait appearance. The lighting is soft, illuminating the individual from the front, creating a calm and serene ambiance.",
|
122 |
+
"A person dressed in a sleek, black turtleneck sweater and a matching black suit jacket. The outfit conveys a sophisticated and formal style. The background is a solid olive green color, which contrasts subtly with the dark clothing. The hair appears to be dark and styled in a slightly tousled manner, adding a casual touch to the otherwise formal attire.",
|
123 |
+
"The upper body of a person wearing a plain, vibrant red, long-sleeved sweater. The sweater has a round neckline with a ribbed texture. The person has black hair that appears to be slightly tousled. The background of the image is plain and neutral, likely a light gray or white color, providing a clean and simple backdrop that contrasts with the rich color of the sweater. The image conveys a sense of casual yet stylish attire.",
|
124 |
+
]
|
125 |
+
prompt_list_examples = [
|
126 |
+
'hold a sign writing "Kolors Portrait with Flux"',
|
127 |
+
'The millionaire flung wads of cash in the air like confetti at the crowded nightclub, making it rain on the ecstatic revellers below.',
|
128 |
+
'Wearing Iron Man costume, in fantastic space, with stars twinkling, ultra-high resolutions,32K UHD,best quality,masterpiece',
|
129 |
+
'a person sitting on the ground in a forest or park during autumn. The ground is covered with fallen leaves in shades of yellow and brown. They are wearing a cozy cream-colored knit sweater and jeans. Their hair is long and brown, reaching past their shoulders. In one hand, they hold up a yellow maple leaf, while the other hand rests on their lap, also holding a leaf. The background features trees with yellow leaves, indicating the fall season, and the sunlight filters through the foliage, casting a warm, golden light on the scene. The atmosphere is serene and picturesque, capturing the essence of autumn.',
|
130 |
+
'A masterpiece of dreamy photography. The girl holds a glowing glass jar in her hands, which emits a soft yellow light, illuminating her face and the surrounding environment. She wears a white lace dress with blue and pink decorations and a light blue bow tied around her waist. The girl wears a white headdress dotted with blue and pink flowers and carries twinkling blue wings on her back. Behind the girl, you can see a vast sea of flowers, which sparkle with pink and gold light and are scattered on the green grass. The sky is full of sparkling stars, from the upper left corner to the lower right corner, as if the Milky Way is scattered in the night sky. The overall light is soft and full of magical colors, making the whole picture look like a fairy tale world.',
|
131 |
+
]
|
132 |
+
prompt_list_single = [
|
133 |
+
'hold a sign writing "Kolors Portrait with Flux"',
|
134 |
+
"A beautiful girl reading book, high quality.",
|
135 |
+
"Full body shot of young Asian face woman in sun hat and white dress standing on sunny beach with sea and mountains in background, high quality, sharp focus,",
|
136 |
+
]
|
137 |
+
|
138 |
+
css="""
|
139 |
+
#col-left {
|
140 |
+
margin: 0 auto;
|
141 |
+
max-width: 270px;
|
142 |
+
}
|
143 |
+
#col-mid {
|
144 |
+
margin: 0 auto;
|
145 |
+
max-width: 270px;
|
146 |
+
}
|
147 |
+
#col-right {
|
148 |
+
margin: 0 auto;
|
149 |
+
max-width: 550px;
|
150 |
+
}
|
151 |
+
#col-showcase {
|
152 |
+
margin: 0 auto;
|
153 |
+
max-width: 1100px;
|
154 |
+
}
|
155 |
+
#col-left-left {
|
156 |
+
margin: 0 auto;
|
157 |
+
max-width: 400px;
|
158 |
+
}
|
159 |
+
#col-left-right {
|
160 |
+
margin: 0 auto;
|
161 |
+
max-width: 120px;
|
162 |
+
}
|
163 |
+
#button {
|
164 |
+
color: blue;
|
165 |
+
}
|
166 |
+
"""
|
167 |
+
|
168 |
+
def img_to_prompt(img_path,prompt):
|
169 |
+
if img_path is None:
|
170 |
+
# return prompt,prompt_final
|
171 |
+
return prompt
|
172 |
+
else:
|
173 |
+
return None
|
174 |
+
|
175 |
+
def imgpath_to_prompt(img_path):
|
176 |
+
img_name = img_path.split("/")[-1]
|
177 |
+
if img_name in refer_list:
|
178 |
+
prompt_id = refer_list.index(img_name)
|
179 |
+
prompt_final = prompt_list[prompt_id]
|
180 |
+
else:
|
181 |
+
prompt_final = None
|
182 |
+
return prompt_final
|
183 |
+
|
184 |
+
def text_to_text(text1, text2):
|
185 |
+
if text1 is not None:
|
186 |
+
return text1
|
187 |
+
else:
|
188 |
+
return text2
|
189 |
+
|
190 |
+
def load_description(fp):
|
191 |
+
with open(fp, 'r', encoding='utf-8') as f:
|
192 |
+
content = f.read()
|
193 |
+
return content
|
194 |
+
|
195 |
+
def img_close():
|
196 |
+
return None
|
197 |
+
|
198 |
+
def change_mode(mode: str):
|
199 |
+
if mode == "Input prompt":
|
200 |
+
return gr.update(visible=True), gr.update(visible=False, value=None)
|
201 |
+
elif mode == "Ref. image":
|
202 |
+
return gr.update(visible=False, value=""), gr.update(visible=True)
|
203 |
+
else:
|
204 |
+
raise gr.Error("no such mode!")
|
205 |
+
|
206 |
+
change_mode_js = """
|
207 |
+
function change_mode_js(...args){
|
208 |
+
mode = args[0];
|
209 |
+
console.log("change_mode");
|
210 |
+
text_examples = document.querySelector("#text_examples");
|
211 |
+
image_examples = document.querySelector("#image_examples");
|
212 |
+
ref_examples = document.querySelector("#ref_examples");
|
213 |
+
prompt_examples = document.querySelector("#prompt_examples");
|
214 |
+
if (mode === "Input prompt"){
|
215 |
+
text_examples.hidden = false;
|
216 |
+
prompt_examples.hidden = false;
|
217 |
+
image_examples.hidden = true;
|
218 |
+
ref_examples.hidden = true;
|
219 |
+
}else {
|
220 |
+
text_examples.hidden = true;
|
221 |
+
prompt_examples.hidden = true;
|
222 |
+
image_examples.hidden = false;
|
223 |
+
ref_examples.hidden = false;
|
224 |
+
}
|
225 |
+
return args
|
226 |
+
}
|
227 |
+
"""
|
228 |
+
|
229 |
+
|
230 |
+
with gr.Blocks(css=css) as Portrait:
|
231 |
+
gr.HTML(load_description("title.md"))
|
232 |
+
with gr.Row():
|
233 |
+
with gr.Column(elem_id = "col-left"):
|
234 |
+
gr.HTML("""
|
235 |
+
<div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 20px;">
|
236 |
+
<div>
|
237 |
+
Step 1. Upload a portrait image ⬇️
|
238 |
+
</div>
|
239 |
+
</div>
|
240 |
+
""")
|
241 |
+
|
242 |
+
|
243 |
+
with gr.Column(elem_id = "col-mid"):
|
244 |
+
gr.HTML("""
|
245 |
+
<div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 20px;">
|
246 |
+
<div>
|
247 |
+
Step 2. Set a style reference ⬇️
|
248 |
+
</div>
|
249 |
+
</div>
|
250 |
+
""")
|
251 |
+
with gr.Column(elem_id = "col-right"):
|
252 |
+
gr.HTML("""
|
253 |
+
<div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 20px;">
|
254 |
+
<div>
|
255 |
+
Step 3. Press “Run” to get results ⬇️
|
256 |
+
</div>
|
257 |
+
</div>
|
258 |
+
""")
|
259 |
+
with gr.Row():
|
260 |
+
with gr.Column(elem_id = "col-left"):
|
261 |
+
imgs = gr.Image(label="Person Images", sources='upload', type="numpy",width=400)
|
262 |
+
example = gr.Examples(
|
263 |
+
inputs=imgs,
|
264 |
+
examples_per_page=10,
|
265 |
+
examples=human_list_path,
|
266 |
+
label="Person Images"
|
267 |
+
)
|
268 |
+
|
269 |
+
with gr.Column(elem_id = "col-mid"):
|
270 |
+
# gr.HTML("""
|
271 |
+
# <div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 15px;">
|
272 |
+
# <div>
|
273 |
+
# Use image <strong>OR!!!</strong> text as reference style.
|
274 |
+
# </div>
|
275 |
+
# </div>
|
276 |
+
# """)
|
277 |
+
mode = gr.Radio(label="Set a reference image or input prompt", choices=["Ref. image", "Input prompt"], value="text")
|
278 |
+
refer_img = gr.Image(label="Reference images", sources='upload', type="filepath")
|
279 |
+
example = gr.Examples(
|
280 |
+
inputs=refer_img,
|
281 |
+
examples_per_page=9,
|
282 |
+
examples=refer_list_path,
|
283 |
+
label = 'Reference images',
|
284 |
+
elem_id="ref_examples"
|
285 |
+
)
|
286 |
+
prompt = gr.Text(
|
287 |
+
label="Input prompts",
|
288 |
+
show_label=False,
|
289 |
+
max_lines=1,
|
290 |
+
placeholder="Enter your prompt",
|
291 |
+
container=False,
|
292 |
+
)
|
293 |
+
examples_prompt = gr.Examples(
|
294 |
+
inputs=prompt,
|
295 |
+
examples=prompt_list_single,
|
296 |
+
label = 'Input prompts',
|
297 |
+
elem_id="prompt_examples"
|
298 |
+
)
|
299 |
+
|
300 |
+
Portrait.load(
|
301 |
+
fn=lambda: gr.update(value="Ref. image"),
|
302 |
+
outputs=[mode],
|
303 |
+
show_progress=False
|
304 |
+
)
|
305 |
+
|
306 |
+
mode.change(
|
307 |
+
js=change_mode_js,
|
308 |
+
fn=change_mode,
|
309 |
+
inputs=[mode],
|
310 |
+
outputs=[prompt, refer_img],
|
311 |
+
show_progress=False
|
312 |
+
)
|
313 |
+
|
314 |
+
with gr.Column(elem_id = "col-right"):
|
315 |
+
image_out = gr.Image(label="Results", show_share_button=False)
|
316 |
+
with gr.Row():
|
317 |
+
seed = gr.Slider(
|
318 |
+
label="Seed",
|
319 |
+
minimum=0,
|
320 |
+
maximum=MAX_SEED,
|
321 |
+
step=1,
|
322 |
+
value=0,
|
323 |
+
)
|
324 |
+
randomize_seed = gr.Checkbox(label="Random seed", value=True)
|
325 |
+
with gr.Row():
|
326 |
+
seed_used = gr.Number(label="Seed used")
|
327 |
+
result_info = gr.Text(label="Response")
|
328 |
+
test_button = gr.Button(value="Run", elem_id="button")
|
329 |
+
|
330 |
+
|
331 |
+
test_button.click(fn=portrait_gen, inputs=[imgs, refer_img, prompt, seed, randomize_seed], outputs=[image_out, seed_used, result_info], api_name=False)
|
332 |
+
|
333 |
+
with gr.Column(elem_id = "col-showcase"):
|
334 |
+
gr.HTML("""
|
335 |
+
<div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 20px;">
|
336 |
+
<div> </div>
|
337 |
+
<br>
|
338 |
+
<br>
|
339 |
+
<div>
|
340 |
+
Portrait examples in pairs of person images and style.
|
341 |
+
</div>
|
342 |
+
</div>
|
343 |
+
""")
|
344 |
+
|
345 |
+
image_show_case = gr.Examples(
|
346 |
+
examples=[
|
347 |
+
[human_list_path[5], refer_list_path[0], os.path.join(example_path, 'outputs/190815.jpg')],
|
348 |
+
[human_list_path[6], refer_list_path[1], os.path.join(example_path, 'outputs/190811.jpg')],
|
349 |
+
[human_list_path[2], refer_list_path[3], os.path.join(example_path, 'outputs/190813.jpg')],
|
350 |
+
[human_list_path[0], refer_list_path[4], os.path.join(example_path, 'outputs/190814.jpg')],
|
351 |
+
],
|
352 |
+
inputs=[imgs, refer_img, image_out],
|
353 |
+
label=None,
|
354 |
+
elem_id="image_examples"
|
355 |
+
)
|
356 |
+
|
357 |
+
text_show_case = gr.Examples(
|
358 |
+
examples=[
|
359 |
+
[human_list_path[6], prompt_list_examples[0], os.path.join(example_path, 'outputs/190820.jpg')],
|
360 |
+
[human_list_path[4], prompt_list_examples[1], os.path.join(example_path, 'outputs/190812.jpg')],
|
361 |
+
[human_list_path[3], prompt_list_examples[2], os.path.join(example_path, 'outputs/190816.jpg')],
|
362 |
+
[human_list_path[7], prompt_list_examples[3], os.path.join(example_path, 'outputs/190818.jpg')],
|
363 |
+
[human_list_path[8], prompt_list_examples[4], os.path.join(example_path, 'outputs/190819.jpg')],
|
364 |
+
],
|
365 |
+
inputs=[imgs, prompt, image_out],
|
366 |
+
label=None,
|
367 |
+
elem_id="text_examples"
|
368 |
+
)
|
369 |
+
|
370 |
+
|
371 |
+
Portrait.queue(api_open=False).launch(show_api=False)
|
assets/id_imgs/0047.jpg
ADDED
assets/id_imgs/0048.jpg
ADDED
assets/id_imgs/0049.jpg
ADDED
assets/id_imgs/0050.jpg
ADDED
assets/id_imgs/0051.jpg
ADDED
assets/id_imgs/0053.jpg
ADDED
assets/id_imgs/0054.jpg
ADDED
assets/id_imgs/0055.jpg
ADDED
assets/id_imgs/0056.jpg
ADDED
assets/outputs/190811.jpg
ADDED
assets/outputs/190812.jpg
ADDED
assets/outputs/190813.jpg
ADDED
assets/outputs/190814.jpg
ADDED
assets/outputs/190815.jpg
ADDED
assets/outputs/190816.jpg
ADDED
assets/outputs/190818.jpg
ADDED
assets/outputs/190819.jpg
ADDED
assets/outputs/190820.jpg
ADDED
assets/refer_imgs/0006.jpg
ADDED
assets/refer_imgs/0007.jpg
ADDED
assets/refer_imgs/0008.jpg
ADDED
assets/refer_imgs/man0004.jpg
ADDED
assets/refer_imgs/man0006.jpg
ADDED
assets/refer_imgs/man0007.jpg
ADDED
assets/refer_imgs/z0001.jpg
ADDED
assets/refer_imgs/z0002.jpg
ADDED
assets/refer_imgs/z0003.jpg
ADDED
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
accelerate
|
2 |
+
diffusers
|
3 |
+
invisible_watermark
|
4 |
+
torch
|
5 |
+
transformers
|
6 |
+
xformers
|
title.md
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div>
|
2 |
+
<div>
|
3 |
+
<div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 40px;">
|
4 |
+
<b>Kolors Portrait with Flux</b>
|
5 |
+
</div>
|
6 |
+
|
7 |
+
<div style="display: flex; text-align: center; font-size: 14px; padding-right: 300px; padding-left: 300px;">
|
8 |
+
<strong>Disclaimer: </strong> Kolors Portrait aims to preserve the face identity and improve the visual quality with Flux-dev. This demo on HuggingFace space developed by Kolors is free for trials.
|
9 |
+
</div>
|
10 |
+
</div>
|
11 |
+
</div>
|