salomonsky commited on
Commit
4dbb52e
verified
1 Parent(s): 227bbda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -23
app.py CHANGED
@@ -1,14 +1,28 @@
1
  import os
2
- import random
3
- import asyncio
4
  import numpy as np
 
5
  from pathlib import Path
6
  from PIL import Image
7
  import streamlit as st
8
- from huggingface_hub import AsyncInferenceClient
 
9
  import streamlit_authenticator as stauth
10
 
11
- st.set_page_config(layout="wide")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  MAX_SEED = np.iinfo(np.int32).max
14
  client = AsyncInferenceClient()
@@ -17,21 +31,6 @@ DATA_PATH.mkdir(exist_ok=True)
17
 
18
  PREDEFINED_SEED = random.randint(0, MAX_SEED)
19
 
20
- credentials = {
21
- "usernames": {
22
- "admin": {
23
- "name": "Admin",
24
- "password": stauth.Hasher(["flux33"]).generate()[0]
25
- }
26
- }
27
- }
28
-
29
- cookie_name = "image_gen"
30
- key = "abcdef"
31
- cookie_expiry_days = 1
32
-
33
- authenticator = stauth.Authenticate(credentials, cookie_name, key, cookie_expiry_days)
34
-
35
  async def generate_image(prompt, width, height, seed):
36
  try:
37
  if seed == -1:
@@ -55,7 +54,7 @@ def save_prompt(prompt_text, seed):
55
  return None
56
 
57
  async def gen(prompt, width, height):
58
- combined_prompt = prompt
59
 
60
  seed = PREDEFINED_SEED
61
  progress_bar = st.progress(0)
@@ -91,9 +90,16 @@ def get_prompts():
91
  return {file.stem.replace("prompt_", ""): file for file in prompt_files}
92
 
93
  def main():
94
- name, authentication_status, username = authenticator.login("Login", "sidebar")
 
 
 
 
95
 
96
  if authentication_status:
 
 
 
97
  st.title("Generador de Im谩genes FLUX")
98
  prompt = st.sidebar.text_input("Descripci贸n de la imagen", max_chars=500)
99
  format_option = st.sidebar.selectbox("Formato", ["9:16", "16:9"])
@@ -145,10 +151,12 @@ def main():
145
  st.success(f"Imagen {idx+1} y su prompt fueron borrados.")
146
  except Exception as e:
147
  st.error(f"Error al borrar la imagen o prompt: {e}")
 
148
  elif authentication_status == False:
149
- st.error("Usuario/Contrase帽a incorrectos")
 
150
  elif authentication_status == None:
151
- st.warning("Por favor, ingrese sus credenciales.")
152
 
153
  if __name__ == "__main__":
154
  main()
 
1
  import os
 
 
2
  import numpy as np
3
+ import random
4
  from pathlib import Path
5
  from PIL import Image
6
  import streamlit as st
7
+ from huggingface_hub import InferenceClient, AsyncInferenceClient
8
+ import asyncio
9
  import streamlit_authenticator as stauth
10
 
11
+ # Definir usuarios y contrase帽as
12
+ names = ["admin"]
13
+ usernames = ["admin"]
14
+ passwords = ["flux33"]
15
+
16
+ # Crear el objeto de autenticaci贸n
17
+ hashed_passwords = stauth.Hasher(passwords).generate()
18
+ authenticator = stauth.Authenticate(
19
+ names,
20
+ usernames,
21
+ hashed_passwords,
22
+ "imagen_gen_auth",
23
+ "abcdef", # Llave para la cookie
24
+ cookie_expiry_days=30
25
+ )
26
 
27
  MAX_SEED = np.iinfo(np.int32).max
28
  client = AsyncInferenceClient()
 
31
 
32
  PREDEFINED_SEED = random.randint(0, MAX_SEED)
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  async def generate_image(prompt, width, height, seed):
35
  try:
36
  if seed == -1:
 
54
  return None
55
 
56
  async def gen(prompt, width, height):
57
+ combined_prompt = prompt
58
 
59
  seed = PREDEFINED_SEED
60
  progress_bar = st.progress(0)
 
90
  return {file.stem.replace("prompt_", ""): file for file in prompt_files}
91
 
92
  def main():
93
+ # Configuraci贸n de p谩gina
94
+ st.set_page_config(layout="wide")
95
+
96
+ # Autenticaci贸n
97
+ name, authentication_status, username = authenticator.login("Login", "main")
98
 
99
  if authentication_status:
100
+ st.success(f"Bienvenido {name}")
101
+
102
+ # Aqu铆 comienza la l贸gica de generaci贸n de im谩genes despu茅s de autenticarse
103
  st.title("Generador de Im谩genes FLUX")
104
  prompt = st.sidebar.text_input("Descripci贸n de la imagen", max_chars=500)
105
  format_option = st.sidebar.selectbox("Formato", ["9:16", "16:9"])
 
151
  st.success(f"Imagen {idx+1} y su prompt fueron borrados.")
152
  except Exception as e:
153
  st.error(f"Error al borrar la imagen o prompt: {e}")
154
+
155
  elif authentication_status == False:
156
+ st.error("Nombre de usuario/contrase帽a incorrectos")
157
+
158
  elif authentication_status == None:
159
+ st.warning("Por favor, ingrese sus credenciales")
160
 
161
  if __name__ == "__main__":
162
  main()