Spaces:
Running
Running
salomonsky
commited on
Commit
•
99a5876
1
Parent(s):
077426a
Update app.py
Browse files
app.py
CHANGED
@@ -60,49 +60,18 @@ def save_prompt(prompt_text, seed):
|
|
60 |
st.error(f"Error al guardar el prompt: {e}")
|
61 |
return None
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
if process_enhancer:
|
68 |
-
improved_prompt = await improve_prompt(prompt)
|
69 |
-
combined_prompt = f"{prompt} {improved_prompt}"
|
70 |
-
|
71 |
-
if seed == -1:
|
72 |
-
seed = random.randint(0, MAX_SEED)
|
73 |
-
seed = int(seed)
|
74 |
-
progress_bar = st.progress(0)
|
75 |
-
image, seed = await generate_image(combined_prompt, model, width, height, scales, steps, seed)
|
76 |
-
progress_bar.progress(50)
|
77 |
-
|
78 |
-
if isinstance(image, str) and image.startswith("Error"):
|
79 |
-
progress_bar.empty()
|
80 |
-
return [image, None, combined_prompt]
|
81 |
-
|
82 |
-
image_path = save_image(image, seed)
|
83 |
-
prompt_file_path = save_prompt(combined_prompt, seed)
|
84 |
-
|
85 |
-
if process_upscale:
|
86 |
-
upscale_image_path = get_upscale_finegrain(combined_prompt, image_path, upscale_factor)
|
87 |
-
if upscale_image_path:
|
88 |
-
upscale_image = Image.open(upscale_image_path)
|
89 |
-
upscale_image.save(DATA_PATH / f"upscale_image_{seed}.jpg", format="JPEG")
|
90 |
-
progress_bar.progress(100)
|
91 |
-
image_path.unlink()
|
92 |
-
return [str(DATA_PATH / f"upscale_image_{seed}.jpg"), str(prompt_file_path)]
|
93 |
-
else:
|
94 |
-
progress_bar.empty()
|
95 |
-
return [str(image_path), str(prompt_file_path)]
|
96 |
-
else:
|
97 |
-
progress_bar.progress(100)
|
98 |
-
return [str(image_path), str(prompt_file_path)]
|
99 |
|
100 |
async def improve_prompt(prompt, language):
|
101 |
try:
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
106 |
|
107 |
formatted_prompt = f"{prompt}: {instruction}"
|
108 |
response = llm_client.text_generation(formatted_prompt, max_new_tokens=300)
|
@@ -115,7 +84,6 @@ async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_fac
|
|
115 |
model = enable_lora(lora_model, basemodel) if process_lora else basemodel
|
116 |
combined_prompt = prompt # Usar el prompt original por defecto
|
117 |
|
118 |
-
# Mejorar el prompt si el checkbox está activado y según el idioma seleccionado
|
119 |
if process_enhancer:
|
120 |
improved_prompt = await improve_prompt(prompt, prompt_language)
|
121 |
combined_prompt = f"{prompt} {improved_prompt}"
|
@@ -149,14 +117,13 @@ async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_fac
|
|
149 |
progress_bar.progress(100)
|
150 |
return [str(image_path), str(prompt_file_path)]
|
151 |
|
152 |
-
|
153 |
def main():
|
154 |
st.set_page_config(layout="wide")
|
155 |
st.title("FLUX with enhancer and upscaler with LORA model training")
|
156 |
|
157 |
prompt = st.sidebar.text_input("Descripción de la imagen", max_chars=200)
|
158 |
process_enhancer = st.sidebar.checkbox("Mejorar Prompt", value=True)
|
159 |
-
prompt_language = st.sidebar.selectbox("Idioma para mejorar el prompt", ["English", "Spanish"])
|
160 |
basemodel = st.sidebar.selectbox("Modelo Base", ["black-forest-labs/FLUX.1-schnell", "black-forest-labs/FLUX.1-DEV"])
|
161 |
lora_model = st.sidebar.selectbox("LORA Realismo", ["Shakker-Labs/FLUX.1-dev-LoRA-add-details", "XLabs-AI/flux-RealismLora"])
|
162 |
format_option = st.sidebar.selectbox("Formato", ["9:16", "16:9"])
|
@@ -194,4 +161,7 @@ def main():
|
|
194 |
else:
|
195 |
st.write("El archivo del prompt no está disponible.")
|
196 |
else:
|
197 |
-
st.error("No se pudo generar la imagen.")
|
|
|
|
|
|
|
|
60 |
st.error(f"Error al guardar el prompt: {e}")
|
61 |
return None
|
62 |
|
63 |
+
def save_image(image, seed):
|
64 |
+
image_path = DATA_PATH / f"generated_image_{seed}.jpg"
|
65 |
+
image.save(image_path)
|
66 |
+
return image_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
async def improve_prompt(prompt, language):
|
69 |
try:
|
70 |
+
instruction = (
|
71 |
+
"With this idea, describe in English a detailed txt2img prompt in 500 characters at most, add illumination, atmosphere, cinematic elements, and characters..."
|
72 |
+
if language == "English"
|
73 |
+
else "Con esta idea, describe en español un prompt detallado de txt2img en un máximo de 500 caracteres, añadiendo iluminación, atmósfera, elementos cinematográficos y personajes..."
|
74 |
+
)
|
75 |
|
76 |
formatted_prompt = f"{prompt}: {instruction}"
|
77 |
response = llm_client.text_generation(formatted_prompt, max_new_tokens=300)
|
|
|
84 |
model = enable_lora(lora_model, basemodel) if process_lora else basemodel
|
85 |
combined_prompt = prompt # Usar el prompt original por defecto
|
86 |
|
|
|
87 |
if process_enhancer:
|
88 |
improved_prompt = await improve_prompt(prompt, prompt_language)
|
89 |
combined_prompt = f"{prompt} {improved_prompt}"
|
|
|
117 |
progress_bar.progress(100)
|
118 |
return [str(image_path), str(prompt_file_path)]
|
119 |
|
|
|
120 |
def main():
|
121 |
st.set_page_config(layout="wide")
|
122 |
st.title("FLUX with enhancer and upscaler with LORA model training")
|
123 |
|
124 |
prompt = st.sidebar.text_input("Descripción de la imagen", max_chars=200)
|
125 |
process_enhancer = st.sidebar.checkbox("Mejorar Prompt", value=True)
|
126 |
+
prompt_language = st.sidebar.selectbox("Idioma para mejorar el prompt", ["English", "Spanish"])
|
127 |
basemodel = st.sidebar.selectbox("Modelo Base", ["black-forest-labs/FLUX.1-schnell", "black-forest-labs/FLUX.1-DEV"])
|
128 |
lora_model = st.sidebar.selectbox("LORA Realismo", ["Shakker-Labs/FLUX.1-dev-LoRA-add-details", "XLabs-AI/flux-RealismLora"])
|
129 |
format_option = st.sidebar.selectbox("Formato", ["9:16", "16:9"])
|
|
|
161 |
else:
|
162 |
st.write("El archivo del prompt no está disponible.")
|
163 |
else:
|
164 |
+
st.error("No se pudo generar la imagen.")
|
165 |
+
|
166 |
+
if __name__ == "__main__":
|
167 |
+
main()
|