Spaces:
Running
Running
salomonsky
commited on
Commit
•
27e4a6a
1
Parent(s):
c79e0ac
Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,9 @@ import os
|
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
import random
|
5 |
-
from
|
6 |
from PIL import Image
|
|
|
7 |
from gradio_client import Client, handle_file
|
8 |
from gradio_imageslider import ImageSlider
|
9 |
|
@@ -13,6 +14,10 @@ HF_TOKEN_UPSCALER = os.environ.get("HF_TOKEN_UPSCALER")
|
|
13 |
client = AsyncInferenceClient()
|
14 |
llm_client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
15 |
|
|
|
|
|
|
|
|
|
16 |
def enable_lora(lora_add, basemodel):
|
17 |
return basemodel if not lora_add else lora_add
|
18 |
|
@@ -57,15 +62,15 @@ async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_fac
|
|
57 |
if isinstance(image, str) and image.startswith("Error"):
|
58 |
return [image, None]
|
59 |
|
60 |
-
image_path = "
|
61 |
image.save(image_path, format="JPEG")
|
62 |
|
63 |
if process_upscale:
|
64 |
upscale_image_path = get_upscale_finegrain(combined_prompt, image_path, upscale_factor)
|
65 |
if upscale_image_path:
|
66 |
upscale_image = Image.open(upscale_image_path)
|
67 |
-
upscale_image.save("
|
68 |
-
return [image_path, "
|
69 |
else:
|
70 |
return [image_path, image_path]
|
71 |
else:
|
@@ -82,6 +87,18 @@ async def improve_prompt(prompt):
|
|
82 |
except Exception as e:
|
83 |
return f"Error mejorando el prompt: {e}"
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
css = """
|
86 |
#col-container{ margin: 0 auto; max-width: 1024px;}
|
87 |
"""
|
@@ -90,9 +107,9 @@ with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
|
|
90 |
with gr.Column(elem_id="col-container"):
|
91 |
with gr.Row():
|
92 |
with gr.Column(scale=3):
|
93 |
-
output_res = ImageSlider(label="
|
94 |
with gr.Column(scale=2):
|
95 |
-
prompt = gr.Textbox(label="Descripción de
|
96 |
basemodel_choice = gr.Dropdown(
|
97 |
label="Modelo",
|
98 |
choices=["black-forest-labs/FLUX.1-schnell", "black-forest-labs/FLUX.1-DEV"],
|
@@ -107,7 +124,7 @@ with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
|
|
107 |
process_lora = gr.Checkbox(label="Procesar LORA")
|
108 |
process_upscale = gr.Checkbox(label="Procesar Escalador")
|
109 |
improved_prompt = gr.Textbox(label="Prompt Mejorado", interactive=False)
|
110 |
-
improve_btn = gr.Button("
|
111 |
improve_btn.click(fn=improve_prompt, inputs=[prompt], outputs=improved_prompt)
|
112 |
with gr.Accordion(label="Opciones Avanzadas", open=False):
|
113 |
width = gr.Slider(label="Ancho", minimum=512, maximum=1280, step=8, value=1280)
|
@@ -122,4 +139,10 @@ with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
|
|
122 |
inputs=[prompt, basemodel_choice, width, height, scales, steps, seed, upscale_factor, process_upscale, lora_model_choice, process_lora],
|
123 |
outputs=output_res
|
124 |
)
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
import random
|
5 |
+
from pathlib import Path
|
6 |
from PIL import Image
|
7 |
+
from huggingface_hub import AsyncInferenceClient, InferenceClient
|
8 |
from gradio_client import Client, handle_file
|
9 |
from gradio_imageslider import ImageSlider
|
10 |
|
|
|
14 |
client = AsyncInferenceClient()
|
15 |
llm_client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
16 |
|
17 |
+
# Directorio de almacenamiento de imágenes
|
18 |
+
DATA_PATH = Path("./data")
|
19 |
+
DATA_PATH.mkdir(exist_ok=True) # Asegura que el directorio exista
|
20 |
+
|
21 |
def enable_lora(lora_add, basemodel):
|
22 |
return basemodel if not lora_add else lora_add
|
23 |
|
|
|
62 |
if isinstance(image, str) and image.startswith("Error"):
|
63 |
return [image, None]
|
64 |
|
65 |
+
image_path = DATA_PATH / f"image_{seed}.jpg"
|
66 |
image.save(image_path, format="JPEG")
|
67 |
|
68 |
if process_upscale:
|
69 |
upscale_image_path = get_upscale_finegrain(combined_prompt, image_path, upscale_factor)
|
70 |
if upscale_image_path:
|
71 |
upscale_image = Image.open(upscale_image_path)
|
72 |
+
upscale_image.save(DATA_PATH / f"upscale_image_{seed}.jpg", format="JPEG")
|
73 |
+
return [image_path, DATA_PATH / f"upscale_image_{seed}.jpg"]
|
74 |
else:
|
75 |
return [image_path, image_path]
|
76 |
else:
|
|
|
87 |
except Exception as e:
|
88 |
return f"Error mejorando el prompt: {e}"
|
89 |
|
90 |
+
def get_storage():
|
91 |
+
files = [
|
92 |
+
{
|
93 |
+
"name": str(file.resolve()),
|
94 |
+
"size": file.stat().st_size,
|
95 |
+
}
|
96 |
+
for file in DATA_PATH.glob("*.jpg")
|
97 |
+
if file.is_file()
|
98 |
+
]
|
99 |
+
usage = sum([f['size'] for f in files])
|
100 |
+
return [file["name"] for file in files], f"Uso total: {usage/(1024.0 ** 3):.3f}GB"
|
101 |
+
|
102 |
css = """
|
103 |
#col-container{ margin: 0 auto; max-width: 1024px;}
|
104 |
"""
|
|
|
107 |
with gr.Column(elem_id="col-container"):
|
108 |
with gr.Row():
|
109 |
with gr.Column(scale=3):
|
110 |
+
output_res = ImageSlider(label="Generadas / Escaladas")
|
111 |
with gr.Column(scale=2):
|
112 |
+
prompt = gr.Textbox(label="Descripción de imagen")
|
113 |
basemodel_choice = gr.Dropdown(
|
114 |
label="Modelo",
|
115 |
choices=["black-forest-labs/FLUX.1-schnell", "black-forest-labs/FLUX.1-DEV"],
|
|
|
124 |
process_lora = gr.Checkbox(label="Procesar LORA")
|
125 |
process_upscale = gr.Checkbox(label="Procesar Escalador")
|
126 |
improved_prompt = gr.Textbox(label="Prompt Mejorado", interactive=False)
|
127 |
+
improve_btn = gr.Button("Mejorar prompt")
|
128 |
improve_btn.click(fn=improve_prompt, inputs=[prompt], outputs=improved_prompt)
|
129 |
with gr.Accordion(label="Opciones Avanzadas", open=False):
|
130 |
width = gr.Slider(label="Ancho", minimum=512, maximum=1280, step=8, value=1280)
|
|
|
139 |
inputs=[prompt, basemodel_choice, width, height, scales, steps, seed, upscale_factor, process_upscale, lora_model_choice, process_lora],
|
140 |
outputs=output_res
|
141 |
)
|
142 |
+
with gr.Row():
|
143 |
+
with gr.Column():
|
144 |
+
file_list = gr.Gallery(label="Imágenes Guardadas") # Usar Gallery en lugar de Files
|
145 |
+
storage_info = gr.Text(label="Uso de Almacenamiento")
|
146 |
+
refresh_btn = gr.Button("Actualizar Galería")
|
147 |
+
refresh_btn.click(fn=get_storage, inputs=None, outputs=[file_list, storage_info])
|
148 |
+
demo.launch(allowed_paths=[str(DATA_PATH)])
|