Spaces:
No application file
No application file
Commit
·
c047743
1
Parent(s):
ad8cb4d
app.py
CHANGED
|
@@ -1,25 +1,29 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
-
from transformers import pipeline
|
| 4 |
|
| 5 |
-
#
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def describir(imagen):
|
| 10 |
if imagen is None:
|
| 11 |
-
return
|
| 12 |
|
| 13 |
-
img = Image.fromarray(imagen)
|
| 14 |
-
|
|
|
|
| 15 |
return result
|
| 16 |
|
|
|
|
| 17 |
demo = gr.Interface(
|
| 18 |
-
fn=
|
| 19 |
inputs=gr.Image(type="numpy"),
|
| 20 |
-
outputs=gr.
|
| 21 |
-
title="
|
| 22 |
-
description="Sube una imagen y
|
| 23 |
)
|
| 24 |
|
| 25 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionUpscalePipeline
|
| 3 |
from PIL import Image
|
|
|
|
| 4 |
|
| 5 |
+
# Cargar pipeline (float32 para CPU)
|
| 6 |
+
model_id = "stabilityai/stable-diffusion-x4-upscaler"
|
| 7 |
+
pipe = StableDiffusionUpscalePipeline.from_pretrained(model_id)
|
| 8 |
+
pipe = pipe.to("cpu") # o "cuda" si hay GPU
|
| 9 |
|
| 10 |
+
# Función de Gradio
|
| 11 |
+
def upscaler_gradio(imagen):
|
|
|
|
| 12 |
if imagen is None:
|
| 13 |
+
return None
|
| 14 |
|
| 15 |
+
img = Image.fromarray(imagen) # convertir de NumPy a PIL
|
| 16 |
+
prompt = "A high quality, detailed, and visually clear image"
|
| 17 |
+
result = pipe(prompt=prompt, image=img, scale=4).images[0]
|
| 18 |
return result
|
| 19 |
|
| 20 |
+
# Interfaz Gradio
|
| 21 |
demo = gr.Interface(
|
| 22 |
+
fn=upscaler_gradio,
|
| 23 |
inputs=gr.Image(type="numpy"),
|
| 24 |
+
outputs=gr.Image(),
|
| 25 |
+
title="Upscaler Difusión",
|
| 26 |
+
description="Sube una imagen y el modelo la mejorará y aumentará resolución 4×."
|
| 27 |
)
|
| 28 |
|
| 29 |
+
demo.launch()
|