tolgacangoz commited on
Commit
d25e2f8
1 Parent(s): dc89c85

Add requirements.txt and improve app.py

Browse files
Files changed (2) hide show
  1. app.py +31 -2
  2. requirements.txt +8 -0
app.py CHANGED
@@ -1,7 +1,36 @@
1
  import gradio as gr
 
 
 
 
 
 
 
2
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from rembg import remove, new_session
3
+ import cv2
4
+ import numpy as np
5
+ import PIL
6
+ import torch
7
+ from diffusers import StableDiffusionInpaintPipeline
8
+
9
 
10
  def greet(name):
11
  return "Hello " + name + "!!"
12
 
13
+ iface = gr.Interface(fn=greet,
14
+ inputs=[gr.inputs.Image(label='Upload the product'), gr.inputs.Textbox(label='Enter the prompt')],
15
+ outputs=gr.outputs.Image(label='Result'),
16
+ title='Product placement with background change'
17
+ )
18
+ iface.launch()
19
+
20
+ """
21
+ input_path = 'c.png'
22
+ input = cv2.cvtColor(cv2.imread(input_path), cv2.COLOR_BGR2RGB)
23
+ mask = remove(input, session=new_session('u2net'), only_mask=True)
24
+ mask = cv2.bitwise_not(mask)
25
+ #plt.imshow(mask)
26
+
27
+ pipeline = StableDiffusionInpaintPipeline.from_pretrained(
28
+ "stabilityai/stable-diffusion-2-inpainting", #runwayml/stable-diffusion-inpainting
29
+ torch_dtype=torch.float16,
30
+ )
31
+ pipeline = pipeline.to("cuda")
32
+ init_image = PIL.Image.open(input_path).convert("RGB").resize((512, 512))
33
+ mask_image = PIL.Image.fromarray(np.uint8(mask)).convert('RGB').resize((512, 512))
34
+ prompt = "colorful particles, high resolution, a yellow cat, 8K"
35
+ image = pipeline(prompt=prompt, image=init_image, mask_image=mask_image).images[0]
36
+ """
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ rembg
2
+ diffusers
3
+ transformers
4
+ accelerate
5
+ opencv-python
6
+ numpy
7
+ Pillow
8
+ torch