Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from diffusers import DiffusionPipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Cargar el modelo
|
| 6 |
+
model_id = "sd-community/sdxl-flash"
|
| 7 |
+
pipeline = DiffusionPipeline.from_pretrained(model_id)
|
| 8 |
+
|
| 9 |
+
# Estilos CSS personalizados
|
| 10 |
+
custom_css = """
|
| 11 |
+
<style>
|
| 12 |
+
body {
|
| 13 |
+
background-color: #1f1f1f;
|
| 14 |
+
color: #ffffff;
|
| 15 |
+
font-family: Arial, sans-serif;
|
| 16 |
+
}
|
| 17 |
+
.gr-form input[type="text"], .gr-form select {
|
| 18 |
+
background-color: #333333 !important;
|
| 19 |
+
border: 1px solid #777777 !important;
|
| 20 |
+
color: #ffffff !important;
|
| 21 |
+
}
|
| 22 |
+
.gr-output {
|
| 23 |
+
background-color: #333333 !important;
|
| 24 |
+
border: 2px solid #777777 !important;
|
| 25 |
+
border-radius: 5px;
|
| 26 |
+
padding: 10px;
|
| 27 |
+
margin-top: 20px;
|
| 28 |
+
}
|
| 29 |
+
.gr-control.gr-number input {
|
| 30 |
+
width: 100px !important;
|
| 31 |
+
}
|
| 32 |
+
</style>
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
def generate_image(prompt, steps, negative_prompt, num_images):
|
| 36 |
+
result = pipeline(prompt, num_inference_steps=steps, negative_prompt=negative_prompt, num_images=num_images)
|
| 37 |
+
images = result.images
|
| 38 |
+
return images
|
| 39 |
+
|
| 40 |
+
# Crear la interfaz de Gradio
|
| 41 |
+
iface = gr.Interface(
|
| 42 |
+
fn=generate_image,
|
| 43 |
+
inputs=[
|
| 44 |
+
gr.inputs.Textbox(label="Prompt", placeholder="Ingrese un prompt...", lines=5),
|
| 45 |
+
gr.inputs.Number(label="Steps", default=10, min=1, max=15),
|
| 46 |
+
gr.inputs.Textbox(label="Negative Prompt (Opcional)", placeholder="Ingrese un negative prompt...", lines=2, optional=True),
|
| 47 |
+
gr.inputs.Number(label="Número de Imágenes", default=1, min=1, max=8)
|
| 48 |
+
],
|
| 49 |
+
outputs=gr.outputs.Image(label="Imágenes Generadas"),
|
| 50 |
+
title="Generador de Imágenes con Stable Diffusion",
|
| 51 |
+
description="Este modelo de Stable Diffusion genera imágenes a partir de un prompt.",
|
| 52 |
+
theme="gradio",
|
| 53 |
+
css=custom_css
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
# Ejecutar la interfaz
|
| 57 |
+
iface.launch()
|