Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .gitattributes +4 -0
- README.md +1 -1
- gradio_demo/app.py +63 -248
- image_data.csv +1 -0
- images/reena@lowq_gallery1.png +0 -0
- images/reena@lowq_gallery2.png +0 -0
- images/reena@lowq_gallery3.png +0 -0
- images/yashviii@qq_gallery1.png +3 -0
- images/yashviii@qq_gallery2.png +3 -0
- images/yashviii@qq_gallery3.png +3 -0
- images/yashviii@qq_gallery4.png +3 -0
- requirements.txt +2 -1
- serviceaccount.json +13 -0
.gitattributes
CHANGED
|
@@ -46,3 +46,7 @@ images/[email protected]_gallery1.png filter=lfs diff=lfs merge=lfs -text
|
|
| 46 |
images/[email protected]_gallery2.png filter=lfs diff=lfs merge=lfs -text
|
| 47 |
images/[email protected]_gallery3.png filter=lfs diff=lfs merge=lfs -text
|
| 48 |
images/[email protected]_gallery4.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
images/[email protected]_gallery2.png filter=lfs diff=lfs merge=lfs -text
|
| 47 |
images/[email protected]_gallery3.png filter=lfs diff=lfs merge=lfs -text
|
| 48 |
images/[email protected]_gallery4.png filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
images/yashviii@qq_gallery1.png filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
images/yashviii@qq_gallery2.png filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
images/yashviii@qq_gallery3.png filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
images/yashviii@qq_gallery4.png filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
app_file: gradio_demo/app.py
|
| 4 |
sdk: gradio
|
| 5 |
sdk_version: 4.38.1
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Idfy-Avatarify
|
| 3 |
app_file: gradio_demo/app.py
|
| 4 |
sdk: gradio
|
| 5 |
sdk_version: 4.38.1
|
gradio_demo/app.py
CHANGED
|
@@ -29,6 +29,26 @@ from style_template import styles
|
|
| 29 |
from pipeline_stable_diffusion_xl_instantid_full import StableDiffusionXLInstantIDPipeline
|
| 30 |
from model_util import load_models_xl, get_torch_device, torch_gc
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# global variable
|
| 34 |
MAX_SEED = np.iinfo(np.int32).max
|
|
@@ -54,17 +74,10 @@ logo = logo.resize((100, 100))
|
|
| 54 |
from cv2 import imencode
|
| 55 |
import base64
|
| 56 |
|
| 57 |
-
# def encode_pil_to_base64_new(pil_image):
|
| 58 |
-
# print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
|
| 59 |
-
# image_arr = np.asarray(pil_image)[:,:,::-1]
|
| 60 |
-
# _, byte_data = imencode('.png', image_arr)
|
| 61 |
-
# base64_data = base64.b64encode(byte_data)
|
| 62 |
-
# base64_string_opencv = base64_data.decode("utf-8")
|
| 63 |
-
# return "data:image/png;base64," + base64_string_opencv
|
| 64 |
-
|
| 65 |
import gradio as gr
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
# gr.processing_utils.encode_pil_to_base64 = encode_pil_to_base64_new
|
| 68 |
|
| 69 |
def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=False):
|
| 70 |
|
|
@@ -112,16 +125,8 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
| 112 |
pipe.disable_lora()
|
| 113 |
|
| 114 |
def remove_tips():
|
| 115 |
-
print("GG")
|
| 116 |
return gr.update(visible=False)
|
| 117 |
|
| 118 |
-
|
| 119 |
-
# prompts = [
|
| 120 |
-
# ["superman","Vibrant Color"], ["japanese anime character with white/neon hair","Watercolor"],
|
| 121 |
-
# # ["Suited professional","(No style)"],
|
| 122 |
-
# ["Scooba diver","Line art"], ["eskimo","Snow"]
|
| 123 |
-
# ]
|
| 124 |
-
|
| 125 |
def convert_from_cv2_to_image(img: np.ndarray) -> Image:
|
| 126 |
return Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
| 127 |
|
|
@@ -146,12 +151,25 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
| 146 |
# if email != "":
|
| 147 |
p,n = styles.get(style, styles.get(STYLE_NAMES[1]))
|
| 148 |
return generate_image(face_file, p[3], n)
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
#
|
| 153 |
-
|
| 154 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
def draw_kps(image_pil, kps, color_list=[(255,0,0), (0,255,0), (0,0,255), (255,255,0), (255,0,255)]):
|
| 157 |
stickwidth = 4
|
|
@@ -185,7 +203,6 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
| 185 |
pad_to_max_side=True, mode=PIL.Image.BILINEAR, base_pixel_number=64):
|
| 186 |
|
| 187 |
w, h = input_image.size
|
| 188 |
-
print(f"Original Size --> {input_image.size}")
|
| 189 |
if size is not None:
|
| 190 |
w_resize_new, h_resize_new = size
|
| 191 |
else:
|
|
@@ -203,62 +220,27 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
| 203 |
offset_y = (max_side - h_resize_new) // 2
|
| 204 |
res[offset_y:offset_y+h_resize_new, offset_x:offset_x+w_resize_new] = np.array(input_image)
|
| 205 |
input_image = Image.fromarray(res)
|
| 206 |
-
|
| 207 |
-
print(f"Final modified image size --> {input_image.size}")
|
| 208 |
return input_image
|
| 209 |
|
| 210 |
# def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
| 211 |
# p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
| 212 |
# return p.replace("{prompt}", positive), n + ' ' + negative
|
| 213 |
|
| 214 |
-
def store_images(email, gallery1, gallery2, gallery3, gallery4,consent):
|
|
|
|
|
|
|
| 215 |
if not consent:
|
| 216 |
raise gr.Error("Consent not provided")
|
| 217 |
-
galleries = []
|
| 218 |
for i, img in enumerate([gallery1, gallery2, gallery3, gallery4], start=1):
|
| 219 |
-
|
| 220 |
-
img
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
# Define image file paths
|
| 228 |
-
image_paths = []
|
| 229 |
-
for i, img in enumerate(galleries, start=1):
|
| 230 |
-
img_path = f'images/{email}_gallery{i}.png'
|
| 231 |
-
print("saving image")
|
| 232 |
-
img.save(img_path)
|
| 233 |
-
image_paths.append(img_path)
|
| 234 |
-
print("saved image at path ",img_path)
|
| 235 |
-
|
| 236 |
-
# Define the CSV file path
|
| 237 |
-
csv_file_path = 'image_data.csv'
|
| 238 |
-
|
| 239 |
-
# Create a DataFrame for the email and image paths
|
| 240 |
-
df = pd.DataFrame({
|
| 241 |
-
'email': [email],
|
| 242 |
-
'img1_path': [image_paths[0]],
|
| 243 |
-
'img2_path': [image_paths[1]],
|
| 244 |
-
'img3_path': [image_paths[2]],
|
| 245 |
-
'img4_path': [image_paths[3]],
|
| 246 |
-
})
|
| 247 |
-
|
| 248 |
-
print("created df ",df)
|
| 249 |
-
|
| 250 |
-
# Write to CSV (append if the file exists, create a new one if it doesn't)
|
| 251 |
-
if not os.path.isfile(csv_file_path):
|
| 252 |
-
df.to_csv(csv_file_path, index=False)
|
| 253 |
-
else:
|
| 254 |
-
df_check = pd.read_csv(csv_file_path)
|
| 255 |
-
print(f"CSV content before append:\n{df_check}")
|
| 256 |
-
df.to_csv(csv_file_path, mode='a', header=False, index=False)
|
| 257 |
-
print("writing to csv",csv_file_path)
|
| 258 |
-
df_check = pd.read_csv(csv_file_path)
|
| 259 |
-
print(f"CSV content before append:\n{df_check}")
|
| 260 |
-
|
| 261 |
gr.Info("Thankyou!! Your avatar is on the way to your inbox")
|
|
|
|
| 262 |
|
| 263 |
def add_watermark(image, watermark=logo, opacity=128, position="bottom_right", padding=10):
|
| 264 |
# Convert NumPy array to PIL Image if needed
|
|
@@ -311,10 +293,6 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
| 311 |
num_steps = 15
|
| 312 |
guidance_scale = 5
|
| 313 |
seed = random.randint(0, MAX_SEED)
|
| 314 |
-
print(f"Seed --> {seed}")
|
| 315 |
-
|
| 316 |
-
# negative_prompt = ""
|
| 317 |
-
# negative_prompt += neg
|
| 318 |
enhance_face_region = True
|
| 319 |
if enable_LCM:
|
| 320 |
pipe.enable_lora()
|
|
@@ -325,14 +303,6 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
| 325 |
|
| 326 |
if face_image is None:
|
| 327 |
raise gr.Error(f"Cannot find any input face image! Please upload the face image")
|
| 328 |
-
|
| 329 |
-
# if prompt is None:
|
| 330 |
-
# prompt = "a person"
|
| 331 |
-
|
| 332 |
-
# apply the style template
|
| 333 |
-
# prompt, negative_prompt = apply_style(style_name, prompt, negative_prompt)
|
| 334 |
-
|
| 335 |
-
# face_image = load_image(face_image_path)
|
| 336 |
face_image = resize_img(face_image)
|
| 337 |
face_image_cv2 = convert_from_image_to_cv2(face_image)
|
| 338 |
height, width, _ = face_image_cv2.shape
|
|
@@ -373,9 +343,6 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
| 373 |
|
| 374 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 375 |
|
| 376 |
-
print("Start inference...")
|
| 377 |
-
print(f"[Debug] Prompt: {prompt}, \n[Debug] Neg Prompt: {negative_prompt}")
|
| 378 |
-
|
| 379 |
pipe.set_ip_adapter_scale(adapter_strength_ratio)
|
| 380 |
images = pipe(
|
| 381 |
prompt=prompt,
|
|
@@ -408,21 +375,6 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
| 408 |
article = r""""""
|
| 409 |
|
| 410 |
tips = r""""""
|
| 411 |
-
# css = '''
|
| 412 |
-
# .gradio-container {
|
| 413 |
-
# width: 95% !important;
|
| 414 |
-
# background-image: url('./InstantID/gradio_demo/logo.png');
|
| 415 |
-
# background-size: cover;
|
| 416 |
-
# background-position: center;
|
| 417 |
-
# }
|
| 418 |
-
# .image-gallery {
|
| 419 |
-
# height: 100vh !important;
|
| 420 |
-
# overflow: auto;
|
| 421 |
-
# }
|
| 422 |
-
# .gradio-row .gradio-element {
|
| 423 |
-
# margin: 0 !important;
|
| 424 |
-
# }
|
| 425 |
-
# '''
|
| 426 |
css = '''
|
| 427 |
.gradio-container {width: 100% !important; color: white; background: linear-gradient(135deg, #1C43B9, #254977, #343434);}
|
| 428 |
.gradio-row .gradio-element { margin: 0 !important; }
|
|
@@ -431,7 +383,7 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
| 431 |
justify-content: center;
|
| 432 |
align-items: center;
|
| 433 |
width: 100%;}
|
| 434 |
-
#
|
| 435 |
background: linear-gradient(to right, #ffffff, #f2bb13); !important;
|
| 436 |
color: #254977 !important;
|
| 437 |
}
|
|
@@ -442,47 +394,23 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
| 442 |
gr.Markdown(title)
|
| 443 |
with gr.Column():
|
| 444 |
with gr.Row():
|
| 445 |
-
gr.Image("./gradio_demo/logo.png", scale=0, min_width=50, show_label=False, show_download_button=False)
|
| 446 |
gr.Markdown(description)
|
| 447 |
style = gr.Dropdown(label="Choose your STYLE", choices=STYLE_NAMES)
|
| 448 |
with gr.Row(equal_height=True): # Center the face file
|
| 449 |
with gr.Column(elem_id="centered-face", elem_classes=["centered-column"]): # Use CSS class for centering
|
| 450 |
face_file = gr.Image(label="Upload a photo of your face", type="pil", height=400, width=500)
|
| 451 |
-
submit = gr.Button("Submit", variant="primary",elem_id="
|
| 452 |
with gr.Column():
|
| 453 |
with gr.Row():
|
| 454 |
-
gallery1 = gr.Image(label="Generated Images")
|
| 455 |
-
gallery2 = gr.Image(label="Generated Images")
|
| 456 |
with gr.Row():
|
| 457 |
-
gallery3 = gr.Image(label="Generated Images")
|
| 458 |
-
gallery4 = gr.Image(label="Generated Images")
|
| 459 |
email = gr.Textbox(label="Email", info="Enter your email address", value="")
|
| 460 |
-
consent = gr.Checkbox(label="I am giving my consent to use my data to share my AI Avtar and IDfy relevant information from time to time")
|
| 461 |
-
submit1 = gr.Button("SUBMIT",elem_id="store-btn")
|
| 462 |
-
# with gr.Blocks(css=css) as demo:
|
| 463 |
-
|
| 464 |
-
# # description
|
| 465 |
-
# gr.Markdown(title)
|
| 466 |
-
# with gr.Column():
|
| 467 |
-
# with gr.Row():
|
| 468 |
-
# gr.Image("./gradio_demo/logo.png",scale=0,min_width=50,show_label=False,show_download_button=False)
|
| 469 |
-
# gr.Markdown(description)
|
| 470 |
-
# style = gr.Dropdown(label="Choose your STYLE", choices=STYLE_NAMES)
|
| 471 |
-
# face_file = gr.Image(label="Upload a photo of your face", type="pil",sources="webcam", height=400, width=500)
|
| 472 |
-
# submit = gr.Button("Submit", variant="primary")
|
| 473 |
-
# with gr.Column():
|
| 474 |
-
# with gr.Row():
|
| 475 |
-
# gallery1 = gr.Image(label="Generated Images")
|
| 476 |
-
# gallery2 = gr.Image(label="Generated Images")
|
| 477 |
-
# with gr.Row():
|
| 478 |
-
# gallery3 = gr.Image(label="Generated Images")
|
| 479 |
-
# gallery4 = gr.Image(label="Generated Images")
|
| 480 |
-
# email = gr.Textbox(label="Email",
|
| 481 |
-
# info="Enter your email address",
|
| 482 |
-
# value="")
|
| 483 |
-
# consent = gr.Checkbox(label="I am giving my consent to use my data to share my AI Avtar and IDfy relevant information from time to time")
|
| 484 |
-
# submit1 = gr.Button("STORE", variant="primary")
|
| 485 |
-
# # submit1 = gr.Button("Store")
|
| 486 |
usage_tips = gr.Markdown(label="Usage tips of InstantID", value=tips ,visible=False)
|
| 487 |
|
| 488 |
face_file.upload(
|
|
@@ -534,127 +462,14 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
| 534 |
|
| 535 |
submit1.click(
|
| 536 |
fn=store_images,
|
| 537 |
-
inputs=[email,gallery1,gallery2,gallery3,gallery4,consent],
|
| 538 |
-
outputs=
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
gr.Markdown(article)
|
| 543 |
|
| 544 |
demo.launch(share=True)
|
| 545 |
-
|
| 546 |
-
# with gr.Blocks(css=css, js=js) as demo:
|
| 547 |
-
|
| 548 |
-
# # description
|
| 549 |
-
# gr.Markdown(title)
|
| 550 |
-
# with gr.Row():
|
| 551 |
-
# gr.Image("./gradio_demo/logo.png",scale=0,min_width=50,show_label=False,show_download_button=False)
|
| 552 |
-
# gr.Markdown(description)
|
| 553 |
-
# with gr.Row():
|
| 554 |
-
# with gr.Column():
|
| 555 |
-
# style = gr.Dropdown(label="Choose your STYLE", choices=STYLE_NAMES)
|
| 556 |
-
# face_file = gr.Image(label="Upload a photo of your face", type="pil",sources="webcam")
|
| 557 |
-
# submit = gr.Button("Submit", variant="primary")
|
| 558 |
-
# with gr.Column():
|
| 559 |
-
# with gr.Row():
|
| 560 |
-
# gallery1 = gr.Image(label="Generated Images")
|
| 561 |
-
# gallery2 = gr.Image(label="Generated Images")
|
| 562 |
-
# with gr.Row():
|
| 563 |
-
# gallery3 = gr.Image(label="Generated Images")
|
| 564 |
-
# gallery4 = gr.Image(label="Generated Images")
|
| 565 |
-
# email = gr.Textbox(label="Email",
|
| 566 |
-
# info="Enter your email address",
|
| 567 |
-
# value="")
|
| 568 |
-
|
| 569 |
-
# usage_tips = gr.Markdown(label="Usage tips of InstantID", value=tips ,visible=False)
|
| 570 |
-
# # identitynet_strength_ratio = gr.Slider(
|
| 571 |
-
# # label="IdentityNet strength (for fidelity)",
|
| 572 |
-
# # minimum=0,
|
| 573 |
-
# # maximum=1.5,
|
| 574 |
-
# # step=0.05,
|
| 575 |
-
# # value=0.95,
|
| 576 |
-
# # )
|
| 577 |
-
# # adapter_strength_ratio = gr.Slider(
|
| 578 |
-
# # label="Image adapter strength (for detail)",
|
| 579 |
-
# # minimum=0,
|
| 580 |
-
# # maximum=1.5,
|
| 581 |
-
# # step=0.05,
|
| 582 |
-
# # value=0.60,
|
| 583 |
-
# # )
|
| 584 |
-
# # negative_prompt = gr.Textbox(
|
| 585 |
-
# # label="Negative Prompt",
|
| 586 |
-
# # placeholder="low quality",
|
| 587 |
-
# # value="(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
|
| 588 |
-
# # )
|
| 589 |
-
# # num_steps = gr.Slider(
|
| 590 |
-
# # label="Number of sample steps",
|
| 591 |
-
# # minimum=15,
|
| 592 |
-
# # maximum=100,
|
| 593 |
-
# # step=1,
|
| 594 |
-
# # value=5 if enable_lcm_arg else 15,
|
| 595 |
-
# # )
|
| 596 |
-
# # guidance_scale = gr.Slider(
|
| 597 |
-
# # label="Guidance scale",
|
| 598 |
-
# # minimum=0.1,
|
| 599 |
-
# # maximum=10.0,
|
| 600 |
-
# # step=0.1,
|
| 601 |
-
# # value=0 if enable_lcm_arg else 8.5,
|
| 602 |
-
# # )
|
| 603 |
-
# # if email is None:
|
| 604 |
-
# # print("STOPPPP")
|
| 605 |
-
# # raise gr.Error("Email ID is compulsory")
|
| 606 |
-
# face_file.upload(
|
| 607 |
-
# fn=remove_tips,
|
| 608 |
-
# outputs=usage_tips,
|
| 609 |
-
# queue=True,
|
| 610 |
-
# api_name=False,
|
| 611 |
-
# show_progress = "full"
|
| 612 |
-
# ).then(
|
| 613 |
-
# fn=run_for_prompts1,
|
| 614 |
-
# inputs=[face_file,style],
|
| 615 |
-
# outputs=[gallery1]
|
| 616 |
-
# ).then(
|
| 617 |
-
# fn=run_for_prompts2,
|
| 618 |
-
# inputs=[face_file,style],
|
| 619 |
-
# outputs=[gallery2]
|
| 620 |
-
# ).then(
|
| 621 |
-
# fn=run_for_prompts3,
|
| 622 |
-
# inputs=[face_file,style],
|
| 623 |
-
# outputs=[gallery3]
|
| 624 |
-
# ).then(
|
| 625 |
-
# fn=run_for_prompts4,
|
| 626 |
-
# inputs=[face_file,style],
|
| 627 |
-
# outputs=[gallery4]
|
| 628 |
-
# )
|
| 629 |
-
# submit.click(
|
| 630 |
-
# fn=remove_tips,
|
| 631 |
-
# outputs=usage_tips,
|
| 632 |
-
# queue=True,
|
| 633 |
-
# api_name=False,
|
| 634 |
-
# show_progress = "full"
|
| 635 |
-
# ).then(
|
| 636 |
-
# fn=run_for_prompts1,
|
| 637 |
-
# inputs=[face_file,style],
|
| 638 |
-
# outputs=[gallery1]
|
| 639 |
-
# ).then(
|
| 640 |
-
# fn=run_for_prompts2,
|
| 641 |
-
# inputs=[face_file,style],
|
| 642 |
-
# outputs=[gallery2]
|
| 643 |
-
# ).then(
|
| 644 |
-
# fn=run_for_prompts3,
|
| 645 |
-
# inputs=[face_file,style],
|
| 646 |
-
# outputs=[gallery3]
|
| 647 |
-
# ).then(
|
| 648 |
-
# fn=run_for_prompts4,
|
| 649 |
-
# inputs=[face_file,style],
|
| 650 |
-
# outputs=[gallery4]
|
| 651 |
-
# )
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
# gr.Markdown(article)
|
| 655 |
-
|
| 656 |
-
# demo.launch(share=True)
|
| 657 |
-
|
| 658 |
if __name__ == "__main__":
|
| 659 |
parser = argparse.ArgumentParser()
|
| 660 |
parser.add_argument("--pretrained_model_name_or_path", type=str, default="wangqixun/YamerMIX_v8")
|
|
|
|
| 29 |
from pipeline_stable_diffusion_xl_instantid_full import StableDiffusionXLInstantIDPipeline
|
| 30 |
from model_util import load_models_xl, get_torch_device, torch_gc
|
| 31 |
|
| 32 |
+
import os
|
| 33 |
+
|
| 34 |
+
# try:
|
| 35 |
+
# # Send a GET request to the URL
|
| 36 |
+
# response = requests.get("https://storage.googleapis.com/idfy-gff-public/idfy-gff-public%40idfy-eve-ml-training.iam.gserviceaccount.com.json")
|
| 37 |
+
|
| 38 |
+
# # Raise an exception if the request was unsuccessful
|
| 39 |
+
# response.raise_for_status()
|
| 40 |
+
|
| 41 |
+
# # Save the file to the specified path
|
| 42 |
+
# with open("serviceaccount.json", 'wb') as file:
|
| 43 |
+
# file.write(response.content)
|
| 44 |
+
|
| 45 |
+
# print(f"Service account JSON file successfully downloaded")
|
| 46 |
+
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "serviceaccount.json"
|
| 47 |
+
|
| 48 |
+
# except requests.exceptions.RequestException as e:
|
| 49 |
+
# print(f"Failed to download the service account JSON file: {e}")
|
| 50 |
+
|
| 51 |
+
|
| 52 |
|
| 53 |
# global variable
|
| 54 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
|
| 74 |
from cv2 import imencode
|
| 75 |
import base64
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
import gradio as gr
|
| 78 |
+
from google.cloud import storage
|
| 79 |
+
from io import BytesIO
|
| 80 |
|
|
|
|
| 81 |
|
| 82 |
def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=False):
|
| 83 |
|
|
|
|
| 125 |
pipe.disable_lora()
|
| 126 |
|
| 127 |
def remove_tips():
|
|
|
|
| 128 |
return gr.update(visible=False)
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
def convert_from_cv2_to_image(img: np.ndarray) -> Image:
|
| 131 |
return Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
| 132 |
|
|
|
|
| 151 |
# if email != "":
|
| 152 |
p,n = styles.get(style, styles.get(STYLE_NAMES[1]))
|
| 153 |
return generate_image(face_file, p[3], n)
|
| 154 |
+
|
| 155 |
+
def upload_pil_image_to_gcs(image, destination_blob_name):
|
| 156 |
+
bucket_name="idfy-gff-public"
|
| 157 |
+
# Convert PIL image to byte stream
|
| 158 |
+
image_byte_array = BytesIO()
|
| 159 |
+
image.save(image_byte_array, format='PNG') # Save image in its original format
|
| 160 |
+
image_byte_array.seek(0)
|
| 161 |
+
|
| 162 |
+
# Initialize a GCP client
|
| 163 |
+
storage_client = storage.Client()
|
| 164 |
+
|
| 165 |
+
# Get the bucket
|
| 166 |
+
bucket = storage_client.bucket(bucket_name)
|
| 167 |
+
|
| 168 |
+
# Create a blob object from the filename
|
| 169 |
+
blob = bucket.blob(destination_blob_name)
|
| 170 |
+
|
| 171 |
+
# Upload the image to GCS
|
| 172 |
+
blob.upload_from_file(image_byte_array, content_type=f'image/png')
|
| 173 |
|
| 174 |
def draw_kps(image_pil, kps, color_list=[(255,0,0), (0,255,0), (0,0,255), (255,255,0), (255,0,255)]):
|
| 175 |
stickwidth = 4
|
|
|
|
| 203 |
pad_to_max_side=True, mode=PIL.Image.BILINEAR, base_pixel_number=64):
|
| 204 |
|
| 205 |
w, h = input_image.size
|
|
|
|
| 206 |
if size is not None:
|
| 207 |
w_resize_new, h_resize_new = size
|
| 208 |
else:
|
|
|
|
| 220 |
offset_y = (max_side - h_resize_new) // 2
|
| 221 |
res[offset_y:offset_y+h_resize_new, offset_x:offset_x+w_resize_new] = np.array(input_image)
|
| 222 |
input_image = Image.fromarray(res)
|
|
|
|
|
|
|
| 223 |
return input_image
|
| 224 |
|
| 225 |
# def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
| 226 |
# p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
| 227 |
# return p.replace("{prompt}", positive), n + ' ' + negative
|
| 228 |
|
| 229 |
+
def store_images(email, gallery1, gallery2, gallery3, gallery4,consent,style):
|
| 230 |
+
if not email:
|
| 231 |
+
raise gr.Error("Email Id not provided")
|
| 232 |
if not consent:
|
| 233 |
raise gr.Error("Consent not provided")
|
|
|
|
| 234 |
for i, img in enumerate([gallery1, gallery2, gallery3, gallery4], start=1):
|
| 235 |
+
try:
|
| 236 |
+
if isinstance(img, np.ndarray):
|
| 237 |
+
img = Image.fromarray(img)
|
| 238 |
+
dest = f'{email}/img{i}@{style}.png'
|
| 239 |
+
upload_pil_image_to_gcs(img,dest)
|
| 240 |
+
except Exception as e:
|
| 241 |
+
print()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
gr.Info("Thankyou!! Your avatar is on the way to your inbox")
|
| 243 |
+
return None,None,None,None,None
|
| 244 |
|
| 245 |
def add_watermark(image, watermark=logo, opacity=128, position="bottom_right", padding=10):
|
| 246 |
# Convert NumPy array to PIL Image if needed
|
|
|
|
| 293 |
num_steps = 15
|
| 294 |
guidance_scale = 5
|
| 295 |
seed = random.randint(0, MAX_SEED)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
enhance_face_region = True
|
| 297 |
if enable_LCM:
|
| 298 |
pipe.enable_lora()
|
|
|
|
| 303 |
|
| 304 |
if face_image is None:
|
| 305 |
raise gr.Error(f"Cannot find any input face image! Please upload the face image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
face_image = resize_img(face_image)
|
| 307 |
face_image_cv2 = convert_from_image_to_cv2(face_image)
|
| 308 |
height, width, _ = face_image_cv2.shape
|
|
|
|
| 343 |
|
| 344 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 345 |
|
|
|
|
|
|
|
|
|
|
| 346 |
pipe.set_ip_adapter_scale(adapter_strength_ratio)
|
| 347 |
images = pipe(
|
| 348 |
prompt=prompt,
|
|
|
|
| 375 |
article = r""""""
|
| 376 |
|
| 377 |
tips = r""""""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
css = '''
|
| 379 |
.gradio-container {width: 100% !important; color: white; background: linear-gradient(135deg, #1C43B9, #254977, #343434);}
|
| 380 |
.gradio-row .gradio-element { margin: 0 !important; }
|
|
|
|
| 383 |
justify-content: center;
|
| 384 |
align-items: center;
|
| 385 |
width: 100%;}
|
| 386 |
+
#submit-btn, #store-btn {
|
| 387 |
background: linear-gradient(to right, #ffffff, #f2bb13); !important;
|
| 388 |
color: #254977 !important;
|
| 389 |
}
|
|
|
|
| 394 |
gr.Markdown(title)
|
| 395 |
with gr.Column():
|
| 396 |
with gr.Row():
|
| 397 |
+
gr.Image("./gradio_demo/logo.png", scale=0, min_width=50, show_label=False, show_download_button=False, show_share_button=False)
|
| 398 |
gr.Markdown(description)
|
| 399 |
style = gr.Dropdown(label="Choose your STYLE", choices=STYLE_NAMES)
|
| 400 |
with gr.Row(equal_height=True): # Center the face file
|
| 401 |
with gr.Column(elem_id="centered-face", elem_classes=["centered-column"]): # Use CSS class for centering
|
| 402 |
face_file = gr.Image(label="Upload a photo of your face", type="pil", height=400, width=500)
|
| 403 |
+
submit = gr.Button("Submit", variant="primary",elem_id="submit-btn")
|
| 404 |
with gr.Column():
|
| 405 |
with gr.Row():
|
| 406 |
+
gallery1 = gr.Image(label="Generated Images", interactive=False, height=640, width=640)
|
| 407 |
+
gallery2 = gr.Image(label="Generated Images", interactive=False, height=640, width=640)
|
| 408 |
with gr.Row():
|
| 409 |
+
gallery3 = gr.Image(label="Generated Images", interactive=False, height=640, width=640)
|
| 410 |
+
gallery4 = gr.Image(label="Generated Images", interactive=False, height=640, width=640)
|
| 411 |
email = gr.Textbox(label="Email", info="Enter your email address", value="")
|
| 412 |
+
consent = gr.Checkbox(label="I am giving my consent to use my data to share my AI Avtar and IDfy relevant information from time to time", value=True)
|
| 413 |
+
submit1 = gr.Button("SUBMIT", variant = "primary", elem_id="store-btn")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
usage_tips = gr.Markdown(label="Usage tips of InstantID", value=tips ,visible=False)
|
| 415 |
|
| 416 |
face_file.upload(
|
|
|
|
| 462 |
|
| 463 |
submit1.click(
|
| 464 |
fn=store_images,
|
| 465 |
+
inputs=[email,gallery1,gallery2,gallery3,gallery4,consent,style],
|
| 466 |
+
outputs=[face_file,gallery1,gallery2,gallery3,gallery4])
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
gr.Markdown(article)
|
| 471 |
|
| 472 |
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
if __name__ == "__main__":
|
| 474 |
parser = argparse.ArgumentParser()
|
| 475 |
parser.add_argument("--pretrained_model_name_or_path", type=str, default="wangqixun/YamerMIX_v8")
|
image_data.csv
CHANGED
|
@@ -13,3 +13,4 @@ yashvi,images/yashvi_gallery1.png,images/yashvi_gallery2.png,images/yashvi_galle
|
|
| 13 |
[email protected],images/[email protected]_gallery1.png,images/[email protected]_gallery2.png,images/[email protected]_gallery3.png,images/[email protected]_gallery4.png
|
| 14 |
kartik@prof,images/kartik@prof_gallery1.png,images/kartik@prof_gallery2.png,images/kartik@prof_gallery3.png,images/kartik@prof_gallery4.png
|
| 15 |
yashvii@proffffff,images/yashvii@proffffff_gallery1.png,images/yashvii@proffffff_gallery2.png,images/yashvii@proffffff_gallery3.png,images/yashvii@proffffff_gallery4.png
|
|
|
|
|
|
| 13 |
[email protected],images/[email protected]_gallery1.png,images/[email protected]_gallery2.png,images/[email protected]_gallery3.png,images/[email protected]_gallery4.png
|
| 14 |
kartik@prof,images/kartik@prof_gallery1.png,images/kartik@prof_gallery2.png,images/kartik@prof_gallery3.png,images/kartik@prof_gallery4.png
|
| 15 |
yashvii@proffffff,images/yashvii@proffffff_gallery1.png,images/yashvii@proffffff_gallery2.png,images/yashvii@proffffff_gallery3.png,images/yashvii@proffffff_gallery4.png
|
| 16 |
+
yashviii@qq,images/yashviii@qq_gallery1.png,images/yashviii@qq_gallery2.png,images/yashviii@qq_gallery3.png,images/yashviii@qq_gallery4.png
|
images/reena@lowq_gallery1.png
ADDED
|
|
images/reena@lowq_gallery2.png
ADDED
|
|
images/reena@lowq_gallery3.png
ADDED
|
|
images/yashviii@qq_gallery1.png
ADDED
|
|
Git LFS Details
|
images/yashviii@qq_gallery2.png
ADDED
|
|
Git LFS Details
|
images/yashviii@qq_gallery3.png
ADDED
|
|
Git LFS Details
|
images/yashviii@qq_gallery4.png
ADDED
|
|
Git LFS Details
|
requirements.txt
CHANGED
|
@@ -16,4 +16,5 @@ gradio==4.38.1
|
|
| 16 |
controlnet_aux==0.0.9
|
| 17 |
gdown==5.2.0
|
| 18 |
peft==0.11.1
|
| 19 |
-
setuptools==71.1.0
|
|
|
|
|
|
| 16 |
controlnet_aux==0.0.9
|
| 17 |
gdown==5.2.0
|
| 18 |
peft==0.11.1
|
| 19 |
+
setuptools==71.1.0
|
| 20 |
+
google-cloud-storage==2.18.2
|
serviceaccount.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"type": "service_account",
|
| 3 |
+
"project_id": "idfy-eve-ml-training",
|
| 4 |
+
"private_key_id": "10af299eab9393498e6b78641f698091bb173208",
|
| 5 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDGPFFdelZGWBGU\nte130Ih/7rlY4HH4qI9M97TV03kdVMeQiqsLCTV2ao6Nga6enXEjvFNjktYsaXC5\n7970uzHyepbZxiEsGxcZZMYfHSF+2sdMqoNhlNC4MrPjFqt+hTRNoqz3d68OSIwq\nKTmrQARboOP/D7KpftV9w+3NUIGm8I0Wz569E0/nBKKZvJ7X71EroHNJKX6lEWp0\nTXJC5CxRMbCKibX0J9cwtcxt0oUs+kdEeN7wxOfIuu7zRia9Ek4zoDgB0SElzjD+\n6tTL2G40qewWXUJOZl7oPI+uu9vYsDzbi4xb31aHlMbdaTPTxZWk//he96OJpNGZ\neFUInrOXAgMBAAECggEAA0w1k6HZXK3EJ8WZqpbO0g5yl8aSSXZymgvYaWKmUnjP\n6RHeXMWGcieg+FjFtKeQEApYpTmg/neykbN/1RwtbWuoNBnkju7Ub4rRnyPFXRkX\nf6k4Ry30zLD5dRtq/ghDBSXTosh4sJc/6+OhAmi7/yhxIoWIxnENQlyOtCpU6HtW\nrDcGGT9bNVxFMug0zE4E1NAN+KeVjXelaiC/IbK0YhN/bXgKKTfSx/kZCknPBgZu\nJ+jdQxRkqEgMV/D4O7/RU/AzfryEeMib8d4Kz2JqZ4vZ9nnmg9ndyoQMeDqLttXQ\nbYDc0Ey55XOiwNL9g7OGTSgN+FQmixomg4kjvPa9AQKBgQDnzZu6hUmYtIsN71xQ\nCledmCPKDOpeJuDkOxGW5zgW6Imok2VRDTWVflKh7S+ABVeN1aLZJ+QEJcnfC+DW\naV/9uuWg9p0zVl5cyx4b6Re0W28xVZem0s+fHX4sKuj+LYPeFIH7Ubdz0YgcDpOH\n7lRQBPQHMKZ5DZCFCdNgMWq69wKBgQDa7bJAnnOdQF+D87nQt9mZp9aX9BSM/cBj\nk4VzDFfliDOgoPW6FEuXN5Tq4aaS0Cbok7J5HivHTOLTlcoWIgIbaJx1RW8UU9O9\ntG3NbFPE+Nfbf3kwugMb2peYdzfm12CD/HsXFKXbT9UZOCTa2nL+SlWDgsUQXGYo\nKQiVe04EYQKBgBnaD20c4llagUubj1MJ5D2aMxuclyLK+Tfa8po+zT2Yz4lybtE8\nROaYQQT4G90OO3aBBflr/n0L7dinTXr8I417o5JxDpUkI7/7ky8PruoZbGw3HIOp\nbShUtLaeTn/Seatx5BEwSuJq0uA2K/Pz+4k1FDYdEePcRGrh7qYCvOF/AoGBAJox\nO5CDiQ5CHoPDDyZPtrSgH2YahLbgqbX4Ws8y7F0/Vo1VkHwkezDf9sSPdVCFxkGc\ndOEVPOQ75K39G74G6dEAFuIJqzh36fP8tjEukLl0QiPYXjTRbgsaJBdAMGEnZFTR\naKhS5JXYXlBK2LpDjSZImH3thnoFefXjIKaXl9VBAoGADQsTZI8ZMYTv7DQhlU8g\nbIp2KRM7BvU2Ypi/3XBje0tFQBigoCgc4xO13YGc1KM05Sd8Z0HsKDiYPfyB/zs6\ntnveIl5pBDmgn+G+1wP6aobtiyL7ponQvd4cDNVQrGSM5r4RVuiqzfBsQM0p4nAX\nMW27iQwCQHrxCYA6JA+n98U=\n-----END PRIVATE KEY-----\n",
|
| 6 |
+
"client_email": "[email protected]",
|
| 7 |
+
"client_id": "104779890112284608471",
|
| 8 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 9 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 10 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 11 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/idfy-gff-public%40idfy-eve-ml-training.iam.gserviceaccount.com",
|
| 12 |
+
"universe_domain": "googleapis.com"
|
| 13 |
+
}
|