Spaces:
Sleeping
Sleeping
stable
Browse files
app.py
CHANGED
@@ -1,64 +1,3 @@
|
|
1 |
import gradio as gr
|
2 |
-
from diffusers import DiffusionPipeline
|
3 |
-
import torch
|
4 |
|
5 |
-
|
6 |
-
base = DiffusionPipeline.from_pretrained(
|
7 |
-
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
|
8 |
-
)
|
9 |
-
base.to("cuda")
|
10 |
-
refiner = DiffusionPipeline.from_pretrained(
|
11 |
-
"stabilityai/stable-diffusion-xl-refiner-1.0",
|
12 |
-
text_encoder_2=base.text_encoder_2,
|
13 |
-
vae=base.vae,
|
14 |
-
torch_dtype=torch.float16,
|
15 |
-
use_safetensors=True,
|
16 |
-
variant="fp16",
|
17 |
-
)
|
18 |
-
refiner.to("cuda")
|
19 |
-
|
20 |
-
# Definir cu谩ntos pasos y qu茅 porcentaje de pasos ejecutar en cada experto (80/20) aqu铆
|
21 |
-
n_steps = 40
|
22 |
-
high_noise_frac = 0.8
|
23 |
-
|
24 |
-
# Definir funci贸n para generar imagen
|
25 |
-
def generate_image(prompt):
|
26 |
-
image = base(
|
27 |
-
prompt=prompt,
|
28 |
-
num_inference_steps=n_steps,
|
29 |
-
denoising_end=high_noise_frac,
|
30 |
-
output_type="latent",
|
31 |
-
).images
|
32 |
-
image = refiner(
|
33 |
-
prompt=prompt,
|
34 |
-
num_inference_steps=n_steps,
|
35 |
-
denoising_start=high_noise_frac,
|
36 |
-
image=image,
|
37 |
-
).images[0]
|
38 |
-
return image
|
39 |
-
|
40 |
-
# Crear la interfaz de Gradio
|
41 |
-
iface = gr.Interface(
|
42 |
-
fn=generate_image,
|
43 |
-
inputs=gr.Textbox(lines=5, label="Descripci贸n de la imagen", placeholder="Introduce el texto aqu铆..."),
|
44 |
-
outputs=gr.Image(type="pil", label="Imagen generada"),
|
45 |
-
title="Generador de Im谩genes a partir de Texto",
|
46 |
-
description="Ingrese un texto y obtenga una imagen generada por IA.",
|
47 |
-
examples=[
|
48 |
-
["A picturesque view of a local market. The first light of day illuminates the stone facades and worn tiles of the houses and buildings, some of which date back centuries. At the center of the scene, a cobblestone square leads to an open-air market that begins to come to life, with vendors setting up their stalls selling fruits, vegetables, flowers, and local crafts. The narrow, winding streets are lined with old lanterns, now unlit, while lazy cats lounge on the stone steps. In one corner, an ancient fountain, adorned with weathered carvings, murmurs softly, adding to the tranquil atmosphere. In the background, the towers of an ancient cathedral rise, capturing the first rays of sunlight that paint the sky in soft pinks and oranges. This image should convey a sense of tranquility, beauty, and a deep connection to the past, celebrating the rich history and timeless charm of the ancient village or town."]
|
49 |
-
],
|
50 |
-
live=True,
|
51 |
-
css="""
|
52 |
-
.gradio-container {
|
53 |
-
background-color: #f9f9f9;
|
54 |
-
color: #333;
|
55 |
-
font-family: Arial, sans-serif;
|
56 |
-
}
|
57 |
-
.gradio-container h1 {
|
58 |
-
color: #4CAF50;
|
59 |
-
}
|
60 |
-
"""
|
61 |
-
)
|
62 |
-
|
63 |
-
# Ejecutar la interfaz
|
64 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
+
gr.load("models/stabilityai/stable-diffusion-xl-base-1.0").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|