Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import requests
|
|
3 |
import io
|
4 |
import random
|
5 |
import os
|
|
|
6 |
from PIL import Image
|
7 |
from deep_translator import GoogleTranslator
|
8 |
|
@@ -13,8 +14,8 @@ API_TOKEN = os.getenv("HF_READ_TOKEN")
|
|
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
|
17 |
-
if
|
18 |
return None
|
19 |
|
20 |
key = random.randint(0, 999)
|
@@ -38,9 +39,7 @@ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Ka
|
|
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,70 +64,77 @@ css = """
|
|
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 #
|
76 |
}
|
77 |
|
78 |
button {
|
79 |
-
background-color: #
|
80 |
-
color: #
|
81 |
-
border:
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
}
|
84 |
|
85 |
button:hover {
|
86 |
-
background-color: #
|
87 |
}
|
88 |
|
89 |
-
h1 {
|
90 |
-
color: #333333; /* Texto gris oscuro en
|
91 |
}
|
92 |
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
95 |
}
|
96 |
"""
|
97 |
|
98 |
with gr.Blocks(css=css) as app:
|
99 |
-
gr.HTML("
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
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)
|
|
|
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 |
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 not prompt:
|
19 |
return None
|
20 |
|
21 |
key = random.randint(0, 999)
|
|
|
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 |
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 #cccccc; /* Borde gris claro en inputs */
|
73 |
}
|
74 |
|
75 |
button {
|
76 |
+
background-color: #f5f5f5; /* Fondo gris claro */
|
77 |
+
color: #333333; /* Texto gris oscuro */
|
78 |
+
border: 2px solid black; /* Borde negro en botones */
|
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: #e0e0e0; /* Fondo gris más oscuro en hover */
|
93 |
}
|
94 |
|
95 |
+
h1, h2, h3, h4, h5, h6 {
|
96 |
+
color: #333333; /* Texto gris oscuro en encabezados */
|
97 |
}
|
98 |
|
99 |
+
@media (max-width: 768px) {
|
100 |
+
.button-row {
|
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 |
+
<h1>Dream Generator with Flux</h1>
|
112 |
+
<h2>Transforma tus sueños en imágenes vibrantes con un solo clic.</h2>
|
113 |
+
</center>
|
114 |
+
""")
|
115 |
+
|
116 |
+
with gr.Row():
|
117 |
+
with gr.Column(scale=1):
|
118 |
+
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2, elem_id="prompt-text-input")
|
119 |
+
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image", 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")
|
120 |
+
steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
|
121 |
+
cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=1)
|
122 |
+
method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
|
123 |
+
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
124 |
+
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
125 |
+
|
126 |
+
with gr.Row(elem_id="button-row"):
|
127 |
+
clear_button = gr.Button("Clear", elem_id="clear-button", variant="secondary")
|
128 |
+
generate_button = gr.Button("Generate", elem_id="generate-button", variant="primary")
|
129 |
+
|
130 |
+
with gr.Column(scale=1):
|
131 |
+
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
132 |
+
|
133 |
+
generate_button.click(query, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength], outputs=image_output)
|
134 |
+
|
135 |
+
def clear_prompt():
|
136 |
+
return gr.Textbox.update(value="")
|
137 |
+
|
138 |
+
clear_button.click(clear_prompt, inputs=[], outputs=text_prompt)
|
|
|
|
|
|
|
|
|
139 |
|
140 |
app.launch(show_api=False, share=False)
|