JeCabrera commited on
Commit
0ecf720
verified
1 Parent(s): e30003d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -49
app.py CHANGED
@@ -6,7 +6,6 @@ import os
6
  import time
7
  from PIL import Image
8
  from deep_translator import GoogleTranslator
9
- import json
10
 
11
  # Project by Nymbo
12
 
@@ -16,7 +15,7 @@ headers = {"Authorization": f"Bearer {API_TOKEN}"}
16
  timeout = 100
17
 
18
  def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7):
19
- if prompt == "" or prompt == None:
20
  return None
21
 
22
  key = random.randint(0, 999)
@@ -60,62 +59,37 @@ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Ka
60
  print(f"Error when trying to open the image: {e}")
61
  return None
62
 
63
- def clear_prompt(prompt):
64
- return ""
65
-
66
- css = """
67
- h1 {
68
- color: #f28f8f; /* Color para el encabezado h1 */
69
- }
70
-
71
- h2 {
72
- color: #f28f8f; /* Color para el encabezado h2 */
73
- }
74
-
75
- button.primary {
76
- background-color: #28a745; /* Color verde para el bot贸n Generate */
77
- color: #ffffff; /* Texto blanco en el bot贸n */
78
- border: 1px solid #28a745; /* Borde verde para el bot贸n */
79
- }
80
-
81
- button.primary:hover {
82
- background-color: #218838; /* Verde oscuro en hover */
83
- }
84
-
85
- button.secondary {
86
- background-color: #f0f0f0; /* Color de fondo para el bot贸n Clear */
87
- color: #333333; /* Texto gris oscuro en el bot贸n */
88
- border: 1px solid #cccccc; /* Borde gris claro para el bot贸n */
89
- }
90
- """
91
-
92
- with gr.Blocks(css=css) as app:
93
  gr.HTML("""
94
- <h1 align="center">Dream Generator with Flux</h1>
95
- <h2 align="center">Transforma tus sue帽os en im谩genes vibrantes con un solo clic.</h2>
 
 
96
  """)
97
 
98
  with gr.Row():
99
  with gr.Column(scale=1):
100
  text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2, elem_id="prompt-text-input")
101
- with gr.Accordion("Advanced Settings", open=False):
102
  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")
103
- steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
104
- cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=1)
105
- method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
106
- strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
107
- seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
 
 
 
 
108
 
109
- with gr.Row(): # Fila para los botones
110
- with gr.Column(scale=1, elem_id="button-container"):
111
- clear_button = gr.Button("Clear", elem_id="clear-button", variant="secondary")
112
- with gr.Column(scale=1, elem_id="button-container"):
113
- generate_button = gr.Button("Generate", elem_id="generate-button", variant="primary")
114
-
115
  with gr.Column(scale=1):
116
  image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
117
-
118
- clear_button.click(fn=clear_prompt, inputs=text_prompt, outputs=text_prompt)
119
- generate_button.click(fn=query, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength], outputs=image_output)
 
 
 
 
120
 
121
  app.launch(show_api=False, share=False)
 
6
  import time
7
  from PIL import Image
8
  from deep_translator import GoogleTranslator
 
9
 
10
  # Project by Nymbo
11
 
 
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)
 
59
  print(f"Error when trying to open the image: {e}")
60
  return None
61
 
62
+ with gr.Blocks() as app:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  gr.HTML("""
64
+ <center>
65
+ <h1>Dream Generator with Flux</h1>
66
+ <h2>Transforma tus sue帽os en im谩genes vibrantes con un solo clic.</h2>
67
+ </center>
68
  """)
69
 
70
  with gr.Row():
71
  with gr.Column(scale=1):
72
  text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2, elem_id="prompt-text-input")
73
+ with gr.Row():
74
  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")
75
+ steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
76
+ cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=1)
77
+ method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
78
+ strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
79
+ seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
80
+
81
+ with gr.Row():
82
+ clear_button = gr.Button("Clear", elem_id="clear-button", variant="secondary", color="white", border_color="black")
83
+ generate_button = gr.Button("Generate", elem_id="generate-button", variant="primary", color="green", border_color="black")
84
 
 
 
 
 
 
 
85
  with gr.Column(scale=1):
86
  image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
87
+
88
+ generate_button.click(query, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength], outputs=image_output)
89
+
90
+ def clear_prompt():
91
+ return gr.Textbox.update(value="")
92
+
93
+ clear_button.click(clear_prompt, inputs=[], outputs=text_prompt)
94
 
95
  app.launch(show_api=False, share=False)