Spaces:
Running
Running
salomonsky
commited on
Commit
•
53635c2
1
Parent(s):
e7fe446
Update app.py
Browse files
app.py
CHANGED
@@ -78,7 +78,7 @@ async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_fac
|
|
78 |
upscale_image.save(DATA_PATH / f"upscale_image_{seed}.jpg", format="JPEG")
|
79 |
progress_bar.progress(100)
|
80 |
image_path.unlink()
|
81 |
-
return [str(DATA_PATH / f"upscale_image_{seed}.jpg"), str(prompt_file_path)]
|
82 |
else:
|
83 |
progress_bar.empty()
|
84 |
return [str(image_path), str(prompt_file_path)]
|
@@ -124,71 +124,75 @@ def delete_image(image_path):
|
|
124 |
except Exception as e:
|
125 |
st.error(f"Error al borrar la imagen: {e}")
|
126 |
|
127 |
-
|
128 |
-
st.
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
if
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
|
|
|
|
|
|
|
|
|
78 |
upscale_image.save(DATA_PATH / f"upscale_image_{seed}.jpg", format="JPEG")
|
79 |
progress_bar.progress(100)
|
80 |
image_path.unlink()
|
81 |
+
return [str(DATA_PATH / f"upscale_image_{seed}.jpg"), str(prompt_file_path")]
|
82 |
else:
|
83 |
progress_bar.empty()
|
84 |
return [str(image_path), str(prompt_file_path)]
|
|
|
124 |
except Exception as e:
|
125 |
st.error(f"Error al borrar la imagen: {e}")
|
126 |
|
127 |
+
def main():
|
128 |
+
st.set_page_config(layout="wide")
|
129 |
+
st.title("Generador de Imágenes FLUX")
|
130 |
+
prompt = st.sidebar.text_input("Descripción de la imagen", max_chars=200)
|
131 |
+
|
132 |
+
with st.sidebar.expander("Opciones avanzadas", expanded=False):
|
133 |
+
basemodel = st.selectbox("Modelo Base", ["black-forest-labs/FLUX.1-schnell", "black-forest-labs/FLUX.1-DEV"])
|
134 |
+
lora_model = st.selectbox("LORA Realismo", ["Shakker-Labs/FLUX.1-dev-LoRA-add-details", "XLabs-AI/flux-RealismLora"])
|
135 |
+
format_option = st.selectbox("Formato", ["9:16", "16:9"])
|
136 |
+
process_lora = st.checkbox("Procesar LORA")
|
137 |
+
process_upscale = st.checkbox("Procesar Escalador")
|
138 |
+
upscale_factor = st.selectbox("Factor de Escala", [2, 4, 8], index=0)
|
139 |
+
scales = st.slider("Escalado", 1, 20, 10)
|
140 |
+
steps = st.slider("Pasos", 1, 100, 20)
|
141 |
+
seed = st.number_input("Semilla", value=-1)
|
142 |
+
|
143 |
+
if format_option == "9:16":
|
144 |
+
width = 720
|
145 |
+
height = 1280
|
146 |
+
else:
|
147 |
+
width = 1280
|
148 |
+
height = 720
|
149 |
+
|
150 |
+
if st.sidebar.button("Generar Imagen"):
|
151 |
+
with st.spinner("Mejorando y generando imagen..."):
|
152 |
+
improved_prompt = asyncio.run(improve_prompt(prompt))
|
153 |
+
st.session_state.improved_prompt = improved_prompt
|
154 |
+
prompt_to_use = st.session_state.get('improved_prompt', prompt)
|
155 |
+
result = asyncio.run(gen(prompt_to_use, basemodel, width, height, scales, steps, seed, upscale_factor, process_upscale, lora_model, process_lora))
|
156 |
+
|
157 |
+
image_paths = result[0]
|
158 |
+
prompt_file = result[1]
|
159 |
+
|
160 |
+
st.write(f"Image paths: {image_paths}")
|
161 |
+
|
162 |
+
if image_paths:
|
163 |
+
if Path(image_paths).exists():
|
164 |
+
st.image(image_paths, caption="Imagen Generada")
|
165 |
+
else:
|
166 |
+
st.error("El archivo de imagen no existe.")
|
167 |
+
|
168 |
+
if prompt_file and Path(prompt_file).exists():
|
169 |
+
prompt_text = Path(prompt_file).read_text()
|
170 |
+
st.write(f"Prompt utilizado: {prompt_text}")
|
171 |
+
else:
|
172 |
+
st.write("El archivo del prompt no está disponible.")
|
173 |
+
|
174 |
+
files, usage = get_storage()
|
175 |
+
st.text(usage)
|
176 |
+
cols = st.columns(6)
|
177 |
+
prompts = get_prompts()
|
178 |
+
|
179 |
+
for idx, file in enumerate(files):
|
180 |
+
with cols[idx % 6]:
|
181 |
+
image = Image.open(file)
|
182 |
+
prompt_file = prompts.get(Path(file).stem.replace("image_", ""), None)
|
183 |
+
prompt_text = Path(prompt_file).read_text() if prompt_file else "No disponible"
|
184 |
+
|
185 |
+
st.image(image, caption=f"Imagen {idx+1}")
|
186 |
+
st.write(f"Prompt: {prompt_text}")
|
187 |
+
|
188 |
+
if st.button(f"Borrar Imagen {idx+1}", key=f"delete_{idx}"):
|
189 |
+
try:
|
190 |
+
os.remove(file)
|
191 |
+
if prompt_file:
|
192 |
+
os.remove(prompt_file)
|
193 |
+
st.success(f"Imagen {idx+1} y su prompt fueron borrados.")
|
194 |
+
except Exception as e:
|
195 |
+
st.error(f"Error al borrar la imagen o prompt: {e}")
|
196 |
+
|
197 |
+
if __name__ == "__main__":
|
198 |
+
main()
|