add
Browse files
main.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
from PIL import Image
|
3 |
+
from io import BytesIO
|
4 |
+
from diffusers import StableDiffusionUpscalePipeline
|
5 |
+
import torch
|
6 |
+
|
7 |
+
# pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-x4-upscaler")
|
8 |
+
|
9 |
+
# load model and scheduler
|
10 |
+
model_id = "stabilityai/stable-diffusion-x4-upscaler"
|
11 |
+
pipeline = StableDiffusionUpscalePipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
12 |
+
pipeline = pipeline.to("cuda")
|
13 |
+
|
14 |
+
# let's download an image
|
15 |
+
url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd2-upscale/low_res_cat.png"
|
16 |
+
response = requests.get(url)
|
17 |
+
low_res_img = Image.open(BytesIO(response.content)).convert("RGB")
|
18 |
+
low_res_img = low_res_img.resize((128, 128))
|
19 |
+
|
20 |
+
prompt = "a white cat"
|
21 |
+
|
22 |
+
upscaled_image = pipeline(prompt=prompt, image=low_res_img).images[0]
|
23 |
+
upscaled_image.save("upsampled_cat.png")
|