File size: 1,909 Bytes
352c33a
 
 
66c3b89
 
066186a
2b0d5d4
066186a
352c33a
 
f106b3f
 
352c33a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b6639b
352c33a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b6639b
352c33a
 
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
44
45
46
47
48
49
import torch
from PIL import Image
import gradio as gr
import os

os.system("git clone https://github.com/ai-forever/KandiSuperRes.git .")
os.system("ls")
from KandiSuperRes import sr_pipeline

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
sr_pipe2x = sr_pipeline(device=device, fp16=True, flash=True, scale=2)
sr_pipe4x = sr_pipeline(device=device, fp16=True, flash=True, scale=4)


def inference(image, size):
    if image is None:
        raise gr.Error("Image not uploaded")
    r_image = Image.open(image)
    
    if size == '2x':
        result = sr_pipe2x(lr_image)
    else:
        result = sr_pipe4x(lr_image)
            
    print(f"Image size ({device}): {size} ... OK")
    return result


title = "KandiSuperRes - diffusion model for super resolution"
description = "KandiSuperRes Flash is a new version of the diffusion model for super resolution. This model includes a distilled version of the KandiSuperRes model and a distilled model Kandinsky 3.0 Flash. KandiSuperRes Flash not only improves image clarity, but also corrects artifacts, draws details, improves image aesthetics. And one of the most important advantages is the ability to use the model in the «infinite super resolution» mode."
article = "<div style='text-align: center;'>Twitter <a href='https://twitter.com/DoEvent' target='_blank'>Max Skobeev</a> | <a href='https://huggingface.co/ai-forever/KandiSuperRes' target='_blank'>Model card</a><div>"


gr.Interface(inference,
    [gr.Image(type="pil"), 
    gr.Radio(['2x', '4x'], 
    type="value",
    value='2x',
    label='Resolution model')], 
    gr.Image(type="pil", label="Output"),
    title=title,
    description=description,
    article=article,
    examples=[['groot.jpeg', "2x"]],
    allow_flagging='never',
    cache_examples=False,
    delete_cache=(4000, 4000),
    ).queue(api_open=True).launch(show_error=True, show_api=True)