Spaces:
Running
on
Zero
Running
on
Zero
one more test with user HF_TOKEN
Browse files
app.py
CHANGED
@@ -23,52 +23,6 @@ IMAGE_SIZE = 1024
|
|
23 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
24 |
PIPE = FluxInpaintPipeline.from_pretrained(
|
25 |
"black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16).to(DEVICE)
|
26 |
-
CLIENT = Client("SkalskiP/florence-sam-masking")
|
27 |
-
|
28 |
-
|
29 |
-
# def remove_background(image: Image.Image, threshold: int = 50) -> Image.Image:
|
30 |
-
# image = image.convert("RGBA")
|
31 |
-
# data = image.getdata()
|
32 |
-
# new_data = []
|
33 |
-
# for item in data:
|
34 |
-
# avg = sum(item[:3]) / 3
|
35 |
-
# if avg < threshold:
|
36 |
-
# new_data.append((0, 0, 0, 0))
|
37 |
-
# else:
|
38 |
-
# new_data.append(item)
|
39 |
-
#
|
40 |
-
# image.putdata(new_data)
|
41 |
-
# return image
|
42 |
-
|
43 |
-
|
44 |
-
# EXAMPLES = [
|
45 |
-
# [
|
46 |
-
# {
|
47 |
-
# "background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
|
48 |
-
# "layers": [remove_background(Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-mask-2.png", stream=True).raw))],
|
49 |
-
# "composite": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-composite-2.png", stream=True).raw),
|
50 |
-
# },
|
51 |
-
# "little lion",
|
52 |
-
# None,
|
53 |
-
# 42,
|
54 |
-
# False,
|
55 |
-
# 0.85,
|
56 |
-
# 30
|
57 |
-
# ],
|
58 |
-
# [
|
59 |
-
# {
|
60 |
-
# "background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
|
61 |
-
# "layers": [remove_background(Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-mask-3.png", stream=True).raw))],
|
62 |
-
# "composite": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-composite-3.png", stream=True).raw),
|
63 |
-
# },
|
64 |
-
# "tattoos",
|
65 |
-
# None,
|
66 |
-
# 42,
|
67 |
-
# False,
|
68 |
-
# 0.85,
|
69 |
-
# 30
|
70 |
-
# ]
|
71 |
-
# ]
|
72 |
|
73 |
|
74 |
def calculate_image_dimensions_for_flux(
|
@@ -193,7 +147,7 @@ def process(
|
|
193 |
return None, None
|
194 |
|
195 |
if is_mask_empty(mask):
|
196 |
-
mask =
|
197 |
image_input=handle_file(image_path),
|
198 |
text_input=masking_prompt_text,
|
199 |
api_name="/process_image")
|
@@ -308,26 +262,6 @@ with gr.Blocks() as demo:
|
|
308 |
with gr.Accordion("Debug", open=False):
|
309 |
output_mask_component = gr.Image(
|
310 |
type='pil', image_mode='RGB', label='Input mask', format="png")
|
311 |
-
# with gr.Row():
|
312 |
-
# gr.Examples(
|
313 |
-
# fn=process,
|
314 |
-
# examples=EXAMPLES,
|
315 |
-
# inputs=[
|
316 |
-
# input_image_editor_component,
|
317 |
-
# inpainting_prompt_text_component,
|
318 |
-
# masking_prompt_text_component,
|
319 |
-
# seed_slicer_component,
|
320 |
-
# randomize_seed_checkbox_component,
|
321 |
-
# strength_slider_component,
|
322 |
-
# num_inference_steps_slider_component
|
323 |
-
# ],
|
324 |
-
# outputs=[
|
325 |
-
# output_image_component,
|
326 |
-
# output_mask_component
|
327 |
-
# ],
|
328 |
-
# run_on_click=True,
|
329 |
-
# cache_examples=True
|
330 |
-
# )
|
331 |
|
332 |
submit_button_component.click(
|
333 |
fn=process,
|
|
|
23 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
24 |
PIPE = FluxInpaintPipeline.from_pretrained(
|
25 |
"black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16).to(DEVICE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
|
28 |
def calculate_image_dimensions_for_flux(
|
|
|
147 |
return None, None
|
148 |
|
149 |
if is_mask_empty(mask):
|
150 |
+
mask = client.predict(
|
151 |
image_input=handle_file(image_path),
|
152 |
text_input=masking_prompt_text,
|
153 |
api_name="/process_image")
|
|
|
262 |
with gr.Accordion("Debug", open=False):
|
263 |
output_mask_component = gr.Image(
|
264 |
type='pil', image_mode='RGB', label='Input mask', format="png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
|
266 |
submit_button_component.click(
|
267 |
fn=process,
|