Update app.py
Browse files
app.py
CHANGED
@@ -1,83 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
import numpy as np
|
3 |
-
import random
|
4 |
import torch
|
5 |
-
from diffusers import
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
num_inference_steps=num_inference_steps,
|
31 |
-
width=width,
|
32 |
-
height=height,
|
33 |
-
generator=generator,
|
34 |
-
output_type="pil",
|
35 |
-
good_vae=good_vae,
|
36 |
-
):
|
37 |
-
yield img, seed
|
38 |
-
|
39 |
-
examples = [
|
40 |
-
"a tiny astronaut hatching from an egg on the moon",
|
41 |
-
"a cat holding a sign that says hello world",
|
42 |
-
"an anime illustration of a wiener schnitzel",
|
43 |
-
]
|
44 |
-
|
45 |
-
css = """
|
46 |
-
#col-container {
|
47 |
-
margin: 0 auto;
|
48 |
-
max-width: 520px;
|
49 |
-
}
|
50 |
-
"""
|
51 |
-
|
52 |
-
with gr.Blocks(css=css) as demo:
|
53 |
-
with gr.Column(elem_id="col-container"):
|
54 |
-
gr.Markdown("""# FLUX.1 [dev]
|
55 |
-
12B param rectified flow transformer guidance-distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/)
|
56 |
-
[[non-commercial license](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md)] [[blog](https://blackforestlabs.ai/announcing-black-forest-labs/)] [[model](https://huggingface.co/black-forest-labs/FLUX.1-dev)]
|
57 |
-
""")
|
58 |
-
|
59 |
-
with gr.Row():
|
60 |
-
prompt = gr.Textbox(
|
61 |
-
label="Prompt",
|
62 |
-
show_label=False,
|
63 |
-
max_lines=1,
|
64 |
-
placeholder="Enter your prompt",
|
65 |
-
container=False,
|
66 |
-
)
|
67 |
-
run_button = gr.Button("Run", scale=0)
|
68 |
-
|
69 |
-
result = gr.Image(label="Result", show_label=False)
|
70 |
-
|
71 |
-
with gr.Accordion("Advanced Settings", open=False):
|
72 |
-
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
|
73 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
74 |
-
|
75 |
-
with gr.Row():
|
76 |
-
width = gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
|
77 |
-
height = gr.Slider(label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
|
78 |
-
|
79 |
-
with gr.Row():
|
80 |
-
guidance_scale = gr.Slider(label="Guidance Scale", minimum=1, maximum=15, step=0.1, value=3.5)
|
81 |
-
num_inference_steps = gr.Slider(label="Number of inference steps", minimum=1, maximum=50, step=1, value=28)
|
82 |
-
|
83 |
-
gr.Examples(examples=examples, inputs=[prompt], outputs=[
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
import torch
|
3 |
+
from diffusers import StableDiffusionPipeline
|
4 |
+
|
5 |
+
# Cargar el modelo de Stable Diffusion desde Hugging Face
|
6 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
7 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
8 |
+
pipe.to("cuda") # Cambiar a CPU si no hay GPU disponible
|
9 |
+
|
10 |
+
# Función para generar la imagen
|
11 |
+
def generar_imagen(texto):
|
12 |
+
with torch.autocast("cuda"):
|
13 |
+
image = pipe(texto, guidance_scale=7.5).images[0]
|
14 |
+
return image
|
15 |
+
|
16 |
+
# Interfaz de Gradio
|
17 |
+
interfaz = gr.Interface(
|
18 |
+
fn=generar_imagen,
|
19 |
+
inputs="text",
|
20 |
+
outputs="image",
|
21 |
+
title="Generador de Imágenes con Stable Diffusion",
|
22 |
+
description="Escribe una descripción y genera una imagen usando Stable Diffusion."
|
23 |
+
)
|
24 |
+
|
25 |
+
# Ejecuta la aplicación
|
26 |
+
if __name__ == "__main__":
|
27 |
+
interfaz.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|