Casa-AI / app.py
LN1996's picture
Update app.py
bfe0a04 verified
raw
history blame
3.75 kB
import modal
import gradio as gr
import numpy as np
f = modal.Cls.lookup("casa-interior-hf-v3", "DesignModel")
def casa_ai_run_tab1(image=None, prompt=None):
if image is None and text is None:
print('Please provide context in form of image, text')
return None
result_image = f.inference.remote("tab1", image, text)
return result_image
def casa_ai_run_tab2(dict=None, text=None):
image = dict["background"].convert("RGB")
mask = dict["layers"][0].convert('L')
if np.sum(np.array(mask)) == 0:
mask = None
if mask is None:
print('Please provide a mask over the object you want to generate again.')
if image is None and text is None:
print('Please provide context in form of image, text')
return None
result_image = f.inference.remote("tab2", image, text, mask)
return result_image
def casa_ai_run_tab3(dict=None, text=None):
image = dict["background"].convert("RGB")
mask = dict["layers"][0].convert('L')
if image is None and text is None:
print('Please provide context in form of image, text')
return None
result_image = f.inference.remote("tab3", image, text, mask)
return result_image
with gr.Blocks() as casa:
title = "Casa-AI Demo"
description = "A Gradio interface to use CasaAI for virtual staging"
with gr.Tab("ReImagine"):
with gr.Row():
with gr.Column():
inputs = [
gr.Image(sources='upload', type="pil", label="Upload"),
gr.Textbox(label="Prompt to design room")]
with gr.Column():
outputs = [gr.Image(label="Generated room image")]
submit_btn = gr.Button("Generate")
submit_btn.click(casa_ai_run_tab1, inputs=inputs, outputs=outputs)
with gr.Tab("ReDesign"):
with gr.Row():
with gr.Column():
inputs = [
gr.ImageEditor(sources='upload', brush=gr.Brush(colors=["#FFFFFF"]), elem_id="image_upload", type="pil", label="Upload", layers=False, eraser=True, transforms=[]),
gr.Textbox(label="Prompt for redesigning masked object")]
with gr.Column():
outputs = [gr.Image(label="Image with new designed object")]
submit_btn = gr.Button("Generate")
submit_btn.click(casa_ai_run_tab2, inputs=inputs, outputs=outputs)
with gr.Tab("Recommendation"):
with gr.Row():
with gr.Column():
inputs = [
gr.ImageEditor(sources='upload', brush=gr.Brush(colors=["#FFFFFF"]), elem_id="image_upload", type="pil", label="Upload", layers=False, eraser=True, transforms=[]),
]
with gr.Column():
outputs = [gr.Image(label="Image with new designed object")]
submit_btn = gr.Button("Show similar objects")
submit_btn.click(casa_ai_run_tab3, inputs=inputs, outputs=outputs)
casa.launch()
# demo = gr.Interface(casa_ai_run,
# inputs = [gr.ImageEditor(sources='upload', brush=gr.Brush(colors=["#FFFFFF"]), elem_id="image_upload", type="pil", label="Upload", layers=False, eraser=True, transforms=[]),
# gr.Textbox(label="Prompt to design room"),
# ],
# outputs = [
# gr.Image(label="Generated room image"),
# ],
# title = title,
# description = description,
# )
# demo.launch()