Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,97 +11,19 @@ def casa_ai_run(image=None, text=None):
|
|
11 |
result_image = f.inference.remote(image, text)
|
12 |
return result_image
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
import gradio as gr
|
33 |
-
|
34 |
-
def read_content(file_path: str) -> str:
|
35 |
-
"""read the content of target file
|
36 |
-
"""
|
37 |
-
with open(file_path, 'r', encoding='utf-8') as f:
|
38 |
-
content = f.read()
|
39 |
-
|
40 |
-
return content
|
41 |
-
|
42 |
-
def predict(dict, prompt=""):
|
43 |
-
|
44 |
-
init_image = dict["image"].convert("RGB")
|
45 |
-
mask = dict["mask"].convert("RGB")
|
46 |
-
|
47 |
-
output = casa_ai_run(init_image, prompt)
|
48 |
-
|
49 |
-
return output.images[0], gr.update(visible=True)
|
50 |
-
|
51 |
-
|
52 |
-
css = '''
|
53 |
-
.gradio-container{max-width: 1100px !important}
|
54 |
-
#image_upload{min-height:400px}
|
55 |
-
#image_upload [data-testid="image"], #image_upload [data-testid="image"] > div{min-height: 400px}
|
56 |
-
#mask_radio .gr-form{background:transparent; border: none}
|
57 |
-
#word_mask{margin-top: .75em !important}
|
58 |
-
#word_mask textarea:disabled{opacity: 0.3}
|
59 |
-
.footer {margin-bottom: 45px;margin-top: 35px;text-align: center;border-bottom: 1px solid #e5e5e5}
|
60 |
-
.footer>p {font-size: .8rem; display: inline-block; padding: 0 10px;transform: translateY(10px);background: white}
|
61 |
-
.dark .footer {border-color: #303030}
|
62 |
-
.dark .footer>p {background: #0b0f19}
|
63 |
-
.acknowledgments h4{margin: 1.25em 0 .25em 0;font-weight: bold;font-size: 115%}
|
64 |
-
#image_upload .touch-none{display: flex}
|
65 |
-
@keyframes spin {
|
66 |
-
from {
|
67 |
-
transform: rotate(0deg);
|
68 |
-
}
|
69 |
-
to {
|
70 |
-
transform: rotate(360deg);
|
71 |
-
}
|
72 |
-
}
|
73 |
-
#share-btn-container {padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; max-width: 13rem; margin-left: auto;}
|
74 |
-
div#share-btn-container > div {flex-direction: row;background: black;align-items: center}
|
75 |
-
#share-btn-container:hover {background-color: #060606}
|
76 |
-
#share-btn {all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.5rem !important; padding-bottom: 0.5rem !important;right:0;}
|
77 |
-
#share-btn * {all: unset}
|
78 |
-
#share-btn-container div:nth-child(-n+2){width: auto !important;min-height: 0px !important;}
|
79 |
-
#share-btn-container .wrap {display: none !important}
|
80 |
-
#share-btn-container.hidden {display: none!important}
|
81 |
-
#prompt input{width: calc(100% - 160px);border-top-right-radius: 0px;border-bottom-right-radius: 0px;}
|
82 |
-
#run_button{position:absolute;margin-top: 11px;right: 0;margin-right: 0.8em;border-bottom-left-radius: 0px;
|
83 |
-
border-top-left-radius: 0px;}
|
84 |
-
#prompt-container{margin-top:-18px;}
|
85 |
-
#prompt-container .form{border-top-left-radius: 0;border-top-right-radius: 0}
|
86 |
-
#image_upload{border-bottom-left-radius: 0px;border-bottom-right-radius: 0px}
|
87 |
-
'''
|
88 |
-
|
89 |
-
image_blocks = gr.Blocks(css=css, elem_id="total-container")
|
90 |
-
with image_blocks as demo:
|
91 |
-
gr.HTML(read_content("header.html"))
|
92 |
-
with gr.Row():
|
93 |
-
with gr.Column():
|
94 |
-
image = gr.ImageEditor(sources='upload', brush=gr.Brush(colors=["#000000"]), elem_id="image_upload", type="pil", label="Upload")
|
95 |
-
with gr.Row(elem_id="prompt-container", equal_height=True):
|
96 |
-
with gr.Row():
|
97 |
-
prompt = gr.Textbox(placeholder="Your prompt (what you want in place of what is erased)", show_label=False, elem_id="prompt")
|
98 |
-
btn = gr.Button("Inpaint!", elem_id="run_button")
|
99 |
-
|
100 |
-
with gr.Column():
|
101 |
-
image_out = gr.Image(label="Output", elem_id="output-img")
|
102 |
-
|
103 |
-
btn.click(fn=predict, inputs=[image, prompt], outputs=[image_out], api_name='run')
|
104 |
-
prompt.submit(fn=predict, inputs=[image, prompt], outputs=[image_out])
|
105 |
-
|
106 |
-
|
107 |
-
image_blocks.queue(max_size=25,api_open=False).launch(show_api=False)
|
|
|
11 |
result_image = f.inference.remote(image, text)
|
12 |
return result_image
|
13 |
|
14 |
+
import gradio as gr
|
15 |
+
|
16 |
+
title = "Casa-AI Demo"
|
17 |
+
description = "A Gradio interface to use CasaAI for virtual staging"
|
18 |
+
|
19 |
+
demo = gr.Interface(casa_ai_run,
|
20 |
+
inputs = [gr.ImageEditor(sources='upload', brush=gr.Brush(colors=["#000000"]), elem_id="image_upload", type="pil", label="Upload")
|
21 |
+
gr.Textbox(label="Prompt to design room"),
|
22 |
+
],
|
23 |
+
outputs = [
|
24 |
+
gr.Image(label="Generated room image"),
|
25 |
+
],
|
26 |
+
title = title,
|
27 |
+
description = description,
|
28 |
+
)
|
29 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|