Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,97 @@
|
|
1 |
-
|
2 |
-
import
|
|
|
|
|
|
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import modal
|
2 |
+
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
+
from io import BytesIO
|
5 |
+
import requests
|
6 |
|
7 |
+
f = modal.Cls.lookup("casa-interior-hf-v3", "DesignModel")
|
8 |
+
f_gc = modal.Cls.lookup("casa-interior-gc-v2", "GetProduct")
|
9 |
+
|
10 |
+
def casa_ai_run_tab1(image=None, text=None):
|
11 |
+
|
12 |
+
if image is None:
|
13 |
+
print('Please provide image of empty room to design')
|
14 |
+
return None
|
15 |
+
|
16 |
+
if text is None:
|
17 |
+
print('Please provide a text prompt')
|
18 |
+
return None
|
19 |
+
|
20 |
+
result_image = f.inference.remote("tab1", image, text)
|
21 |
+
return result_image
|
22 |
+
|
23 |
+
def casa_ai_run_tab2(dict=None, text=None):
|
24 |
+
|
25 |
+
image = dict["background"].convert("RGB")
|
26 |
+
mask = dict["layers"][0].convert('L')
|
27 |
+
|
28 |
+
if np.sum(np.array(mask)) == 0:
|
29 |
+
mask = None
|
30 |
+
|
31 |
+
if mask is None:
|
32 |
+
print('Please provide a mask over the object you want to generate again.')
|
33 |
+
|
34 |
+
if image is None and text is None:
|
35 |
+
print('Please provide context in form of image, text')
|
36 |
+
return None
|
37 |
+
|
38 |
+
result_image = f.inference.remote("tab2", image, text, mask)
|
39 |
+
return result_image
|
40 |
+
|
41 |
+
def casa_ai_run_tab3(dict=None):
|
42 |
+
|
43 |
+
selected_crop = dict["composite"]
|
44 |
+
|
45 |
+
if selected_crop is None:
|
46 |
+
print('Please provide cropped object')
|
47 |
+
return None
|
48 |
+
|
49 |
+
selected_crop = PIL.Image.fromarray(selected_crop).convert('RGB')
|
50 |
+
results = f_gc.inference.remote(selected_crop)
|
51 |
+
|
52 |
+
return results
|
53 |
+
|
54 |
+
with gr.Blocks() as casa:
|
55 |
+
title = "Casa-AI Demo"
|
56 |
+
description = "A Gradio interface to use CasaAI for virtual staging"
|
57 |
+
|
58 |
+
with gr.Tab("Reimagine"):
|
59 |
+
with gr.Row():
|
60 |
+
with gr.Column():
|
61 |
+
inputs = [
|
62 |
+
gr.Image(sources='upload', type="pil", label="Upload"),
|
63 |
+
gr.Textbox(label="Room description.")
|
64 |
+
]
|
65 |
+
with gr.Column():
|
66 |
+
outputs = [gr.Image(label="Generated room image")]
|
67 |
+
|
68 |
+
|
69 |
+
submit_btn = gr.Button("Generate!")
|
70 |
+
submit_btn.click(casa_ai_run_tab1, inputs=inputs, outputs=outputs)
|
71 |
+
|
72 |
+
|
73 |
+
with gr.Tab("Redesign"):
|
74 |
+
with gr.Row():
|
75 |
+
with gr.Column():
|
76 |
+
inputs = [
|
77 |
+
gr.ImageEditor(sources='upload', brush=gr.Brush(colors=["#FFFFFF"]), elem_id="image_upload", type="pil", label="Upload", layers=False, eraser=True, transforms=[]),
|
78 |
+
gr.Textbox(label="Description for redesigning masked object")]
|
79 |
+
with gr.Column():
|
80 |
+
outputs = [gr.Image(label="Image with new designed object")]
|
81 |
+
|
82 |
+
submit_btn = gr.Button("Redesign!")
|
83 |
+
submit_btn.click(casa_ai_run_tab2, inputs=inputs, outputs=outputs)
|
84 |
+
|
85 |
+
with gr.Tab("Recommendation"):
|
86 |
+
with gr.Row():
|
87 |
+
with gr.Column():
|
88 |
+
inputs = [
|
89 |
+
gr.ImageEditor(sources='upload', elem_id="image_upload", type="numpy", label="Upload", layers=False, eraser=False, brush=False, transforms=['crop']),
|
90 |
+
]
|
91 |
+
with gr.Column():
|
92 |
+
outputs = [gr.Gallery(label="Similar products")]
|
93 |
+
|
94 |
+
submit_btn = gr.Button("Find similar products!")
|
95 |
+
submit_btn.click(casa_ai_run_tab3, inputs=inputs, outputs=outputs)
|
96 |
+
|
97 |
+
casa.launch()
|