File size: 1,596 Bytes
ba3fe1f
9d4dcc7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dabdb7e
9d4dcc7
 
 
 
 
2331805
9d4dcc7
 
 
2331805
f8c0a4c
 
9d4dcc7
 
 
 
 
ba09a50
f8c0a4c
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
import spaces
from diffusers import StableDiffusionXLInpaintPipeline
import gradio as gr
import numpy as np
import imageio
from PIL import Image
import torch
import modin.pandas as pd

device = "cuda" if torch.cuda.is_available() else "cpu"
pipe = StableDiffusionXLInpaintPipeline.from_pretrained("stabilityai/sdxl-turbo", safety_checker=None)
pipe = pipe.to(device)

def resize(value,img):
    img = Image.open(img)
    img = img.resize((value,value))
    return img

@spaces.GPU
def img2img(source_img, prompt, strength):
    imageio.imwrite("data.png", source_img['image'])
    imageio.imwrite("data_mask.png", source_img["mask"])
    src = resize(768, "data.png")
    src.save("src.png")
    mask = resize(768, "data_mask.png")  
    mask.save("mask.png")
    image = pipe(prompt=prompt, image=src, mask_image=mask, num_inference_steps=6, strength=strength, guidance_scale=0.0).images[0]
    return image
    
title="SDXLturbo CPU/GPU"
description="GoldExtra Preview OpenCV --> <b>I2I (Zeichnung > 2.5D)</b> --> "
gr.Interface(fn=img2img, inputs=[gr.Image(source="upload", tool="sketch", label="Source Image"), 
                                gr.Textbox(label='What you want the AI to Generate, 77 Token limit'),
                                gr.Slider(minimum=.5, maximum=1, value=.75, step=.025, label='Strength')], 
             outputs='image', 
             title=title, 
             description=description).launch(max_threads=True, debug=True)
             # article = "Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(max_threads=True, debug=True)