Spaces:
No application file
No application file
Commit
·
19fa8b2
1
Parent(s):
3113fbb
app3.py
CHANGED
|
@@ -1,22 +1,36 @@
|
|
|
|
|
| 1 |
from diffusers import StableDiffusionUpscalePipeline
|
| 2 |
-
import torch
|
| 3 |
from PIL import Image
|
|
|
|
| 4 |
|
| 5 |
-
# Cargar
|
| 6 |
model_id = "stabilityai/stable-diffusion-x4-upscaler"
|
| 7 |
-
pipe = StableDiffusionUpscalePipeline.from_pretrained(model_id
|
| 8 |
-
pipe = pipe.to("cpu")
|
| 9 |
-
|
| 10 |
-
# Cargar la imagen a mejorar
|
| 11 |
-
input_image = Image.open("mi_imagen.jpg").convert("RGB")
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
from diffusers import StableDiffusionUpscalePipeline
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
|
| 6 |
+
# Cargar pipeline (float32 para CPU)
|
| 7 |
model_id = "stabilityai/stable-diffusion-x4-upscaler"
|
| 8 |
+
pipe = StableDiffusionUpscalePipeline.from_pretrained(model_id)
|
| 9 |
+
pipe = pipe.to("cpu") # o "cuda" si tenés GPU
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Función que Gradio llamará
|
| 12 |
+
def upscaler_gradio(imagen):
|
| 13 |
+
if imagen is None:
|
| 14 |
+
return None
|
| 15 |
|
| 16 |
+
# Convertir la imagen de NumPy a PIL
|
| 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=upscaler_gradio,
|
| 30 |
+
inputs=gr.Image(type="numpy"), # permite subir imagen desde la web
|
| 31 |
+
outputs=gr.Image(),
|
| 32 |
+
title="Upscaler Difusión",
|
| 33 |
+
description="Sube una imagen y el modelo la mejorará y aumentará resolución 4×."
|
| 34 |
+
)
|
| 35 |
|
| 36 |
+
demo.launch()
|