Spaces:
Running
Running
salomonsky
commited on
Commit
•
3e02b14
1
Parent(s):
9940a0d
Update app.py
Browse files
app.py
CHANGED
@@ -3,57 +3,39 @@ from huggingface_hub import InferenceClient
|
|
3 |
from PIL import Image
|
4 |
import io
|
5 |
|
6 |
-
#
|
7 |
-
hf_token = st.secrets["HF_TOKEN"]
|
8 |
-
client = InferenceClient(token=hf_token)
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
|
13 |
-
# Configura la UI en la barra lateral
|
14 |
-
st.sidebar.title("Generación de Imágenes img2img con Flux")
|
15 |
prompt = st.sidebar.text_input("Escribe tu prompt:", value="")
|
16 |
|
17 |
-
|
18 |
-
strength = st.sidebar.slider("Nivel de transformación (strength):", 0.0, 1.0, 0.75)
|
19 |
-
|
20 |
-
# Input de imagen opcional
|
21 |
-
uploaded_file = st.sidebar.file_uploader("Sube una imagen base (opcional)", type=["jpg", "png"])
|
22 |
|
23 |
-
|
24 |
-
if st.sidebar.button("Generar Imagen"):
|
25 |
try:
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
# Manejar respuesta y mostrar la imagen generada
|
47 |
-
image_data = io.BytesIO(response.content)
|
48 |
-
generated_image = Image.open(image_data)
|
49 |
-
st.image(generated_image, caption="Imagen Generada", use_column_width=True)
|
50 |
-
|
51 |
-
# Permitir descarga
|
52 |
-
st.download_button(
|
53 |
-
label="Descargar imagen",
|
54 |
-
data=image_data.getvalue(),
|
55 |
-
file_name="generated_image.png",
|
56 |
-
mime="image/png"
|
57 |
-
)
|
58 |
except Exception as e:
|
59 |
-
st.error(f"Error en la generación de la imagen: {
|
|
|
|
|
|
3 |
from PIL import Image
|
4 |
import io
|
5 |
|
6 |
+
# Initialize Hugging Face Inference Client
|
7 |
+
hf_token = st.secrets["HF_TOKEN"] # Use your Hugging Face token
|
8 |
+
client = InferenceClient(model="enhanceaiteam/Flux-uncensored", token=hf_token)
|
9 |
|
10 |
+
# Streamlit UI
|
11 |
+
st.title("Generación de Imágenes img2img con Flux")
|
12 |
+
st.sidebar.header("Opciones de generación")
|
|
|
|
|
13 |
prompt = st.sidebar.text_input("Escribe tu prompt:", value="")
|
14 |
|
15 |
+
uploaded_file = st.sidebar.file_uploader("Sube una imagen base", type=["jpg", "png"])
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
if uploaded_file is not None:
|
|
|
18 |
try:
|
19 |
+
init_image = Image.open(uploaded_file).convert("RGB")
|
20 |
+
st.image(init_image, caption="Imagen Base", use_column_width=True)
|
21 |
+
|
22 |
+
if st.sidebar.button("Generar Imagen"):
|
23 |
+
with st.spinner('Generando imagen...'):
|
24 |
+
# Convert the uploaded image to bytes
|
25 |
+
img_bytes = io.BytesIO()
|
26 |
+
init_image.save(img_bytes, format="PNG")
|
27 |
+
img_bytes = img_bytes.getvalue()
|
28 |
+
|
29 |
+
# Call the API with the prompt and base image
|
30 |
+
image = client.img2img(prompt=prompt, image=img_bytes) # Returns image bytes
|
31 |
+
|
32 |
+
# Display the generated image
|
33 |
+
st.image(image, caption="Imagen Generada")
|
34 |
+
|
35 |
+
# Option to download the generated image
|
36 |
+
st.download_button(label="Descargar imagen", data=image, file_name="generated_image.png", mime="image/png")
|
37 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
except Exception as e:
|
39 |
+
st.error(f"Error en la generación de la imagen: {e}")
|
40 |
+
else:
|
41 |
+
st.warning("Por favor, sube una imagen base para continuar.")
|