fountai commited on
Commit
5cee4f3
1 Parent(s): dc56d68

fix image geneartion

Browse files
Files changed (2) hide show
  1. app.py +17 -14
  2. default.jpeg +0 -0
app.py CHANGED
@@ -62,24 +62,28 @@ def maskHead(input):
62
  return output_image
63
 
64
  def random_positioning(input, output_size=(1024, 1024)):
65
- if input is None:
66
- raise ValueError("Impossible to load image")
 
 
 
67
 
 
 
 
68
  scale_factor = random.uniform(0.5, 1.0)
 
69
 
70
- new_size = (int(input.shape[1] * scale_factor), int(input.shape[0] * scale_factor))
71
-
72
- resized_image = cv2.resize(input, new_size, interpolation=cv2.INTER_AREA)
73
-
74
- background = np.zeros((output_size[1], output_size[0], 3), dtype=np.uint8)
75
-
76
  x_offset = random.randint(0, output_size[0] - new_size[0])
77
  y_offset = random.randint(0, output_size[1] - new_size[1])
78
-
79
  background[y_offset:y_offset+new_size[1], x_offset:x_offset+new_size[0]] = resized_image
80
- background = np.clip(background, 0, 255)
81
- background = background.astype(np.uint8)
82
-
83
  return background
84
 
85
 
@@ -112,7 +116,7 @@ def execute(image, prompt):
112
  img = cv2.imread(image)
113
  img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
114
 
115
- imgs = [ random_positioning(img)]
116
 
117
  pipe.load_lora_weights("XLabs-AI/flux-RealismLora", weight_name='lora.safetensors')
118
  response = []
@@ -154,7 +158,6 @@ def execute(image, prompt):
154
  description = "This is an unofficial implementation of the ip face adapter for FLUX DEV and does not explicitly follow the ip face model, I created a wrapper with inpaint and mediapipe, I like using Fake IP Adapter"
155
  title = "Flux IP Face Adapter"
156
  iface = gr.Interface(
157
- theme=gr.themes.Glass(),
158
  fn=execute,
159
  description=description,
160
  title=title,
 
62
  return output_image
63
 
64
  def random_positioning(input, output_size=(1024, 1024)):
65
+ background = cv2.imread("default.jpeg")
66
+ if background is None:
67
+ raise ValueError("Unable to load background image")
68
+
69
+ background = cv2.resize(background, output_size, interpolation=cv2.INTER_AREA)
70
 
71
+ if input_image is None:
72
+ raise ValueError("Unable to load input image")
73
+
74
  scale_factor = random.uniform(0.5, 1.0)
75
+ new_size = (int(input_image.shape[1] * scale_factor), int(input_image.shape[0] * scale_factor))
76
 
77
+ resized_image = cv2.resize(input_image, new_size, interpolation=cv2.INTER_AREA)
78
+
79
+ if background.shape[2] != resized_image.shape[2]:
80
+ raise ValueError("Input image and background image must have the same number of channels")
81
+
 
82
  x_offset = random.randint(0, output_size[0] - new_size[0])
83
  y_offset = random.randint(0, output_size[1] - new_size[1])
84
+ # Sobrepor a imagem redimensionada na imagem de fundo
85
  background[y_offset:y_offset+new_size[1], x_offset:x_offset+new_size[0]] = resized_image
86
+
 
 
87
  return background
88
 
89
 
 
116
  img = cv2.imread(image)
117
  img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
118
 
119
+ imgs = [ random_positioning(img), random_positioning(img)]
120
 
121
  pipe.load_lora_weights("XLabs-AI/flux-RealismLora", weight_name='lora.safetensors')
122
  response = []
 
158
  description = "This is an unofficial implementation of the ip face adapter for FLUX DEV and does not explicitly follow the ip face model, I created a wrapper with inpaint and mediapipe, I like using Fake IP Adapter"
159
  title = "Flux IP Face Adapter"
160
  iface = gr.Interface(
 
161
  fn=execute,
162
  description=description,
163
  title=title,
default.jpeg ADDED