emirhanno commited on
Commit
3f0e127
1 Parent(s): 68f6e22

bugfix and additions

Browse files
Files changed (2) hide show
  1. app.py +19 -3
  2. requirements.txt +14 -0
app.py CHANGED
@@ -13,6 +13,8 @@ import imutils
13
  from imutils import face_utils
14
  import numpy as np
15
  from skimage import transform as tf
 
 
16
 
17
  base_model_path = "SG161222/Realistic_Vision_V6.0_B1_noVAE"
18
  base_cache = "model-cache"
@@ -94,12 +96,26 @@ def morph_faces(image1_path, image2_path, alpha=0.5):
94
  cv2.imwrite(output_path, morphed_image)
95
  return output_path
96
 
97
- def generate_image(face_image_1, face_image_2, prompt, negative_prompt, width, height, num_inference_steps, seed):
 
 
 
 
 
 
 
 
98
  if seed is None:
99
  seed = int.from_bytes(os.urandom(4), "big")
100
 
 
 
 
 
 
101
  baby_image_path = morph_faces(face_image_1.name, face_image_2.name)
102
 
 
103
  def generate_images(faceid_embeds, num_outputs=1):
104
  images = ip_model.generate(
105
  prompt=prompt,
@@ -125,8 +141,8 @@ gr_interface = gr.Interface(
125
  inputs=[
126
  gr.Image(type="file", label="First Face Image"),
127
  gr.Image(type="file", label="Second Face Image"),
128
- gr.Textbox(value="portrait of a 6 y.o. boy, male child, 8k, HD, happy, in living room, perfect eyes, cute", label="Prompt"),
129
- gr.Textbox(value="(mascara, makeup: 1.4), (breasts, boobs, naked, nude: 1.4), (beard, old, mustache, wrinkles: 1.4), (deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation", label="Negative Prompt"),
130
  gr.Slider(256, 1024, value=768, step=64, label="Width"),
131
  gr.Slider(256, 1024, value=768, step=64, label="Height"),
132
  gr.Slider(1, 200, value=30, step=1, label="Number of Inference Steps"),
 
13
  from imutils import face_utils
14
  import numpy as np
15
  from skimage import transform as tf
16
+ import random
17
+ import spaces
18
 
19
  base_model_path = "SG161222/Realistic_Vision_V6.0_B1_noVAE"
20
  base_cache = "model-cache"
 
96
  cv2.imwrite(output_path, morphed_image)
97
  return output_path
98
 
99
+ def get_negative_prompt(gender):
100
+ if gender == "Boy":
101
+ return "(mascara, makeup: 1.4), (breasts, boobs, naked, nude: 1.4), (deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation"
102
+ elif gender == "Girl":
103
+ return "(beard, mustache, male features: 1.4), (naked, nude: 1.4), (deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation"
104
+ else: # Random
105
+ return "(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation"
106
+
107
+ def generate_image(face_image_1, face_image_2, prompt, gender, width, height, num_inference_steps, seed):
108
  if seed is None:
109
  seed = int.from_bytes(os.urandom(4), "big")
110
 
111
+ if gender == "Random":
112
+ gender = random.choice(["Boy", "Girl"])
113
+
114
+ negative_prompt = get_negative_prompt(gender)
115
+
116
  baby_image_path = morph_faces(face_image_1.name, face_image_2.name)
117
 
118
+ @spaces.GPU(duration=30)
119
  def generate_images(faceid_embeds, num_outputs=1):
120
  images = ip_model.generate(
121
  prompt=prompt,
 
141
  inputs=[
142
  gr.Image(type="file", label="First Face Image"),
143
  gr.Image(type="file", label="Second Face Image"),
144
+ gr.Textbox(value="portrait of a 6 y.o. child, 8k, HD, happy, in living room, perfect eyes, cute", label="Prompt"),
145
+ gr.Dropdown(choices=["Boy", "Girl", "Random"], value="Boy", label="Gender"),
146
  gr.Slider(256, 1024, value=768, step=64, label="Width"),
147
  gr.Slider(256, 1024, value=768, step=64, label="Height"),
148
  gr.Slider(1, 200, value=30, step=1, label="Number of Inference Steps"),
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ opencv-python-headless
2
+ accelerate==0.24.0
3
+ diffusers==0.23.0
4
+ einops
5
+ insightface==0.7.3
6
+ onnxruntime-gpu
7
+ torch==2.0.1
8
+ torchvision==0.15.2
9
+ transformers==4.35.0
10
+ albumentations==1.1.0
11
+ imutils
12
+ dlib
13
+ cmake
14
+ git+https://github.com/tencent-ailab/IP-Adapter.git