File size: 1,074 Bytes
a6049d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import torch as th
from diffusers import IFImg2ImgSuperResolutionPipeline
from transformers import T5EncoderModel
from PIL import Image 
import numpy as np

def get_pipeline():

    text_encoder = T5EncoderModel.from_pretrained(
        "DeepFloyd/IF-I-XL-v1.0",
        subfolder="text_encoder", 
        device_map="auto", 
        load_in_8bit=True, 
        variant="8bit"
    )

    pipe = IFImg2ImgSuperResolutionPipeline.from_pretrained(
        "DeepFloyd/IF-II-L-v1.0", 
        text_encoder=text_encoder, 
        variant="fp16", 
        torch_dtype=th.float16, 
        device_map="auto",
        watermarker=None
    )
    return pipe



def upscale_image(im, pipe):
    """im is 64x64 PIL image"""
    prompt = ''
    prompt_embeds, negative_embeds = pipe.encode_prompt(prompt)
    generator = th.Generator().manual_seed(0)

    image = pipe(
        image=original_image,
        original_image=original_image,
        prompt_embeds=prompt_embeds,
        negative_prompt_embeds=negative_embeds, 
        generator=generator,
    ).images[0]

    return image