File size: 2,640 Bytes
f8f6f88
 
 
 
 
e36aacc
f8f6f88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import spaces
import gradio as gr
from PIL import Image
from diffusers import StableDiffusionImg2ImgPipeline
import torch

model_id_or_path = os.environ.get('MODEL')
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16,safety_checker=None, use_safetensors=True)
pipe = pipe.to('cuda')

@spaces.GPU(enable_queue=True)
def generate(image_editor):
    init_image = image_editor['composite'].convert('RGB')
    #img = handle_image_to_image(init_image, prompt='photorealistic, fashion model', negative_prompt='mannequin, sketch, drawing')

    init_image.thumbnail((1024, 1024))
    prompt = "photorealistic, fashion model"
    negative_prompt='mannequin, sketch, drawing, animated, anime, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, bad anatomy, watermark, signature, cut off, low contrast, underexposed, overexposed, bad art, beginner, amateur, distorted face, deformed face, blurry, draft, grainy'

    pipe.to('cuda')
    images = pipe(prompt=prompt, image=init_image, strength=0.65, guidance_scale=7.5,negative_prompt=negative_prompt).images
    img = images[0]
    
    return img


iface = gr.Interface(fn=generate, inputs=[gr.ImageEditor(label='Sketchpad' ,type='pil', height=700, value={'background':'./sketch1.png', 'layers':None, 'composite':None}, sources=['upload'], transforms=[]), 
                                          #gr.Textbox(label="Prompt", value="photorealistic, fashion model", visible=False), 
                                          #gr.Textbox(label="Negative Prompt", value='mannequin, sketch, drawing', visible=False)
                                         ], 
                     outputs=gr.Image(label="Output Image"), 
                     title="Sketch to Fashion Design", 
                     description="""
                     by [Tony Assi](https://www.tonyassi.com/)

                     Please โค๏ธ this Space.
        
                    I build custom AI apps for companies. <a href="mailto: tony.assi.media@gmail.com">Email me</a> for business inquiries.
                     """,
                    api_name=False,
                    theme = gr.themes.Base(primary_hue="teal",secondary_hue="teal",neutral_hue="slate"),
                    cache_examples=True,
                    examples=[[{'background':'./example1.png', 'layers':None, 'composite':'./example1.png'}], [{'background':'./example2.png', 'layers':None, 'composite':'./example2.png'}],[{'background':'./sketch1.png', 'layers':None, 'composite':'./sketch1.png'}]])


iface.launch()