Update app.py
Browse files
app.py
CHANGED
|
@@ -12,19 +12,14 @@ from gradio_client import Client, handle_file
|
|
| 12 |
from huggingface_hub import login
|
| 13 |
from gradio_imageslider import ImageSlider
|
| 14 |
|
| 15 |
-
|
| 16 |
MAX_SEED = np.iinfo(np.int32).max
|
| 17 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 18 |
HF_TOKEN_UPSCALER = os.environ.get("HF_TOKEN_UPSCALER")
|
| 19 |
|
| 20 |
-
|
| 21 |
def enable_lora(lora_add, basemodel):
|
| 22 |
-
"""Habilita o deshabilita LoRA seg煤n la opci贸n seleccionada"""
|
| 23 |
return basemodel if not lora_add else lora_add
|
| 24 |
|
| 25 |
-
|
| 26 |
async def generate_image(prompt, model, lora_word, width, height, scales, steps, seed):
|
| 27 |
-
"""Genera una imagen utilizando el modelo seleccionado"""
|
| 28 |
try:
|
| 29 |
if seed == -1:
|
| 30 |
seed = random.randint(0, MAX_SEED)
|
|
@@ -37,9 +32,7 @@ async def generate_image(prompt, model, lora_word, width, height, scales, steps,
|
|
| 37 |
print(f"Error generando imagen: {e}")
|
| 38 |
return None, None
|
| 39 |
|
| 40 |
-
|
| 41 |
def get_upscale_finegrain(prompt, img_path, upscale_factor):
|
| 42 |
-
"""Escala una imagen utilizando FineGrain"""
|
| 43 |
try:
|
| 44 |
client = Client("finegrain/finegrain-image-enhancer", hf_token=HF_TOKEN_UPSCALER)
|
| 45 |
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")
|
|
@@ -48,9 +41,7 @@ def get_upscale_finegrain(prompt, img_path, upscale_factor):
|
|
| 48 |
print(f"Error escalando imagen: {e}")
|
| 49 |
return None
|
| 50 |
|
| 51 |
-
|
| 52 |
async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_factor, process_upscale, lora_model, process_lora):
|
| 53 |
-
"""Funci贸n principal que genera y escala la imagen"""
|
| 54 |
model = enable_lora(lora_model, basemodel) if process_lora else basemodel
|
| 55 |
image, seed = await generate_image(prompt, model, "", width, height, scales, steps, seed)
|
| 56 |
if image is None:
|
|
@@ -71,12 +62,10 @@ async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_fac
|
|
| 71 |
else:
|
| 72 |
return [image_path, image_path]
|
| 73 |
|
| 74 |
-
|
| 75 |
css = """
|
| 76 |
#col-container{ margin: 0 auto; max-width: 1024px;}
|
| 77 |
"""
|
| 78 |
|
| 79 |
-
|
| 80 |
with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
|
| 81 |
with gr.Column(elem_id="col-container"):
|
| 82 |
with gr.Row():
|
|
|
|
| 12 |
from huggingface_hub import login
|
| 13 |
from gradio_imageslider import ImageSlider
|
| 14 |
|
|
|
|
| 15 |
MAX_SEED = np.iinfo(np.int32).max
|
| 16 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 17 |
HF_TOKEN_UPSCALER = os.environ.get("HF_TOKEN_UPSCALER")
|
| 18 |
|
|
|
|
| 19 |
def enable_lora(lora_add, basemodel):
|
|
|
|
| 20 |
return basemodel if not lora_add else lora_add
|
| 21 |
|
|
|
|
| 22 |
async def generate_image(prompt, model, lora_word, width, height, scales, steps, seed):
|
|
|
|
| 23 |
try:
|
| 24 |
if seed == -1:
|
| 25 |
seed = random.randint(0, MAX_SEED)
|
|
|
|
| 32 |
print(f"Error generando imagen: {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")
|
|
|
|
| 41 |
print(f"Error escalando imagen: {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:
|
|
|
|
| 62 |
else:
|
| 63 |
return [image_path, image_path]
|
| 64 |
|
|
|
|
| 65 |
css = """
|
| 66 |
#col-container{ margin: 0 auto; max-width: 1024px;}
|
| 67 |
"""
|
| 68 |
|
|
|
|
| 69 |
with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
|
| 70 |
with gr.Column(elem_id="col-container"):
|
| 71 |
with gr.Row():
|