Spaces:
No application file
No application file
Commit
·
1a2afdb
1
Parent(s):
19fa8b2
app3.py
CHANGED
|
@@ -1,36 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from diffusers import
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
| 5 |
|
| 6 |
-
# Cargar
|
| 7 |
-
model_id = "
|
| 8 |
-
pipe =
|
| 9 |
-
pipe = pipe.to("cpu") #
|
| 10 |
|
| 11 |
# Función que Gradio llamará
|
| 12 |
-
def
|
| 13 |
-
if
|
| 14 |
return None
|
| 15 |
-
|
| 16 |
-
#
|
| 17 |
-
img = Image.fromarray(imagen)
|
| 18 |
-
|
| 19 |
-
# Prompt opcional
|
| 20 |
-
prompt = "A high quality, detailed, and visually clear image"
|
| 21 |
-
|
| 22 |
-
# Ejecutar upscaling
|
| 23 |
-
result = pipe(prompt=prompt, image=img).images[0]
|
| 24 |
-
|
| 25 |
-
return result
|
| 26 |
|
| 27 |
# Interfaz Gradio
|
| 28 |
demo = gr.Interface(
|
| 29 |
-
fn=
|
| 30 |
-
inputs=gr.
|
| 31 |
-
outputs=gr.Image(),
|
| 32 |
-
title="
|
| 33 |
-
description="
|
| 34 |
)
|
| 35 |
|
| 36 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
| 5 |
|
| 6 |
+
# Cargar un modelo ligero de ejemplo
|
| 7 |
+
model_id = "OFA-Sys/small-stable-diffusion-v0"
|
| 8 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id)
|
| 9 |
+
pipe = pipe.to("cpu") # usar "cuda" si hay GPU
|
| 10 |
|
| 11 |
# Función que Gradio llamará
|
| 12 |
+
def generar_imagen(prompt):
|
| 13 |
+
if not prompt:
|
| 14 |
return None
|
| 15 |
+
image = pipe(prompt).images[0]
|
| 16 |
+
return image # No hacemos image.save(), Gradio lo mostrará y permitirá descargarlo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Interfaz Gradio
|
| 19 |
demo = gr.Interface(
|
| 20 |
+
fn=generar_imagen,
|
| 21 |
+
inputs=gr.Textbox(label="Prompt"),
|
| 22 |
+
outputs=gr.Image(type="pil"), # type="pil" permite descargar la imagen
|
| 23 |
+
title="Generador de imágenes ligero",
|
| 24 |
+
description="Introduce un prompt y el modelo generará la imagen. Podrás descargarla con el botón de Gradio."
|
| 25 |
)
|
| 26 |
|
| 27 |
demo.launch()
|