File size: 11,935 Bytes
ef5bd5d 2a5de64 ef5bd5d d6c12af ef5bd5d 1348ab7 ef5bd5d a8e3a14 ef5bd5d 25073a7 ef5bd5d 4506bf4 ef5bd5d 25073a7 ef5bd5d 25073a7 ef5bd5d 25073a7 ef5bd5d 25073a7 ef5bd5d 25073a7 ef5bd5d 25073a7 ef5bd5d 0dd9a31 ef5bd5d 25073a7 0dd9a31 ef5bd5d 25073a7 0dd9a31 25073a7 0dd9a31 ef5bd5d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
import os
from io import BytesIO
import gradio as gr
import grpc
from PIL import Image
import pandas as pd
import numpy as np
import time
from io import BytesIO
from inference_pb2 import LoraRequest, LoraResponse
from inference_pb2_grpc import LoraServiceStub
import grpc
PREFIX = "./"
info = {
'image': PREFIX + 'preview/{0}.jpg',
'weights_path': PREFIX + 'demo_results/flux-lora-{0}_aug-rank16',
'caption': PREFIX + 'demo/{0}_aug/data.csv',
'aug_path': PREFIX + 'demo/{0}_aug_filter/'
}
params = {
'cup': {'switch_t' : 7, 'aug_image' : None, 'checkpoint' : 1000},
'face_lifting': {'switch_t' : 7, 'aug_image' : None, 'checkpoint' : 1000},
'coffe_machine': {'switch_t' : 7, 'aug_image' : None, 'checkpoint' : 1000},
'kettle': {'switch_t' : 3, 'aug_image' : None, 'checkpoint' : 1000},
'body_lotion': {'switch_t' : 7, 'aug_image' : None, 'checkpoint' : 1000},
'toy': {'switch_t' : 3, 'aug_image' : None, 'checkpoint' : 1000},
'bag': {'switch_t' : 3, 'aug_image' : None, 'checkpoint' : 1000},
'armchair': {'switch_t' : 3, 'aug_image' : None, 'checkpoint' : 600},
'pendant': {'switch_t' : -1, 'aug_image' : None, 'checkpoint' : 1000},
'car': {'switch_t' : 7, 'aug_image' : 'car_aug_2.jpg', 'checkpoint' : 600},
}
table = pd.read_csv("./data.csv")
CAPTIONS = {}
for line in table.values:
print(line)
CAPTIONS[line[0]] = line[1]
def bytes_to_image(image: bytes) -> Image.Image:
image = Image.open(BytesIO(image))
return image
def generate_image(concept, prompt, progress=gr.Progress(track_tqdm=True)):
with grpc.insecure_channel(os.environ["SERVER"]) as channel:
stub = LoraServiceStub(channel)
output = stub.generate(
LoraRequest(prompt=prompt, concept=concept, use_cache=False)
)
return gr.update(value=bytes_to_image(output.res1)), gr.update(), gr.update(), gr.update()
temaplte = """
<div style="font-size: 18px;">
<b>Product description:</b> {}
</div>
"""
def action1():
concept = "kettle" #############
img = Image.open(info["image"].format(concept))
description = temaplte.format(CAPTIONS[concept])
return gr.update(value=img, visible=True), gr.update(value=description, visible=True), gr.update(visible=False), gr.update(visible=True, placeholder="in a cozy kitchen"), gr.update(visible=True), gr.update(value=concept)
def action2():
concept = "face_lifting" ###################
img = Image.open(info["image"].format(concept))
description = temaplte.format(CAPTIONS[concept])
return gr.update(value=img, visible=True), gr.update(value=description, visible=True), gr.update(visible=False), gr.update(visible=True, placeholder="in a sunny bathroom with green plants"), gr.update(visible=True), gr.update(value=concept)
def action3():
concept = "pendant" #############
img = Image.open(info["image"].format(concept))
description = temaplte.format(CAPTIONS[concept])
return gr.update(value=img, visible=True), gr.update(value=description, visible=True), gr.update(visible=False), gr.update(visible=True, placeholder="on a beautiful blonde woman"), gr.update(visible=True), gr.update(value=concept)
def action4():
concept = "car"
img = Image.open(info["image"].format(concept))
description = temaplte.format(CAPTIONS[concept])
return gr.update(value=img, visible=True), gr.update(value=description, visible=True), gr.update(visible=False), gr.update(visible=True, placeholder="driving in a desert"), gr.update(visible=True), gr.update(value=concept)
def action5():
concept = "body_lotion" #################
img = Image.open(info["image"].format(concept))
description = temaplte.format(CAPTIONS[concept])
return gr.update(value=img, visible=True), gr.update(value=description, visible=True), gr.update(visible=False), gr.update(visible=True, placeholder="in a cozy bathroom"), gr.update(visible=True), gr.update(value=concept)
def action6():
concept = "toy" ############
img = Image.open(info["image"].format(concept))
description = temaplte.format(CAPTIONS[concept])
return gr.update(value=img, visible=True), gr.update(value=description, visible=True), gr.update(visible=False), gr.update(visible=True, placeholder="in a cozy living room"), gr.update(visible=True), gr.update(value=concept)
def action7():
concept = "bag" ##############
img = Image.open(info["image"].format(concept))
description = temaplte.format(CAPTIONS[concept])
return gr.update(value=img, visible=True), gr.update(value=description, visible=True), gr.update(visible=False), gr.update(visible=True, placeholder="in a cozy living room"), gr.update(visible=True), gr.update(value=concept)
def action8():
concept = "armchair" ############
img = Image.open(info["image"].format(concept))
description = temaplte.format(CAPTIONS[concept])
return gr.update(value=img, visible=True), gr.update(value=description, visible=True), gr.update(visible=False), gr.update(visible=True, placeholder="in a cozy living room"), gr.update(visible=True), gr.update(value=concept)
css2 = """
.my-custom-button {
width: 100px; /* Button size */
height: 130px;
padding: 0; /* Remove default padding */
margin: 0px; /* Optional spacing between buttons */
display: flex;
align-items: center;
justify-content: center;
background-color: transparent;
border: none;
overflow: hidden; /* Ensures the image doesn't overflow */
--text-xl: 150px
}
.my-custom-button img {
max-width: 100%;
max-height: 100%;
object-fit: contain; /* Ensure icon scales properly */
}
.input_image_container {
width: 350px !important;
height: 350px !important;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
background-color: #f0f0f0;
}
.input_image_container img {
max-width: 100%;
max-height: 100%;
width: 350px;
height: 350px;
object-fit: contain;
display: block;
margin: 0 auto;
}
.prompt input {
font-size: 20px;
}
.prompt input::placeholder {
font-size: 20px;
}
.prompt label {
font-size: 20px !important;
}
.hint {
font-size: 20px !important;
text-align: center;
--text-md: 20px;
}
.airi-content {
display: inline-flex;
align-items: center;
gap: 10px;
white-space: nowrap;
}
.airi {
font-size: 20px;
text-align: center;
--text-md: 20px;
width: 100%;
padding: 10px 0;
}
.airi img {
vertical-align: middle;
max-height: 1.2em;
margin-left: 5px;
}
"""
def get_demo():
with gr.Blocks(css="""
.centered {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
.centered img {
margin: auto;
object-fit: contain;
}
""" + css2) as demo:
gr.Markdown("## Showcase Commercial Products with Stunning Natural Backgrounds")
with gr.Row():
with gr.Column(elem_classes=["centered"]):
with gr.Row():
btn1 = gr.Button("", icon=info["image"].format("kettle"), elem_classes=["my-custom-button"])
btn2 = gr.Button("", icon=info["image"].format("face_lifting"), elem_classes=["my-custom-button"])
btn3 = gr.Button("", icon=info["image"].format("pendant"), elem_classes=["my-custom-button"])
btn4 = gr.Button("", icon=info["image"].format("car"), elem_classes=["my-custom-button"])
with gr.Row():
btn5 = gr.Button("", icon=info["image"].format("body_lotion"), elem_classes=["my-custom-button"])
btn6 = gr.Button("", icon=info["image"].format("toy"), elem_classes=["my-custom-button"])
btn7 = gr.Button("", icon=info["image"].format("bag"), elem_classes=["my-custom-button"])
btn8 = gr.Button("", icon=info["image"].format("armchair"), elem_classes=["my-custom-button"])
# prod_desc = gr.Markdown(value="""<div style="font-size: 20px;">Choose the product you want to showcase </div"> ๐ """, visible=True)
# prod_desc = gr.Markdown(
# '<div style="font-size: 20px; text-align: center;">'
# '<span>Choose the product you want to showcase ๐ </span>'
# '</div>'
# )
prod_desc = gr.Markdown("Choose the product you want to showcase ๐ ", elem_classes=["hint"])
input_image = gr.Image(label="Chosen product", type="pil", height=300, width=300, visible=False, interactive=False, container=True, elem_classes=["input_image_container"])
descr = gr.Markdown(value=temaplte.format(""), visible=False)
concept = gr.Textbox("", visible=False)
prompt = gr.Textbox("", placeholder="is in the cozy kitchen", label="Describe the enviroment for your product", submit_btn=False, max_lines=1, visible=False, elem_classes=["prompt"])
btn_generate = gr.Button("Generate images", visible=False)
btn1.click(fn=action1, outputs=[input_image, descr, prod_desc, prompt, btn_generate, concept])
btn2.click(fn=action2, outputs=[input_image, descr, prod_desc, prompt, btn_generate, concept])
btn3.click(fn=action3, outputs=[input_image, descr, prod_desc, prompt, btn_generate, concept])
btn4.click(fn=action4, outputs=[input_image, descr, prod_desc, prompt, btn_generate, concept])
btn5.click(fn=action5, outputs=[input_image, descr, prod_desc, prompt, btn_generate, concept])
btn6.click(fn=action6, outputs=[input_image, descr, prod_desc, prompt, btn_generate, concept])
btn7.click(fn=action7, outputs=[input_image, descr, prod_desc, prompt, btn_generate, concept])
btn8.click(fn=action8, outputs=[input_image, descr, prod_desc, prompt, btn_generate, concept])
with gr.Column():
with gr.Row():
res1 = gr.Image(label="Result", visible=True)#, height=450, width=450)
res2 = gr.Image(label="Result 2", visible=False)
with gr.Row():
res3 = gr.Image(label="Result 2", visible=False, height=450, width=450)
res4 = gr.Image(label="Result 4", visible=False) #<div style="text-align: center; font-size: 18px;">
# gr.Markdown('''
# <div style="display: flex; align-items: center; gap: 10px; font-size: 20px; text-align: center; margin-left: 200px;">
# <div>Made by FusionBrainLab, AIRI</div><img src="https://static.tildacdn.com/tild3633-6662-4437-a333-646631346335/Airinet.png" style="width: 70px; height: auto;">
# </div>
# ''')
# gr.Markdown(
# '<div style="display: flex; align-items: center; gap: 10px; font-size: 20px; text-align: center; margin-left: 200px;">'
# '<span>Made by FusionBrainLab, AIRI</span>'
# '<img src="https://static.tildacdn.com/tild3633-6662-4437-a333-646631346335/Airinet.png" style="width: 70px; height: auto;">'
# '</div>'
# )
gr.Markdown(
'<span class="airi-content">Made by FusionBrainLab, AIRI <img src="https://static.tildacdn.com/tild3633-6662-4437-a333-646631346335/Airinet.png" style="width: 70px; height: auto;"></span>',
elem_classes=["airi"]
)
btn_generate.click(
fn=generate_image,
inputs=[concept, prompt],
outputs=[res1, res2, res3, res4] # font-family: Arial, sans-serif;
)
return demo
if __name__ == '__main__':
demo = get_demo()
demo.launch(server_name="0.0.0.0", server_port=7860)
|