Commit
·
d4d1341
1
Parent(s):
49d0ea2
image input fix, button try to fix
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ import base64
|
|
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
|
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
|
@@ -48,7 +48,7 @@ def predict_ref_by_text(input_image, prompt):
|
|
48 |
# init_image = Image.fromarray(dict['background'][:, :, :3], 'RGB') #dict['background'].convert("RGB")#.resize((1024, 1024))
|
49 |
# mask = Image.fromarray(dict['layers'][0][:,:,3], 'L') #dict['layers'].convert("RGB")#.resize((1024, 1024))
|
50 |
|
51 |
-
image_base64_file =
|
52 |
|
53 |
gen_img = lifestyle_shot_by_text_api_call(image_base64_file, prompt)
|
54 |
|
@@ -77,13 +77,15 @@ def lifestyle_shot_by_image_api_call(image_base64_file, ref_image_base64_file):
|
|
77 |
|
78 |
def predict_ref_by_image(init_image, ref_image):
|
79 |
|
80 |
-
image_base64_file =
|
81 |
-
ref_base64_file =
|
82 |
|
83 |
gen_img = lifestyle_shot_by_image_api_call(image_base64_file, ref_base64_file)
|
84 |
|
85 |
return gen_img
|
86 |
|
|
|
|
|
87 |
|
88 |
css = '''
|
89 |
.gradio-container{max-width: 1100px !important}
|
@@ -151,9 +153,10 @@ with image_blocks as demo:
|
|
151 |
|
152 |
with gr.Row():
|
153 |
with gr.Column():
|
154 |
-
image = gr.ImageEditor(sources=["upload"], layers=False, transforms=[],
|
155 |
-
brush=gr.Brush(colors=["#000000"], color_mode="fixed"),
|
156 |
-
)
|
|
|
157 |
prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
|
158 |
with gr.Row(elem_id="prompt-container", equal_height=True):
|
159 |
with gr.Column():
|
@@ -163,15 +166,22 @@ with image_blocks as demo:
|
|
163 |
image_out = gr.Image(label="Output", elem_id="output-img")
|
164 |
|
165 |
# Button click will trigger the inpainting function (now with prompt included)
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
btn.click(fn=predict_ref_by_text, inputs=[image, prompt], outputs=[image_out], api_name='run')
|
167 |
|
168 |
with gr.Tab(label="By image reference", id="tab_ref_image"):
|
169 |
|
170 |
with gr.Row():
|
171 |
with gr.Column():
|
172 |
-
image = gr.ImageEditor(sources=["upload"], layers=False, transforms=[],
|
173 |
-
brush=gr.Brush(colors=["#000000"], color_mode="fixed"),
|
174 |
-
)
|
|
|
175 |
ref_image = gr.ImageEditor(sources=["upload"], layers=False, transforms=[],
|
176 |
brush=gr.Brush(colors=["#000000"], color_mode="fixed"),
|
177 |
)
|
|
|
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
|
|
|
48 |
# init_image = Image.fromarray(dict['background'][:, :, :3], 'RGB') #dict['background'].convert("RGB")#.resize((1024, 1024))
|
49 |
# mask = Image.fromarray(dict['layers'][0][:,:,3], 'L') #dict['layers'].convert("RGB")#.resize((1024, 1024))
|
50 |
|
51 |
+
image_base64_file = convert_image_to_base64_string(input_image)
|
52 |
|
53 |
gen_img = lifestyle_shot_by_text_api_call(image_base64_file, prompt)
|
54 |
|
|
|
77 |
|
78 |
def predict_ref_by_image(init_image, ref_image):
|
79 |
|
80 |
+
image_base64_file = convert_image_to_base64_string(init_image)
|
81 |
+
ref_base64_file = convert_image_to_base64_string(ref_image)
|
82 |
|
83 |
gen_img = lifestyle_shot_by_image_api_call(image_base64_file, ref_base64_file)
|
84 |
|
85 |
return gen_img
|
86 |
|
87 |
+
def on_change_prompt(img: Image.Image | None, prompt: str | None):
|
88 |
+
return gr.update(interactive=bool(img and prompt))
|
89 |
|
90 |
css = '''
|
91 |
.gradio-container{max-width: 1100px !important}
|
|
|
153 |
|
154 |
with gr.Row():
|
155 |
with gr.Column():
|
156 |
+
# image = gr.ImageEditor(sources=["upload"], layers=False, transforms=[],
|
157 |
+
# brush=gr.Brush(colors=["#000000"], color_mode="fixed"),
|
158 |
+
# )
|
159 |
+
image = gr.Image(type="pil", label="Input")
|
160 |
prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
|
161 |
with gr.Row(elem_id="prompt-container", equal_height=True):
|
162 |
with gr.Column():
|
|
|
166 |
image_out = gr.Image(label="Output", elem_id="output-img")
|
167 |
|
168 |
# Button click will trigger the inpainting function (now with prompt included)
|
169 |
+
for inp in [image, prompt]:
|
170 |
+
inp.change(
|
171 |
+
fn=on_change_prompt,
|
172 |
+
inputs=[image, prompt],
|
173 |
+
outputs=[btn],
|
174 |
+
)
|
175 |
btn.click(fn=predict_ref_by_text, inputs=[image, prompt], outputs=[image_out], api_name='run')
|
176 |
|
177 |
with gr.Tab(label="By image reference", id="tab_ref_image"):
|
178 |
|
179 |
with gr.Row():
|
180 |
with gr.Column():
|
181 |
+
# image = gr.ImageEditor(sources=["upload"], layers=False, transforms=[],
|
182 |
+
# brush=gr.Brush(colors=["#000000"], color_mode="fixed"),
|
183 |
+
# )
|
184 |
+
image = gr.Image(type="pil", label="Input")
|
185 |
ref_image = gr.ImageEditor(sources=["upload"], layers=False, transforms=[],
|
186 |
brush=gr.Brush(colors=["#000000"], color_mode="fixed"),
|
187 |
)
|