sharonadhitya commited on
Commit
a491da1
·
1 Parent(s): 1b68567

Add Yahoo model Image generation

Browse files
Files changed (2) hide show
  1. app.py +31 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import DiffusionPipeline
3
+ from PIL import Image
4
+
5
+ # Load model (will be cached in the Space, not your local GPU)
6
+ pipe = DiffusionPipeline.from_pretrained(
7
+ "yahoo-inc/photo-background-generation", torch_dtype="float16"
8
+ ).to("cuda")
9
+
10
+ def generate_background(image, mask, prompt):
11
+ result = pipe(
12
+ image=image,
13
+ mask_image=mask,
14
+ prompt=prompt,
15
+ output_type="pil"
16
+ ).images[0]
17
+ return result
18
+
19
+ demo = gr.Interface(
20
+ fn=generate_background,
21
+ inputs=[
22
+ gr.Image(type="pil", label="Input Image"),
23
+ gr.Image(type="pil", label="Frame Mask (white = frame)"),
24
+ gr.Textbox(label="Prompt")
25
+ ],
26
+ outputs=gr.Image(type="pil", label="Generated Image"),
27
+ title="Salient Object-Aware Background Generation",
28
+ description="Upload an image with a frame, its mask, and describe how the background should look."
29
+ )
30
+
31
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ diffusers==0.14.0
2
+ transformers==4.28.1
3
+ accelerate==0.19.0
4
+ torch
5
+ opencv-python
6
+ gradio