Spaces:
Running
Running
salomonsky
commited on
Commit
•
165b2f6
1
Parent(s):
79f1585
Update app.py
Browse files
app.py
CHANGED
@@ -12,8 +12,6 @@ from gradio_client import Client, handle_file
|
|
12 |
from huggingface_hub import login
|
13 |
from gradio_imageslider import ImageSlider
|
14 |
|
15 |
-
|
16 |
-
# Configuración inicial
|
17 |
translator = Translator()
|
18 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
19 |
basemodel = "black-forest-labs/FLUX.1-schnell"
|
@@ -21,12 +19,9 @@ MAX_SEED = np.iinfo(np.int32).max
|
|
21 |
CSS = "footer { visibility: hidden; }"
|
22 |
JS = "function () { gradioURL = window.location.href; if (!gradioURL.endsWith('?__theme=dark')) { window.location.replace(gradioURL + '?__theme=dark'); } }"
|
23 |
|
24 |
-
# Función para habilitar LoRA
|
25 |
def enable_lora(lora_add):
|
26 |
return basemodel if not lora_add else lora_add
|
27 |
|
28 |
-
|
29 |
-
# Función asíncrona para generar imágenes
|
30 |
async def generate_image(prompt, model, lora_word, width, height, scales, steps, seed):
|
31 |
try:
|
32 |
if seed == -1:
|
@@ -39,8 +34,6 @@ async def generate_image(prompt, model, lora_word, width, height, scales, steps,
|
|
39 |
except Exception as e:
|
40 |
raise gr.Error(f"Error en {e}")
|
41 |
|
42 |
-
|
43 |
-
# Función asíncrona para generar imágenes y aplicar upscale
|
44 |
async def gen(prompt, lora_add, lora_word, width, height, scales, steps, seed, upscale_factor, process_upscale):
|
45 |
model = enable_lora(lora_add)
|
46 |
image, seed = await generate_image(prompt, model, lora_word, width, height, scales, steps, seed)
|
@@ -54,15 +47,11 @@ async def gen(prompt, lora_add, lora_word, width, height, scales, steps, seed, u
|
|
54 |
|
55 |
return [image_path, upscale_image]
|
56 |
|
57 |
-
|
58 |
-
# Función para aplicar upscale con Finegrain
|
59 |
def get_upscale_finegrain(prompt, img_path, upscale_factor):
|
60 |
client = Client("finegrain/finegrain-image-enhancer")
|
61 |
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")
|
62 |
return result[1]
|
63 |
|
64 |
-
|
65 |
-
# Configuración de CSS
|
66 |
css = """
|
67 |
#col-container{
|
68 |
margin: 0 auto;
|
@@ -72,8 +61,7 @@ css = """
|
|
72 |
|
73 |
with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
|
74 |
with gr.Column(elem_id="col-container"):
|
75 |
-
gr.Markdown("
|
76 |
-
gr.Markdown("Step 1: Generate image with FLUX schnell; Step 2: UpScale with Finegrain Image-Enhancer")
|
77 |
with gr.Group():
|
78 |
prompt = gr.Textbox(label="Prompt")
|
79 |
with gr.Row():
|
@@ -100,6 +88,4 @@ with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
|
|
100 |
outputs=[output_res]
|
101 |
)
|
102 |
|
103 |
-
|
104 |
-
# Iniciar la aplicación
|
105 |
demo.launch()
|
|
|
12 |
from huggingface_hub import login
|
13 |
from gradio_imageslider import ImageSlider
|
14 |
|
|
|
|
|
15 |
translator = Translator()
|
16 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
17 |
basemodel = "black-forest-labs/FLUX.1-schnell"
|
|
|
19 |
CSS = "footer { visibility: hidden; }"
|
20 |
JS = "function () { gradioURL = window.location.href; if (!gradioURL.endsWith('?__theme=dark')) { window.location.replace(gradioURL + '?__theme=dark'); } }"
|
21 |
|
|
|
22 |
def enable_lora(lora_add):
|
23 |
return basemodel if not lora_add else lora_add
|
24 |
|
|
|
|
|
25 |
async def generate_image(prompt, model, lora_word, width, height, scales, steps, seed):
|
26 |
try:
|
27 |
if seed == -1:
|
|
|
34 |
except Exception as e:
|
35 |
raise gr.Error(f"Error en {e}")
|
36 |
|
|
|
|
|
37 |
async def gen(prompt, lora_add, lora_word, width, height, scales, steps, seed, upscale_factor, process_upscale):
|
38 |
model = enable_lora(lora_add)
|
39 |
image, seed = await generate_image(prompt, model, lora_word, width, height, scales, steps, seed)
|
|
|
47 |
|
48 |
return [image_path, upscale_image]
|
49 |
|
|
|
|
|
50 |
def get_upscale_finegrain(prompt, img_path, upscale_factor):
|
51 |
client = Client("finegrain/finegrain-image-enhancer")
|
52 |
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")
|
53 |
return result[1]
|
54 |
|
|
|
|
|
55 |
css = """
|
56 |
#col-container{
|
57 |
margin: 0 auto;
|
|
|
61 |
|
62 |
with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
|
63 |
with gr.Column(elem_id="col-container"):
|
64 |
+
gr.Markdown("Flux Upscaled +LORA")
|
|
|
65 |
with gr.Group():
|
66 |
prompt = gr.Textbox(label="Prompt")
|
67 |
with gr.Row():
|
|
|
88 |
outputs=[output_res]
|
89 |
)
|
90 |
|
|
|
|
|
91 |
demo.launch()
|