salomonsky commited on
Commit
a63b304
1 Parent(s): 3d30033

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -33
app.py CHANGED
@@ -7,9 +7,6 @@ import os
7
  import random
8
  import numpy as np
9
  import yaml
10
- import requests
11
-
12
- HUGGINGFACE_API = os.environ.get("HF_TOKEN")
13
 
14
  try:
15
  with open("config.yaml", "r") as file:
@@ -27,28 +24,20 @@ DATA_PATH.mkdir(exist_ok=True)
27
  def authenticate_user(username, password):
28
  return username == credentials["username"] and password == credentials["password"]
29
 
30
- async def gen(prompts, width, height, model_name, num_variants, prompt_checkbox):
31
- headers = {"Authorization": f"Bearer {HUGGINGFACE_API}"}
32
-
33
- for prompt in prompts:
34
- payload = {
35
- "inputs": prompt,
36
- "parameters": {
37
- "width": width,
38
- "height": height,
39
- "num_inference_steps": 50,
40
- "guidance_scale": 7.5
41
- }
42
- }
43
-
44
- url = f"https://api-inference.huggingface.co/models/{model_name}"
45
- response = requests.post(url, headers=headers, json=payload)
46
-
47
- if response.status_code != 200:
48
- raise Exception(f"Error: {response.status_code}, {response.text}")
49
-
50
- return response.json()
51
-
52
  def list_saved_images():
53
  return sorted(DATA_PATH.glob("*.jpg"), key=os.path.getmtime, reverse=True)
54
 
@@ -154,11 +143,9 @@ async def main():
154
 
155
  st.title("Flux + Multiple Images")
156
  prompt = st.sidebar.text_area("Descripción de la imagen", height=150, max_chars=500)
157
- style_option = st.sidebar.selectbox("Selecciona un estilo", ["realistic", "photorealistic", "illustration", "cartoon", "comic", "imaginative", "abstract"])
158
- prompt_with_style = f"{prompt}, {style_option} style"
159
  format_option = st.sidebar.selectbox("Formato", ["9:16", "16:9", "1:1"])
160
  prompt_checkbox = st.sidebar.checkbox("Prompt Enhancer")
161
- model_option = st.sidebar.selectbox("Modelo", ["black-forest-labs/FLUX.1-schnell", "black-forest-labs/FLUX.1-dev", "XLabs-AI/flux-RealismLora"])
162
  width, height = (360, 640) if format_option == "9:16" else (640, 360) if format_option == "16:9" else (640, 640)
163
 
164
  if prompt_checkbox:
@@ -166,18 +153,16 @@ async def main():
166
  else:
167
  num_variants = 1
168
 
169
- model_name = model_option
170
-
171
  if prompt_checkbox:
172
  with st.spinner("Generando prompts mejorados..."):
173
- prompts = await generate_variations(prompt_with_style, num_variants, True)
174
  else:
175
- prompts = [prompt_with_style]
176
 
177
  if st.sidebar.button("Generar Imágenes"):
178
  with st.spinner("Generando imágenes..."):
179
  try:
180
- results = await gen(prompts, width, height, model_name, num_variants, prompt_checkbox)
181
  st.session_state['generated_image_paths'] = results
182
  for result in results:
183
  st.image(result, caption="Imagen Generada")
 
7
  import random
8
  import numpy as np
9
  import yaml
 
 
 
10
 
11
  try:
12
  with open("config.yaml", "r") as file:
 
24
  def authenticate_user(username, password):
25
  return username == credentials["username"] and password == credentials["password"]
26
 
27
+ async def gen(prompts, width, height, model_name, num_variants=1, use_enhanced=True):
28
+ images = []
29
+ try:
30
+ for idx, prompt in enumerate(prompts):
31
+ seed = random.randint(0, MAX_SEED)
32
+ image, seed = await generate_image(prompt, width, height, seed, model_name)
33
+ image_path = save_image(image, f"generated_image_{seed}.jpg", prompt)
34
+ if image_path:
35
+ st.success(f"Imagen {idx + 1} generada")
36
+ images.append(str(image_path))
37
+ except Exception as e:
38
+ st.error(f"Error al generar imágenes: {e}")
39
+ return images
40
+
 
 
 
 
 
 
 
 
41
  def list_saved_images():
42
  return sorted(DATA_PATH.glob("*.jpg"), key=os.path.getmtime, reverse=True)
43
 
 
143
 
144
  st.title("Flux + Multiple Images")
145
  prompt = st.sidebar.text_area("Descripción de la imagen", height=150, max_chars=500)
 
 
146
  format_option = st.sidebar.selectbox("Formato", ["9:16", "16:9", "1:1"])
147
  prompt_checkbox = st.sidebar.checkbox("Prompt Enhancer")
148
+ model_option = st.sidebar.selectbox("Modelo", ["black-forest-labs/FLUX.1-schnell", "black-forest-labs/FLUX.1-dev", "enhanceaiteam/Flux-Uncensored-V2", "enhanceaiteam/Flux-Uncensored"])
149
  width, height = (360, 640) if format_option == "9:16" else (640, 360) if format_option == "16:9" else (640, 640)
150
 
151
  if prompt_checkbox:
 
153
  else:
154
  num_variants = 1
155
 
 
 
156
  if prompt_checkbox:
157
  with st.spinner("Generando prompts mejorados..."):
158
+ prompts = await generate_variations(prompt, num_variants, True)
159
  else:
160
+ prompts = [prompt]
161
 
162
  if st.sidebar.button("Generar Imágenes"):
163
  with st.spinner("Generando imágenes..."):
164
  try:
165
+ results = await gen(prompts, width, height, model_option, num_variants, prompt_checkbox)
166
  st.session_state['generated_image_paths'] = results
167
  for result in results:
168
  st.image(result, caption="Imagen Generada")