Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse files- .gitattributes +11 -0
- Untitled1.ipynb +6 -0
- gradio_demo/app.py +96 -184
- gradio_demo/logo.png +0 -0
- gradio_demo/logo1.png +0 -0
- gradio_demo/watermark.png +0 -0
- image_data.csv +5 -0
- images/aa.ll_gallery1.png +3 -0
- images/aa.ll_gallery2.png +0 -0
- images/aa.ll_gallery3.png +0 -0
- images/aa.ll_gallery4.png +0 -0
- images/kartik@prof_gallery1.png +0 -0
- images/kartik@prof_gallery2.png +0 -0
- images/kartik@prof_gallery3.png +0 -0
- images/kartik@prof_gallery4.png +0 -0
- images/reena@lowq_gallery1.png +0 -0
- images/reena@lowq_gallery2.png +0 -0
- images/reena@lowq_gallery3.png +0 -0
- images/yashvi_gallery1.png +3 -0
- images/yashvi_gallery2.png +0 -0
- images/yashvi_gallery3.png +0 -0
- images/yashvi_gallery4.png +3 -0
- images/yashvii@proffffff_gallery1.png +0 -0
- images/yashvii@proffffff_gallery2.png +0 -0
- images/yashvii@proffffff_gallery3.png +0 -0
- images/yashvii@proffffff_gallery4.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
- images/yashviwhy@instantid.com_gallery1.png +3 -0
- images/yashviwhy@instantid.com_gallery2.png +3 -0
- images/yashviwhy@instantid.com_gallery3.png +3 -0
- images/yashviwhy@instantid.com_gallery4.png +3 -0
- requirements.txt +2 -1
- serviceaccount.json +13 -0
.gitattributes
CHANGED
@@ -39,3 +39,14 @@ generated_images/20240723_053853_022841_0.png filter=lfs diff=lfs merge=lfs -tex
|
|
39 |
generated_images/20240723_053948_468290_0.png filter=lfs diff=lfs merge=lfs -text
|
40 |
generated_images/20240723_054025_692605_0.png filter=lfs diff=lfs merge=lfs -text
|
41 |
generated_images/20240723_054124_697176_0.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
generated_images/20240723_053948_468290_0.png filter=lfs diff=lfs merge=lfs -text
|
40 |
generated_images/20240723_054025_692605_0.png filter=lfs diff=lfs merge=lfs -text
|
41 |
generated_images/20240723_054124_697176_0.png filter=lfs diff=lfs merge=lfs -text
|
42 |
+
images/aa.ll_gallery1.png filter=lfs diff=lfs merge=lfs -text
|
43 |
+
images/yashvi_gallery1.png filter=lfs diff=lfs merge=lfs -text
|
44 |
+
images/yashvi_gallery4.png filter=lfs diff=lfs merge=lfs -text
|
45 |
+
images/yashviii@qq_gallery1.png filter=lfs diff=lfs merge=lfs -text
|
46 |
+
images/yashviii@qq_gallery2.png filter=lfs diff=lfs merge=lfs -text
|
47 |
+
images/yashviii@qq_gallery3.png filter=lfs diff=lfs merge=lfs -text
|
48 |
+
images/yashviii@qq_gallery4.png filter=lfs diff=lfs merge=lfs -text
|
49 |
+
images/yashviwhy@instantid.com_gallery1.png filter=lfs diff=lfs merge=lfs -text
|
50 |
+
images/yashviwhy@instantid.com_gallery2.png filter=lfs diff=lfs merge=lfs -text
|
51 |
+
images/yashviwhy@instantid.com_gallery3.png filter=lfs diff=lfs merge=lfs -text
|
52 |
+
images/yashviwhy@instantid.com_gallery4.png filter=lfs diff=lfs merge=lfs -text
|
Untitled1.ipynb
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [],
|
3 |
+
"metadata": {},
|
4 |
+
"nbformat": 4,
|
5 |
+
"nbformat_minor": 5
|
6 |
+
}
|
gradio_demo/app.py
CHANGED
@@ -10,6 +10,7 @@ import torch
|
|
10 |
import random
|
11 |
import numpy as np
|
12 |
import argparse
|
|
|
13 |
|
14 |
import PIL
|
15 |
from PIL import Image
|
@@ -28,6 +29,26 @@ from style_template import styles
|
|
28 |
from pipeline_stable_diffusion_xl_instantid_full import StableDiffusionXLInstantIDPipeline
|
29 |
from model_util import load_models_xl, get_torch_device, torch_gc
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# global variable
|
33 |
MAX_SEED = np.iinfo(np.int32).max
|
@@ -47,22 +68,16 @@ controlnet_path = f'./checkpoints/ControlNetModel'
|
|
47 |
# Load pipeline
|
48 |
controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=dtype)
|
49 |
|
50 |
-
logo = Image.open("./gradio_demo/
|
|
|
51 |
|
52 |
from cv2 import imencode
|
53 |
import base64
|
54 |
|
55 |
-
# def encode_pil_to_base64_new(pil_image):
|
56 |
-
# print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
|
57 |
-
# image_arr = np.asarray(pil_image)[:,:,::-1]
|
58 |
-
# _, byte_data = imencode('.png', image_arr)
|
59 |
-
# base64_data = base64.b64encode(byte_data)
|
60 |
-
# base64_string_opencv = base64_data.decode("utf-8")
|
61 |
-
# return "data:image/png;base64," + base64_string_opencv
|
62 |
-
|
63 |
import gradio as gr
|
|
|
|
|
64 |
|
65 |
-
# gr.processing_utils.encode_pil_to_base64 = encode_pil_to_base64_new
|
66 |
|
67 |
def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=False):
|
68 |
|
@@ -110,16 +125,8 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
110 |
pipe.disable_lora()
|
111 |
|
112 |
def remove_tips():
|
113 |
-
print("GG")
|
114 |
return gr.update(visible=False)
|
115 |
|
116 |
-
|
117 |
-
# prompts = [
|
118 |
-
# ["superman","Vibrant Color"], ["japanese anime character with white/neon hair","Watercolor"],
|
119 |
-
# # ["Suited professional","(No style)"],
|
120 |
-
# ["Scooba diver","Line art"], ["eskimo","Snow"]
|
121 |
-
# ]
|
122 |
-
|
123 |
def convert_from_cv2_to_image(img: np.ndarray) -> Image:
|
124 |
return Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
|
125 |
|
@@ -144,12 +151,25 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
144 |
# if email != "":
|
145 |
p,n = styles.get(style, styles.get(STYLE_NAMES[1]))
|
146 |
return generate_image(face_file, p[3], n)
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
#
|
151 |
-
|
152 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
def draw_kps(image_pil, kps, color_list=[(255,0,0), (0,255,0), (0,0,255), (255,255,0), (255,0,255)]):
|
155 |
stickwidth = 4
|
@@ -183,7 +203,6 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
183 |
pad_to_max_side=True, mode=PIL.Image.BILINEAR, base_pixel_number=64):
|
184 |
|
185 |
w, h = input_image.size
|
186 |
-
print(f"Original Size --> {input_image.size}")
|
187 |
if size is not None:
|
188 |
w_resize_new, h_resize_new = size
|
189 |
else:
|
@@ -201,14 +220,28 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
201 |
offset_y = (max_side - h_resize_new) // 2
|
202 |
res[offset_y:offset_y+h_resize_new, offset_x:offset_x+w_resize_new] = np.array(input_image)
|
203 |
input_image = Image.fromarray(res)
|
204 |
-
|
205 |
-
print(f"Final modified image size --> {input_image.size}")
|
206 |
return input_image
|
207 |
|
208 |
# def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
209 |
# p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
210 |
# return p.replace("{prompt}", positive), n + ' ' + negative
|
211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
def add_watermark(image, watermark=logo, opacity=128, position="bottom_right", padding=10):
|
213 |
# Convert NumPy array to PIL Image if needed
|
214 |
if isinstance(image, np.ndarray):
|
@@ -248,6 +281,7 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
248 |
if image.mode != "RGBA":
|
249 |
image = image.convert("RGB")
|
250 |
|
|
|
251 |
return image
|
252 |
|
253 |
def generate_image(face_image,prompt,negative_prompt):
|
@@ -256,13 +290,9 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
256 |
enable_LCM = False
|
257 |
identitynet_strength_ratio = 0.90
|
258 |
adapter_strength_ratio = 0.60
|
259 |
-
num_steps =
|
260 |
guidance_scale = 5
|
261 |
seed = random.randint(0, MAX_SEED)
|
262 |
-
print(f"Seed --> {seed}")
|
263 |
-
|
264 |
-
# negative_prompt = ""
|
265 |
-
# negative_prompt += neg
|
266 |
enhance_face_region = True
|
267 |
if enable_LCM:
|
268 |
pipe.enable_lora()
|
@@ -273,14 +303,6 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
273 |
|
274 |
if face_image is None:
|
275 |
raise gr.Error(f"Cannot find any input face image! Please upload the face image")
|
276 |
-
|
277 |
-
# if prompt is None:
|
278 |
-
# prompt = "a person"
|
279 |
-
|
280 |
-
# apply the style template
|
281 |
-
# prompt, negative_prompt = apply_style(style_name, prompt, negative_prompt)
|
282 |
-
|
283 |
-
# face_image = load_image(face_image_path)
|
284 |
face_image = resize_img(face_image)
|
285 |
face_image_cv2 = convert_from_image_to_cv2(face_image)
|
286 |
height, width, _ = face_image_cv2.shape
|
@@ -321,9 +343,6 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
321 |
|
322 |
generator = torch.Generator(device=device).manual_seed(seed)
|
323 |
|
324 |
-
print("Start inference...")
|
325 |
-
print(f"[Debug] Prompt: {prompt}, \n[Debug] Neg Prompt: {negative_prompt}")
|
326 |
-
|
327 |
pipe.set_ip_adapter_scale(adapter_strength_ratio)
|
328 |
images = pipe(
|
329 |
prompt=prompt,
|
@@ -347,46 +366,52 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
347 |
|
348 |
### Description
|
349 |
title = r"""
|
350 |
-
<h1 align="center">Choose your AVATAR</h1>
|
351 |
"""
|
352 |
|
353 |
description = r"""
|
354 |
-
<h2> Powered by IDfy </h2>"""
|
355 |
|
356 |
article = r""""""
|
357 |
|
358 |
tips = r""""""
|
359 |
-
|
360 |
css = '''
|
361 |
-
.gradio-container {width:
|
362 |
-
.image-gallery {height: 100vh !important; overflow: auto;}
|
363 |
.gradio-row .gradio-element { margin: 0 !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
364 |
'''
|
365 |
with gr.Blocks(css=css) as demo:
|
366 |
|
367 |
-
|
368 |
gr.Markdown(title)
|
369 |
-
with gr.
|
370 |
-
gr.
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
|
|
377 |
with gr.Column():
|
378 |
with gr.Row():
|
379 |
-
gallery1 = gr.Image(label="Generated Images")
|
380 |
-
gallery2 = gr.Image(label="Generated Images")
|
381 |
with gr.Row():
|
382 |
-
gallery3 = gr.Image(label="Generated Images")
|
383 |
-
gallery4 = gr.Image(label="Generated Images")
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
usage_tips = gr.Markdown(label="Usage tips of InstantID", value=tips ,visible=False)
|
390 |
|
391 |
face_file.upload(
|
392 |
fn=remove_tips,
|
@@ -435,129 +460,16 @@ def main(pretrained_model_name_or_path="wangqixun/YamerMIX_v8", enable_lcm_arg=F
|
|
435 |
outputs=[gallery4]
|
436 |
)
|
437 |
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
|
443 |
|
444 |
|
445 |
gr.Markdown(article)
|
446 |
|
447 |
demo.launch(share=True)
|
448 |
-
|
449 |
-
# with gr.Blocks(css=css, js=js) as demo:
|
450 |
-
|
451 |
-
# # description
|
452 |
-
# gr.Markdown(title)
|
453 |
-
# with gr.Row():
|
454 |
-
# gr.Image("./gradio_demo/logo.png",scale=0,min_width=50,show_label=False,show_download_button=False)
|
455 |
-
# gr.Markdown(description)
|
456 |
-
# with gr.Row():
|
457 |
-
# with gr.Column():
|
458 |
-
# style = gr.Dropdown(label="Choose your STYLE", choices=STYLE_NAMES)
|
459 |
-
# face_file = gr.Image(label="Upload a photo of your face", type="pil",sources="webcam")
|
460 |
-
# submit = gr.Button("Submit", variant="primary")
|
461 |
-
# with gr.Column():
|
462 |
-
# with gr.Row():
|
463 |
-
# gallery1 = gr.Image(label="Generated Images")
|
464 |
-
# gallery2 = gr.Image(label="Generated Images")
|
465 |
-
# with gr.Row():
|
466 |
-
# gallery3 = gr.Image(label="Generated Images")
|
467 |
-
# gallery4 = gr.Image(label="Generated Images")
|
468 |
-
# email = gr.Textbox(label="Email",
|
469 |
-
# info="Enter your email address",
|
470 |
-
# value="")
|
471 |
-
|
472 |
-
# usage_tips = gr.Markdown(label="Usage tips of InstantID", value=tips ,visible=False)
|
473 |
-
# # identitynet_strength_ratio = gr.Slider(
|
474 |
-
# # label="IdentityNet strength (for fidelity)",
|
475 |
-
# # minimum=0,
|
476 |
-
# # maximum=1.5,
|
477 |
-
# # step=0.05,
|
478 |
-
# # value=0.95,
|
479 |
-
# # )
|
480 |
-
# # adapter_strength_ratio = gr.Slider(
|
481 |
-
# # label="Image adapter strength (for detail)",
|
482 |
-
# # minimum=0,
|
483 |
-
# # maximum=1.5,
|
484 |
-
# # step=0.05,
|
485 |
-
# # value=0.60,
|
486 |
-
# # )
|
487 |
-
# # negative_prompt = gr.Textbox(
|
488 |
-
# # label="Negative Prompt",
|
489 |
-
# # placeholder="low quality",
|
490 |
-
# # 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",
|
491 |
-
# # )
|
492 |
-
# # num_steps = gr.Slider(
|
493 |
-
# # label="Number of sample steps",
|
494 |
-
# # minimum=15,
|
495 |
-
# # maximum=100,
|
496 |
-
# # step=1,
|
497 |
-
# # value=5 if enable_lcm_arg else 15,
|
498 |
-
# # )
|
499 |
-
# # guidance_scale = gr.Slider(
|
500 |
-
# # label="Guidance scale",
|
501 |
-
# # minimum=0.1,
|
502 |
-
# # maximum=10.0,
|
503 |
-
# # step=0.1,
|
504 |
-
# # value=0 if enable_lcm_arg else 8.5,
|
505 |
-
# # )
|
506 |
-
# # if email is None:
|
507 |
-
# # print("STOPPPP")
|
508 |
-
# # raise gr.Error("Email ID is compulsory")
|
509 |
-
# face_file.upload(
|
510 |
-
# fn=remove_tips,
|
511 |
-
# outputs=usage_tips,
|
512 |
-
# queue=True,
|
513 |
-
# api_name=False,
|
514 |
-
# show_progress = "full"
|
515 |
-
# ).then(
|
516 |
-
# fn=run_for_prompts1,
|
517 |
-
# inputs=[face_file,style],
|
518 |
-
# outputs=[gallery1]
|
519 |
-
# ).then(
|
520 |
-
# fn=run_for_prompts2,
|
521 |
-
# inputs=[face_file,style],
|
522 |
-
# outputs=[gallery2]
|
523 |
-
# ).then(
|
524 |
-
# fn=run_for_prompts3,
|
525 |
-
# inputs=[face_file,style],
|
526 |
-
# outputs=[gallery3]
|
527 |
-
# ).then(
|
528 |
-
# fn=run_for_prompts4,
|
529 |
-
# inputs=[face_file,style],
|
530 |
-
# outputs=[gallery4]
|
531 |
-
# )
|
532 |
-
# submit.click(
|
533 |
-
# fn=remove_tips,
|
534 |
-
# outputs=usage_tips,
|
535 |
-
# queue=True,
|
536 |
-
# api_name=False,
|
537 |
-
# show_progress = "full"
|
538 |
-
# ).then(
|
539 |
-
# fn=run_for_prompts1,
|
540 |
-
# inputs=[face_file,style],
|
541 |
-
# outputs=[gallery1]
|
542 |
-
# ).then(
|
543 |
-
# fn=run_for_prompts2,
|
544 |
-
# inputs=[face_file,style],
|
545 |
-
# outputs=[gallery2]
|
546 |
-
# ).then(
|
547 |
-
# fn=run_for_prompts3,
|
548 |
-
# inputs=[face_file,style],
|
549 |
-
# outputs=[gallery3]
|
550 |
-
# ).then(
|
551 |
-
# fn=run_for_prompts4,
|
552 |
-
# inputs=[face_file,style],
|
553 |
-
# outputs=[gallery4]
|
554 |
-
# )
|
555 |
-
|
556 |
-
|
557 |
-
# gr.Markdown(article)
|
558 |
-
|
559 |
-
# demo.launch(share=True)
|
560 |
-
|
561 |
if __name__ == "__main__":
|
562 |
parser = argparse.ArgumentParser()
|
563 |
parser.add_argument("--pretrained_model_name_or_path", type=str, default="wangqixun/YamerMIX_v8")
|
|
|
10 |
import random
|
11 |
import numpy as np
|
12 |
import argparse
|
13 |
+
import pandas as pd
|
14 |
|
15 |
import PIL
|
16 |
from PIL import Image
|
|
|
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
|
|
|
68 |
# Load pipeline
|
69 |
controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=dtype)
|
70 |
|
71 |
+
logo = Image.open("./gradio_demo/watermark.png")
|
72 |
+
logo = logo.resize((100, 100))
|
73 |
|
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
|
247 |
if isinstance(image, np.ndarray):
|
|
|
281 |
if image.mode != "RGBA":
|
282 |
image = image.convert("RGB")
|
283 |
|
284 |
+
# return resize_img(image)
|
285 |
return image
|
286 |
|
287 |
def generate_image(face_image,prompt,negative_prompt):
|
|
|
290 |
enable_LCM = False
|
291 |
identitynet_strength_ratio = 0.90
|
292 |
adapter_strength_ratio = 0.60
|
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,
|
|
|
366 |
|
367 |
### Description
|
368 |
title = r"""
|
369 |
+
<h1 align="center" style="color:white;">Choose your AVATAR</h1>
|
370 |
"""
|
371 |
|
372 |
description = r"""
|
373 |
+
<h2 style="color:white;"> Powered by IDfy </h2>"""
|
374 |
|
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; }
|
381 |
+
.centered-column {
|
382 |
+
display: flex;
|
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 |
+
}
|
390 |
'''
|
391 |
with gr.Blocks(css=css) as demo:
|
392 |
|
393 |
+
# description
|
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(
|
417 |
fn=remove_tips,
|
|
|
460 |
outputs=[gallery4]
|
461 |
)
|
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")
|
gradio_demo/logo.png
CHANGED
gradio_demo/logo1.png
ADDED
gradio_demo/watermark.png
ADDED
image_data.csv
CHANGED
@@ -9,3 +9,8 @@ kajal@quirky,images/kajal@quirky_gallery1.png,images/kajal@quirky_gallery2.png,i
|
|
9 |
kajal@prof,images/kajal@prof_gallery1.png,images/kajal@prof_gallery2.png,images/kajal@prof_gallery3.png,images/kajal@prof_gallery4.png
|
10 |
kajal@quirky,images/kajal@quirky_gallery1.png,images/kajal@quirky_gallery2.png,images/kajal@quirky_gallery3.png,images/kajal@quirky_gallery4.png
|
11 |
kajal@sci-fi,images/kajal@sci-fi_gallery1.png,images/kajal@sci-fi_gallery2.png,images/kajal@sci-fi_gallery3.png,images/kajal@sci-fi_gallery4.png
|
|
|
|
|
|
|
|
|
|
|
|
9 |
kajal@prof,images/kajal@prof_gallery1.png,images/kajal@prof_gallery2.png,images/kajal@prof_gallery3.png,images/kajal@prof_gallery4.png
|
10 |
kajal@quirky,images/kajal@quirky_gallery1.png,images/kajal@quirky_gallery2.png,images/kajal@quirky_gallery3.png,images/kajal@quirky_gallery4.png
|
11 |
kajal@sci-fi,images/kajal@sci-fi_gallery1.png,images/kajal@sci-fi_gallery2.png,images/kajal@sci-fi_gallery3.png,images/kajal@sci-fi_gallery4.png
|
12 |
+
yashvi,images/yashvi_gallery1.png,images/yashvi_gallery2.png,images/yashvi_gallery3.png,images/yashvi_gallery4.png
|
13 |
+
yashviwhy@instantid.com,images/yashviwhy@instantid.com_gallery1.png,images/yashviwhy@instantid.com_gallery2.png,images/yashviwhy@instantid.com_gallery3.png,images/yashviwhy@instantid.com_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/aa.ll_gallery1.png
ADDED
Git LFS Details
|
images/aa.ll_gallery2.png
ADDED
images/aa.ll_gallery3.png
ADDED
images/aa.ll_gallery4.png
ADDED
images/kartik@prof_gallery1.png
ADDED
images/kartik@prof_gallery2.png
ADDED
images/kartik@prof_gallery3.png
ADDED
images/kartik@prof_gallery4.png
ADDED
images/reena@lowq_gallery1.png
ADDED
images/reena@lowq_gallery2.png
ADDED
images/reena@lowq_gallery3.png
ADDED
images/yashvi_gallery1.png
ADDED
Git LFS Details
|
images/yashvi_gallery2.png
ADDED
images/yashvi_gallery3.png
ADDED
images/yashvi_gallery4.png
ADDED
Git LFS Details
|
images/yashvii@proffffff_gallery1.png
ADDED
images/yashvii@proffffff_gallery2.png
ADDED
images/yashvii@proffffff_gallery3.png
ADDED
images/yashvii@proffffff_gallery4.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
|
images/yashviwhy@instantid.com_gallery1.png
ADDED
Git LFS Details
|
images/yashviwhy@instantid.com_gallery2.png
ADDED
Git LFS Details
|
images/yashviwhy@instantid.com_gallery3.png
ADDED
Git LFS Details
|
images/yashviwhy@instantid.com_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": "idfy-gff-public@idfy-eve-ml-training.iam.gserviceaccount.com",
|
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 |
+
}
|