Spaces:
Running
on
L4
Running
on
L4
Create app.py
Browse files1st deployment
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch #needed only for GPU
|
2 |
+
from PIL import Image
|
3 |
+
from io import BytesIO
|
4 |
+
from diffusers import StableDiffusionUpscalePipeline
|
5 |
+
import gradio as gr
|
6 |
+
# load model and scheduler
|
7 |
+
model_id = "stabilityai/stable-diffusion-x4-upscaler"
|
8 |
+
pipeline = StableDiffusionUpscalePipeline.from_pretrained(model_id)
|
9 |
+
pipeline = pipeline.to("cpu")
|
10 |
+
#define interface
|
11 |
+
def upscale(low_res_img, prompt, guide):
|
12 |
+
low_res_img = Image.open(low_res_img).convert("RGB")
|
13 |
+
low_res_img = low_res_img.resize((128, 128))
|
14 |
+
upscaled_image = pipeline(prompt=prompt, image=low_res_img, guidance_scale=guide).images[0]
|
15 |
+
upscaled_image.save("upsampled.png")
|
16 |
+
return upscaled_image
|
17 |
+
#launch interface
|
18 |
+
gr.Interface(fn=upscale, inputs=[gr.Image(type='filepath'), 'text', gr.Slider(1, 20, 5)], outputs=gr.Image(type='filepath')).launch(max_threads=True, debug=True)
|