b3h-young123 commited on
Commit
9391a86
·
verified ·
1 Parent(s): cca49a8

Add files using upload-large-folder tool

Browse files
Product-Shot-Generationns/.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
Product-Shot-Generationns/README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Product Shot Generation
3
+ emoji: 📉
4
+ colorFrom: green
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: 4.40.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: other
11
+ ---
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
Product-Shot-Generationns/app.py ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+
4
+ import os
5
+ from PIL import Image
6
+ import requests
7
+ from io import BytesIO
8
+ import io
9
+ import base64
10
+
11
+ hf_token = os.environ.get("HF_TOKEN_API_DEMO") # we get it from a secret env variable, such that it's private
12
+ auth_headers = {"api_token": hf_token}
13
+
14
+ def convert_image_to_base64_string(mask_image):
15
+ buffer = io.BytesIO()
16
+ mask_image.save(buffer, format="PNG") # You can choose the format (e.g., "JPEG", "PNG")
17
+ # Encode the buffer in base64
18
+ image_base64_string = base64.b64encode(buffer.getvalue()).decode('utf-8')
19
+ return f",{image_base64_string}" # for some reason the funciton which downloads image from base64 expects prefix of "," which is redundant in the url
20
+
21
+ def download_image(url):
22
+ response = requests.get(url)
23
+ img_bytes = BytesIO(response.content)
24
+ return Image.open(img_bytes).convert("RGB")
25
+
26
+ def lifestyle_shot_by_text_api_call(image_base64_file, prompt):
27
+
28
+ url = "http://engine.prod.bria-api.com/v1/product/lifestyle_shot_by_text"
29
+
30
+ payload = {
31
+ "file": image_base64_file,
32
+ "scene_description": prompt,
33
+ "num_results": 1,
34
+ "sync": True,
35
+ "original_quality": True,
36
+ "optimize_description": True,
37
+ }
38
+ response = requests.post(url, json=payload, headers=auth_headers)
39
+ response = response.json()
40
+ res_image = download_image(response['result'][0][0])
41
+
42
+ return res_image
43
+
44
+
45
+ def predict_ref_by_text(input_image, prompt):
46
+
47
+ # init_image = Image.fromarray(dict['background'][:, :, :3], 'RGB') #dict['background'].convert("RGB")#.resize((1024, 1024))
48
+ # mask = Image.fromarray(dict['layers'][0][:,:,3], 'L') #dict['layers'].convert("RGB")#.resize((1024, 1024))
49
+
50
+ image_base64_file = convert_image_to_base64_string(input_image)
51
+
52
+ gen_img = lifestyle_shot_by_text_api_call(image_base64_file, prompt)
53
+
54
+ return gen_img
55
+
56
+
57
+ def lifestyle_shot_by_image_api_call(image_base64_file, ref_image_base64_file):
58
+
59
+ url = "http://engine.prod.bria-api.com/v1/product/lifestyle_shot_by_image"
60
+
61
+ payload = {
62
+ "file": image_base64_file,
63
+ "ref_image_file": ref_image_base64_file,
64
+ "num_results": 1,
65
+ "sync": True,
66
+ "original_quality": True,
67
+ "optimize_description": True,
68
+ }
69
+ response = requests.post(url, json=payload, headers=auth_headers)
70
+ response = response.json()
71
+ res_image = download_image(response['result'][0][0])
72
+
73
+ return res_image
74
+
75
+
76
+ def predict_ref_by_image(init_image, ref_image):
77
+
78
+ image_base64_file = convert_image_to_base64_string(init_image)
79
+ ref_base64_file = convert_image_to_base64_string(ref_image)
80
+
81
+ gen_img = lifestyle_shot_by_image_api_call(image_base64_file, ref_base64_file)
82
+
83
+ return gen_img
84
+
85
+ def on_change_prompt(img: Image.Image | None, prompt: str | None):
86
+ return gr.update(interactive=bool(img and prompt))
87
+
88
+ css = '''
89
+ .gradio-container{max-width: 1100px !important}
90
+ #image_upload{min-height:400px}
91
+ #image_upload [data-testid="image"], #image_upload [data-testid="image"] > div{min-height: 400px}
92
+ #mask_radio .gr-form{background:transparent; border: none}
93
+ #word_mask{margin-top: .75em !important}
94
+ #word_mask textarea:disabled{opacity: 0.3}
95
+ .footer {margin-bottom: 45px;margin-top: 35px;text-align: center;border-bottom: 1px solid #e5e5e5}
96
+ .footer>p {font-size: .8rem; display: inline-block; padding: 0 10px;transform: translateY(10px);background: white}
97
+ .dark .footer {border-color: #303030}
98
+ .dark .footer>p {background: #0b0f19}
99
+ .acknowledgments h4{margin: 1.25em 0 .25em 0;font-weight: bold;font-size: 115%}
100
+ #image_upload .touch-none{display: flex}
101
+ @keyframes spin {
102
+ from {
103
+ transform: rotate(0deg);
104
+ }
105
+ to {
106
+ transform: rotate(360deg);
107
+ }
108
+ }
109
+ #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;}
110
+ div#share-btn-container > div {flex-direction: row;background: black;align-items: center}
111
+ #share-btn-container:hover {background-color: #060606}
112
+ #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;}
113
+ #share-btn * {all: unset}
114
+ #share-btn-container div:nth-child(-n+2){width: auto !important;min-height: 0px !important;}
115
+ #share-btn-container .wrap {display: none !important}
116
+ #share-btn-container.hidden {display: none!important}
117
+ #prompt input{width: calc(100% - 160px);border-top-right-radius: 0px;border-bottom-right-radius: 0px;}
118
+ #run_button {
119
+ width: 100%;
120
+ height: 50px; /* Set a fixed height for the button */
121
+ display: flex;
122
+ align-items: center;
123
+ justify-content: center;
124
+ }
125
+ #output-img img, #image_upload img {
126
+ object-fit: contain; /* Ensure aspect ratio is preserved */
127
+ width: 100%;
128
+ height: auto; /* Let height adjust automatically */
129
+ }
130
+ #prompt-container{margin-top:-18px;}
131
+ #prompt-container .form{border-top-left-radius: 0;border-top-right-radius: 0}
132
+ #image_upload{border-bottom-left-radius: 0px;border-bottom-right-radius: 0px}
133
+ '''
134
+
135
+ image_blocks = gr.Blocks(css=css, elem_id="total-container")
136
+ with image_blocks as demo:
137
+ # with gr.Column(elem_id="col-container"):
138
+ gr.Markdown("## Product Shot Generation")
139
+ gr.HTML('''
140
+ <p style="margin-bottom: 10px; font-size: 94%">
141
+ This demo showcases the <strong>Lifestyle Product Shot by Text</strong> and <strong>Lifestyle Product Shot by Image</strong> feature, enabling users to generate product backgrounds effortlessly.<br>
142
+ With <strong>Lifestyle Product Shot by Text</strong>, users can create backgrounds using descriptive textual prompts,
143
+ while <strong>Lifestyle Product Shot by Image</strong> allows backgrounds to be generated based on a reference image for inspiration.<br>
144
+ The pipeline comprises multiple components, including <a href="https://huggingface.co/briaai/BRIA-2.3" target="_blank">briaai/BRIA-2.3</a>,
145
+ <a href="https://huggingface.co/briaai/RMBG-2.0" target="_blank">briaai/RMBG-2.0</a>, <a href="https://huggingface.co/briaai/BRIA-2.3-ControlNet-BG-Gen" target="_blank">briaai/BRIA-2.3-ControlNet-BG-Gen</a> and
146
+ <a href="https://huggingface.co/briaai/Image-Prompt" target="_blank">briaai/Image-Prompt</a>, all trained on licensed data.<br>
147
+ This ensures full legal liability coverage for copyright and privacy infringement.<br>
148
+ Notes:<br>
149
+ - High-resolution images may take longer to process.<br>
150
+ - For best results in reference by image: make sure the foreground in the image is already located in the wanted position and scale, relative to the elements in the reference image.<br>
151
+ </p>
152
+ ''')
153
+ with gr.Tab(label="By scene description", id="tab_prompt"):
154
+
155
+ with gr.Row():
156
+ with gr.Column():
157
+ # image = gr.ImageEditor(sources=["upload"], layers=False, transforms=[],
158
+ # brush=gr.Brush(colors=["#000000"], color_mode="fixed"),
159
+ # )
160
+ image = gr.Image(type="pil", label="Input")
161
+ prompt = gr.Textbox(label="scene description", placeholder="Enter your scene description here...")
162
+ with gr.Row(elem_id="prompt-container", equal_height=True):
163
+ with gr.Column():
164
+ btn = gr.Button("Generate Product Shot!", elem_id="run_button")
165
+
166
+ with gr.Column():
167
+ image_out = gr.Image(label="Output", elem_id="output-img")
168
+
169
+ # Button click will trigger the inpainting function (now with prompt included)
170
+ for inp in [image, prompt]:
171
+ inp.change(
172
+ fn=on_change_prompt,
173
+ inputs=[image, prompt],
174
+ outputs=[btn],
175
+ )
176
+ btn.click(fn=predict_ref_by_text, inputs=[image, prompt], outputs=[image_out], api_name='run')
177
+
178
+ with gr.Tab(label="By reference image", id="tab_ref_image"):
179
+
180
+ with gr.Row():
181
+ with gr.Column():
182
+ image = gr.Image(type="pil", label="Input")
183
+ ref_image = gr.Image(type="pil", label="Reference Image")
184
+ with gr.Row(elem_id="prompt-container", equal_height=True):
185
+ with gr.Column():
186
+ btn = gr.Button("Generate Product Shot!", elem_id="run_button")
187
+
188
+ with gr.Column():
189
+ image_out = gr.Image(label="Output", elem_id="output-img")
190
+
191
+ # Button click will trigger the inpainting function (now with prompt included)
192
+ btn.click(fn=predict_ref_by_image, inputs=[image, ref_image], outputs=[image_out], api_name='run')
193
+
194
+ gr.HTML(
195
+ """
196
+ <div class="footer">
197
+ <p>Model by <a href="https://huggingface.co/diffusers" style="text-decoration: underline;" target="_blank">Diffusers</a> - Gradio Demo by 🤗 Hugging Face
198
+ </p>
199
+ </div>
200
+ """
201
+ )
202
+
203
+ image_blocks.queue(max_size=25, api_open=False).launch(show_api=False)
Product-Shot-Generationns/requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ pillow==10.3.0