Spaces:
Running
Running
salomonsky
commited on
Commit
•
dd9a5a8
1
Parent(s):
e019f29
Update app.py
Browse files
app.py
CHANGED
@@ -32,8 +32,16 @@ async def generate_image(prompt, model, lora_word, width, height, scales, steps,
|
|
32 |
print(f"Error generating image: {e}")
|
33 |
return None, None
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_factor, process_upscale, lora_model, process_lora):
|
36 |
-
"""Genera una imagen y la ajusta"""
|
37 |
model = enable_lora(lora_model, basemodel) if process_lora else basemodel
|
38 |
image, seed = await generate_image(prompt, model, "", width, height, scales, steps, seed)
|
39 |
if image is None:
|
@@ -44,20 +52,11 @@ async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_fac
|
|
44 |
|
45 |
if process_upscale:
|
46 |
upscale_image = get_upscale_finegrain(prompt, image_path, upscale_factor)
|
|
|
|
|
|
|
47 |
else:
|
48 |
-
|
49 |
-
|
50 |
-
return [image_path, upscale_image]
|
51 |
-
|
52 |
-
def get_upscale_finegrain(prompt, img_path, upscale_factor):
|
53 |
-
"""Ajusta la imagen"""
|
54 |
-
try:
|
55 |
-
client = Client("finegrain/finegrain-image-enhancer", hf_token=HF_TOKEN_UPSCALER)
|
56 |
-
result = client.predict(input_image=handle_file(img_path), prompt=prompt, negative_prompt="", seed=42, upscale_factor=upscale_factor, controlnet_scale=0.6, controlnet_decay=1, condition_scale=6, tile_width=112, tile_height=144, denoise_strength=0.35, num_inference_steps=18, solver="DDIM", api_name="/process")
|
57 |
-
return result[1]
|
58 |
-
except Exception as e:
|
59 |
-
print(f"Error upscale image: {e}")
|
60 |
-
return None
|
61 |
|
62 |
css = """
|
63 |
#col-container{ margin: 0 auto; max-width: 1024px;}
|
|
|
32 |
print(f"Error generating image: {e}")
|
33 |
return None, None
|
34 |
|
35 |
+
def get_upscale_finegrain(prompt, img_path, upscale_factor):
|
36 |
+
try:
|
37 |
+
client = Client("finegrain/finegrain-image-enhancer", hf_token=HF_TOKEN_UPSCALER)
|
38 |
+
result = client.predict(input_image=handle_file(img_path), prompt=prompt, negative_prompt="", seed=42, upscale_factor=upscale_factor, controlnet_scale=0.6, controlnet_decay=1, condition_scale=6, tile_width=112, tile_height=144, denoise_strength=0.35, num_inference_steps=18, solver="DDIM", api_name="/process")
|
39 |
+
return result[1]
|
40 |
+
except Exception as e:
|
41 |
+
print(f"Error upscale image: {e}")
|
42 |
+
return None
|
43 |
+
|
44 |
async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_factor, process_upscale, lora_model, process_lora):
|
|
|
45 |
model = enable_lora(lora_model, basemodel) if process_lora else basemodel
|
46 |
image, seed = await generate_image(prompt, model, "", width, height, scales, steps, seed)
|
47 |
if image is None:
|
|
|
52 |
|
53 |
if process_upscale:
|
54 |
upscale_image = get_upscale_finegrain(prompt, image_path, upscale_factor)
|
55 |
+
upscale_image_path = "upscale_image.jpg"
|
56 |
+
upscale_image.save(upscale_image_path, format="JPEG")
|
57 |
+
return [image_path, upscale_image_path]
|
58 |
else:
|
59 |
+
return [image_path, image_path]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
css = """
|
62 |
#col-container{ margin: 0 auto; max-width: 1024px;}
|