JeCabrera commited on
Commit
5329473
·
verified ·
1 Parent(s): 5db9fa6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -51
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, width=1024, height=1024):
17
- if prompt == "" or prompt is None:
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 #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)
 
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)