Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import requests
|
|
3 |
import io
|
4 |
import random
|
5 |
import os
|
6 |
-
import time
|
7 |
from PIL import Image
|
8 |
from deep_translator import GoogleTranslator
|
9 |
|
@@ -14,8 +13,8 @@ API_TOKEN = os.getenv("HF_READ_TOKEN")
|
|
14 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
15 |
timeout = 100
|
16 |
|
17 |
-
def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7):
|
18 |
-
if
|
19 |
return None
|
20 |
|
21 |
key = random.randint(0, 999)
|
@@ -39,7 +38,9 @@ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Ka
|
|
39 |
"steps": steps,
|
40 |
"cfg_scale": cfg_scale,
|
41 |
"seed": seed if seed != -1 else random.randint(1, 1000000000),
|
42 |
-
"strength": strength
|
|
|
|
|
43 |
}
|
44 |
|
45 |
response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
|
@@ -64,77 +65,70 @@ css = """
|
|
64 |
max-width: 600px;
|
65 |
margin-left: auto;
|
66 |
margin-right: auto;
|
|
|
|
|
67 |
}
|
68 |
|
69 |
input, textarea, select {
|
70 |
background-color: #f5f5f5; /* Fondo gris claro para inputs */
|
71 |
color: #333333; /* Texto gris oscuro en inputs */
|
72 |
-
border: 1px solid #
|
73 |
}
|
74 |
|
75 |
button {
|
76 |
-
background-color: #
|
77 |
-
color: #
|
78 |
-
border:
|
79 |
-
|
80 |
-
|
81 |
-
button.primary {
|
82 |
-
background-color: green; /* Fondo verde para el botón 'Generate' */
|
83 |
-
color: white; /* Texto blanco en el botón 'Generate' */
|
84 |
-
}
|
85 |
-
|
86 |
-
button.secondary {
|
87 |
-
background-color: #f5f5f5; /* Fondo gris claro para el botón 'Clear' */
|
88 |
-
color: #333333; /* Texto gris oscuro en el botón 'Clear' */
|
89 |
}
|
90 |
|
91 |
button:hover {
|
92 |
-
background-color: #
|
93 |
}
|
94 |
|
95 |
-
h1
|
96 |
-
color: #333333; /* Texto gris oscuro en
|
97 |
}
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
display: flex;
|
102 |
-
flex-direction: column;
|
103 |
-
gap: 10px;
|
104 |
-
}
|
105 |
}
|
106 |
"""
|
107 |
|
108 |
with gr.Blocks(css=css) as app:
|
109 |
-
gr.HTML(""
|
110 |
-
<center>
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
|
|
|
|
|
|
139 |
|
140 |
app.launch(show_api=False, share=False)
|
|
|
3 |
import io
|
4 |
import random
|
5 |
import os
|
|
|
6 |
from PIL import Image
|
7 |
from deep_translator import GoogleTranslator
|
8 |
|
|
|
13 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
14 |
timeout = 100
|
15 |
|
16 |
+
def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, width=1024, height=1024):
|
17 |
+
if prompt == "" or prompt is None:
|
18 |
return None
|
19 |
|
20 |
key = random.randint(0, 999)
|
|
|
38 |
"steps": steps,
|
39 |
"cfg_scale": cfg_scale,
|
40 |
"seed": seed if seed != -1 else random.randint(1, 1000000000),
|
41 |
+
"strength": strength,
|
42 |
+
"width": width,
|
43 |
+
"height": height
|
44 |
}
|
45 |
|
46 |
response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
|
|
|
65 |
max-width: 600px;
|
66 |
margin-left: auto;
|
67 |
margin-right: auto;
|
68 |
+
background-color: #ffffff; /* Fondo blanco */
|
69 |
+
color: #333333; /* Texto gris oscuro */
|
70 |
}
|
71 |
|
72 |
input, textarea, select {
|
73 |
background-color: #f5f5f5; /* Fondo gris claro para inputs */
|
74 |
color: #333333; /* Texto gris oscuro en inputs */
|
75 |
+
border: 1px solid #333333; /* Borde negro en inputs */
|
76 |
}
|
77 |
|
78 |
button {
|
79 |
+
background-color: #28a745; /* Fondo verde */
|
80 |
+
color: #ffffff; /* Texto blanco en botones */
|
81 |
+
border: 1px solid #333333; /* Borde negro en botones */
|
82 |
+
border-radius: 4px; /* Bordes redondeados */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
}
|
84 |
|
85 |
button:hover {
|
86 |
+
background-color: #218838; /* Verde oscuro en hover */
|
87 |
}
|
88 |
|
89 |
+
h1 {
|
90 |
+
color: #333333; /* Texto gris oscuro en h1 */
|
91 |
}
|
92 |
|
93 |
+
h2 {
|
94 |
+
color: #333333; /* Texto gris oscuro en h2 */
|
|
|
|
|
|
|
|
|
95 |
}
|
96 |
"""
|
97 |
|
98 |
with gr.Blocks(css=css) as app:
|
99 |
+
gr.HTML("<center><h1>Generador de Sueños con Flux</h1></center>")
|
100 |
+
gr.HTML("<center><h2>Transforma tus sueños en imágenes vibrantes con un solo clic.</h2></center>")
|
101 |
+
with gr.Column(elem_id="app-container"):
|
102 |
+
with gr.Row():
|
103 |
+
with gr.Column():
|
104 |
+
text_prompt = gr.Textbox(label="Prompt", placeholder="Introduce un prompt aquí", lines=2, elem_id="prompt-text-input")
|
105 |
+
with gr.Accordion("Opciones avanzadas", open=False):
|
106 |
+
negative_prompt = gr.Textbox(label="Prompt Negativo", placeholder="Qué no debería aparecer en la imagen", value="(deformed, distorted, disfigured), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, misspellings, typos", lines=3, elem_id="negative-prompt-text-input")
|
107 |
+
steps = gr.Slider(label="Pasos de muestreo", value=35, minimum=1, maximum=100, step=1)
|
108 |
+
cfg = gr.Slider(label="Escala CFG", value=7, minimum=1, maximum=20, step=1)
|
109 |
+
method = gr.Radio(label="Método de muestreo", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
|
110 |
+
strength = gr.Slider(label="Fuerza", value=0.7, minimum=0, maximum=1, step=0.001)
|
111 |
+
seed = gr.Slider(label="Semilla", value=-1, minimum=-1, maximum=1000000000, step=1)
|
112 |
+
|
113 |
+
image_size = gr.Dropdown(
|
114 |
+
label="Tamaño de Imagen",
|
115 |
+
choices=[
|
116 |
+
"4:3 (1024x768 px)",
|
117 |
+
"16:9 (1920x1080 px)",
|
118 |
+
"1:1 (1080x1080 px)",
|
119 |
+
"1:1 (500x500 px)",
|
120 |
+
"9:16 (720x1280 px)",
|
121 |
+
"9:16 (1080x1920 px)"
|
122 |
+
],
|
123 |
+
value="16:9 (1920x1080 px)"
|
124 |
+
)
|
125 |
+
|
126 |
+
with gr.Column():
|
127 |
+
with gr.Row():
|
128 |
+
generate_button = gr.Button("Generar", elem_id="generate-button", variant="primary")
|
129 |
+
with gr.Row():
|
130 |
+
image_output = gr.Image(type="pil", label="Imagen de Salida", elem_id="gallery")
|
131 |
+
|
132 |
+
generate_button.click(query, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength, image_size], outputs=image_output)
|
133 |
|
134 |
app.launch(show_api=False, share=False)
|