Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -114,25 +114,35 @@ def end_session(req: gr.Request):
|
|
114 |
shutil.rmtree(user_dir)
|
115 |
|
116 |
@spaces.GPU
|
117 |
-
def preprocess_image(
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
ratio = np.sqrt(1024. * 1024. / (width * height))
|
127 |
new_width, new_height = int(width * ratio), int(height * ratio)
|
128 |
image = image['composite'].resize((new_width, new_height))
|
129 |
image = ImageOps.invert(image)
|
130 |
|
131 |
-
print("image:",type(image))
|
132 |
|
|
|
133 |
prompt, negative_prompt = apply_style(style_name, prompt, negative_prompt)
|
134 |
-
|
135 |
print("params:", prompt, negative_prompt, style_name, num_steps, guidance_scale, controlnet_conditioning_scale)
|
|
|
|
|
136 |
output = pipe_control(
|
137 |
prompt=prompt,
|
138 |
negative_prompt=negative_prompt,
|
@@ -141,11 +151,17 @@ def preprocess_image(image: Image.Image,
|
|
141 |
controlnet_conditioning_scale=controlnet_conditioning_scale,
|
142 |
guidance_scale=guidance_scale,
|
143 |
width=new_width,
|
144 |
-
height=new_height
|
145 |
-
|
146 |
-
|
|
|
|
|
|
|
|
|
|
|
147 |
processed_image = pipeline.preprocess_image(output)
|
148 |
-
|
|
|
149 |
|
150 |
def pack_state(gs: Gaussian, mesh: MeshExtractResult) -> dict:
|
151 |
return {
|
|
|
114 |
shutil.rmtree(user_dir)
|
115 |
|
116 |
@spaces.GPU
|
117 |
+
def preprocess_image(
|
118 |
+
image: Image.Image,
|
119 |
+
prompt: str = "",
|
120 |
+
negative_prompt: str = "",
|
121 |
+
style_name: str = "",
|
122 |
+
num_steps: int = 25,
|
123 |
+
guidance_scale: float = 5,
|
124 |
+
controlnet_conditioning_scale: float = 1.0,
|
125 |
+
req: gr.Request = None # Agregamos el parámetro `req`
|
126 |
+
) -> Tuple[Image.Image, Image.Image]:
|
127 |
+
# Crear un directorio único para el usuario basado en su sesión
|
128 |
+
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
129 |
+
os.makedirs(user_dir, exist_ok=True) # Asegurarse de que el directorio existe
|
130 |
+
|
131 |
+
# Procesar las dimensiones de la imagen
|
132 |
+
width, height = image['composite'].size
|
133 |
ratio = np.sqrt(1024. * 1024. / (width * height))
|
134 |
new_width, new_height = int(width * ratio), int(height * ratio)
|
135 |
image = image['composite'].resize((new_width, new_height))
|
136 |
image = ImageOps.invert(image)
|
137 |
|
138 |
+
print("image:", type(image))
|
139 |
|
140 |
+
# Aplicar estilo al prompt
|
141 |
prompt, negative_prompt = apply_style(style_name, prompt, negative_prompt)
|
142 |
+
|
143 |
print("params:", prompt, negative_prompt, style_name, num_steps, guidance_scale, controlnet_conditioning_scale)
|
144 |
+
|
145 |
+
# Generar la imagen procesada usando el pipeline
|
146 |
output = pipe_control(
|
147 |
prompt=prompt,
|
148 |
negative_prompt=negative_prompt,
|
|
|
151 |
controlnet_conditioning_scale=controlnet_conditioning_scale,
|
152 |
guidance_scale=guidance_scale,
|
153 |
width=new_width,
|
154 |
+
height=new_height
|
155 |
+
).images[0]
|
156 |
+
|
157 |
+
# Guardar la imagen procesada en el directorio del usuario
|
158 |
+
processed_image_path = os.path.join(user_dir, 'processed_image.png')
|
159 |
+
output.save(processed_image_path)
|
160 |
+
|
161 |
+
# Preprocesar la imagen para el siguiente paso (si es necesario)
|
162 |
processed_image = pipeline.preprocess_image(output)
|
163 |
+
|
164 |
+
return image, processed_image
|
165 |
|
166 |
def pack_state(gs: Gaussian, mesh: MeshExtractResult) -> dict:
|
167 |
return {
|