Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,32 @@
|
|
| 1 |
import torch
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
-
from diffusers import StableDiffusionPipeline
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
except Exception as e:
|
| 15 |
-
pipe = None
|
| 16 |
-
print(f"Error al cargar el modelo: {e}")
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
def
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# El pipeline devuelve una clase con una lista de imágenes. Tomamos la primera.
|
| 24 |
-
imagen_generada = pipe(prompt).images[0]
|
| 25 |
-
return imagen_generada
|
| 26 |
|
| 27 |
-
#
|
| 28 |
demo = gr.Interface(
|
| 29 |
-
fn=
|
| 30 |
-
inputs=gr.Textbox(
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
),
|
| 34 |
-
outputs=gr.Image(label="Imagen Generada", type="pil"),
|
| 35 |
-
title="Generador de Imágenes IA",
|
| 36 |
-
description="Escribe una descripción y la IA generará una imagen basándose en tu texto."
|
| 37 |
)
|
| 38 |
|
| 39 |
-
|
| 40 |
-
demo.launch()
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from diffusers import AutoPipelineForText2Image
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
+
# Cargar modelo (se ejecuta una sola vez)
|
| 6 |
+
pipe = AutoPipelineForText2Image.from_pretrained(
|
| 7 |
+
"black-forest-labs/FLUX.1-dev",
|
| 8 |
+
torch_dtype=torch.bfloat16
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
pipe = pipe.to("cuda")
|
| 12 |
|
| 13 |
+
# Cargar LoRA
|
| 14 |
+
pipe.load_lora_weights(
|
| 15 |
+
"enhanceaiteam/Flux-uncensored-v2",
|
| 16 |
+
weight_name="lora.safetensors"
|
| 17 |
+
)
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# Función para generar imagen
|
| 20 |
+
def generate(prompt):
|
| 21 |
+
image = pipe(prompt).images[0]
|
| 22 |
+
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
# Interfaz
|
| 25 |
demo = gr.Interface(
|
| 26 |
+
fn=generate,
|
| 27 |
+
inputs=gr.Textbox(label="Prompt"),
|
| 28 |
+
outputs=gr.Image(label="Resultado"),
|
| 29 |
+
title="FLUX + LoRA Demo"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
+
demo.launch()
|
|
|