RyanHangZhou commited on
Commit
fac3291
·
verified ·
1 Parent(s): 1c845e8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+
4
+ def pics_pairwise_inference(bg, obj_a_data, obj_b_data):
5
+ """
6
+ Main inference function for PICS (Pairwise Image Compositing).
7
+ Handles the spatial interactions between two objects (A and B) and the background.
8
+ """
9
+ # Extract Image and Mask for Object A
10
+ # The 'layers' attribute contains the mask drawn/uploaded by the user
11
+ img_a = obj_a_data["background"]
12
+ mask_a = obj_a_data["layers"][0] if obj_a_data["layers"] else None
13
+
14
+ # Extract Image and Mask for Object B
15
+ img_b = obj_b_data["background"]
16
+ mask_b = obj_b_data["layers"][0] if obj_b_data["layers"] else None
17
+
18
+ # Backend Integration: This is where we call the core PICS logic tomorrow
19
+ # e.g., result = pics_model.infer(bg, (img_a, mask_a), (img_b, mask_b))
20
+
21
+ # Placeholder: Returning background to verify the pipeline
22
+ return bg
23
+
24
+ # Define the Gradio Blocks Layout
25
+ with gr.Blocks(title="PICS: Pairwise Image Compositing") as demo:
26
+ gr.Markdown("# 🚀 PICS: Pairwise Image Compositing with Spatial Interactions")
27
+ gr.Markdown("Interactive demo for **Pairwise** spatial reasoning. Please upload objects and draw/upload their respective masks.")
28
+
29
+ with gr.Row():
30
+ with gr.Column(scale=2):
31
+ # Input Section 1: Background Scene
32
+ bg_input = gr.Image(label="1. Scene Background", type="pil")
33
+
34
+ with gr.Row():
35
+ # Input Section 2: Object A with Interactive Masking
36
+ with gr.Column():
37
+ obj_a_input = gr.ImageEditor(
38
+ label="2. Object A (Image + Mask)",
39
+ type="pil",
40
+ layers=True, # Allows users to draw masks directly
41
+ canvas_size=(512, 512)
42
+ )
43
+ # Input Section 3: Object B with Interactive Masking
44
+ with gr.Column():
45
+ obj_b_input = gr.ImageEditor(
46
+ label="3. Object B (Image + Mask)",
47
+ type="pil",
48
+ layers=True,
49
+ canvas_size=(512, 512)
50
+ )
51
+
52
+ # Action Button
53
+ run_btn