tonyassi commited on
Commit
f8f6f88
·
verified ·
1 Parent(s): 1785492

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -2
app.py CHANGED
@@ -1,3 +1,46 @@
1
- import os
 
 
 
 
2
 
3
- exec(os.environ.get('CODE'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import gradio as gr
3
+ from PIL import Image
4
+ from diffusers import StableDiffusionImg2ImgPipeline
5
+ import torch
6
 
7
+ model_id_or_path = os.environ.get('MODEL')
8
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16,safety_checker=None, use_safetensors=True)
9
+ pipe = pipe.to('cuda')
10
+
11
+ @spaces.GPU(enable_queue=True)
12
+ def generate(image_editor):
13
+ init_image = image_editor['composite'].convert('RGB')
14
+ #img = handle_image_to_image(init_image, prompt='photorealistic, fashion model', negative_prompt='mannequin, sketch, drawing')
15
+
16
+ init_image.thumbnail((1024, 1024))
17
+ prompt = "photorealistic, fashion model"
18
+ 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'
19
+
20
+ pipe.to('cuda')
21
+ images = pipe(prompt=prompt, image=init_image, strength=0.65, guidance_scale=7.5,negative_prompt=negative_prompt).images
22
+ img = images[0]
23
+
24
+ return img
25
+
26
+
27
+ 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=[]),
28
+ #gr.Textbox(label="Prompt", value="photorealistic, fashion model", visible=False),
29
+ #gr.Textbox(label="Negative Prompt", value='mannequin, sketch, drawing', visible=False)
30
+ ],
31
+ outputs=gr.Image(label="Output Image"),
32
+ title="Sketch to Fashion Design",
33
+ description="""
34
+ by [Tony Assi](https://www.tonyassi.com/)
35
+
36
+ Please ❤️ this Space.
37
+
38
+ I build custom AI apps for companies. <a href="mailto: [email protected]">Email me</a> for business inquiries.
39
+ """,
40
+ api_name=False,
41
+ theme = gr.themes.Base(primary_hue="teal",secondary_hue="teal",neutral_hue="slate"),
42
+ cache_examples=True,
43
+ 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'}]])
44
+
45
+
46
+ iface.launch()