Spaces:
Runtime error
Runtime error
Revert "debug"
Browse filesThis reverts commit b83cf9477adf35e17f9cabfb5cbb40d082ede6b2.
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from typing import Tuple
|
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
|
|
|
| 6 |
import spaces
|
| 7 |
import torch
|
| 8 |
from PIL import Image, ImageFilter
|
|
@@ -24,6 +25,53 @@ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
|
| 24 |
# HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 25 |
# client = Client("SkalskiP/florence-sam-masking", hf_token=HF_TOKEN)
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
pipe = FluxInpaintPipeline.from_pretrained(
|
| 28 |
"black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16).to(DEVICE)
|
| 29 |
|
|
@@ -75,8 +123,6 @@ def process(
|
|
| 75 |
gr.Info("Please enter a text prompt.")
|
| 76 |
return None, None
|
| 77 |
|
| 78 |
-
print(input_image_editor)
|
| 79 |
-
|
| 80 |
image_path = input_image_editor['background']
|
| 81 |
mask_path = input_image_editor['layers'][0]
|
| 82 |
|
|
@@ -194,6 +240,27 @@ with gr.Blocks() as demo:
|
|
| 194 |
with gr.Accordion("Debug", open=False):
|
| 195 |
output_mask_component = gr.Image(
|
| 196 |
type='pil', image_mode='RGB', label='Input mask', format="png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
submit_button_component.click(
|
| 199 |
fn=process,
|
|
|
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
| 6 |
+
import requests
|
| 7 |
import spaces
|
| 8 |
import torch
|
| 9 |
from PIL import Image, ImageFilter
|
|
|
|
| 25 |
# HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 26 |
# client = Client("SkalskiP/florence-sam-masking", hf_token=HF_TOKEN)
|
| 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 |
+
# None,
|
| 47 |
+
# {
|
| 48 |
+
# "background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
|
| 49 |
+
# "layers": [remove_background(Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-mask-2.png", stream=True).raw))],
|
| 50 |
+
# "composite": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-composite-2.png", stream=True).raw),
|
| 51 |
+
# },
|
| 52 |
+
# "little lion",
|
| 53 |
+
# None,
|
| 54 |
+
# 42,
|
| 55 |
+
# False,
|
| 56 |
+
# 0.85,
|
| 57 |
+
# 30
|
| 58 |
+
# ],
|
| 59 |
+
# [
|
| 60 |
+
# None,
|
| 61 |
+
# {
|
| 62 |
+
# "background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
|
| 63 |
+
# "layers": [remove_background(Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-mask-3.png", stream=True).raw))],
|
| 64 |
+
# "composite": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-composite-3.png", stream=True).raw),
|
| 65 |
+
# },
|
| 66 |
+
# "tattoos",
|
| 67 |
+
# None,
|
| 68 |
+
# 42,
|
| 69 |
+
# False,
|
| 70 |
+
# 0.85,
|
| 71 |
+
# 30
|
| 72 |
+
# ]
|
| 73 |
+
# ]
|
| 74 |
+
|
| 75 |
pipe = FluxInpaintPipeline.from_pretrained(
|
| 76 |
"black-forest-labs/FLUX.1-schnell", torch_dtype=torch.bfloat16).to(DEVICE)
|
| 77 |
|
|
|
|
| 123 |
gr.Info("Please enter a text prompt.")
|
| 124 |
return None, None
|
| 125 |
|
|
|
|
|
|
|
| 126 |
image_path = input_image_editor['background']
|
| 127 |
mask_path = input_image_editor['layers'][0]
|
| 128 |
|
|
|
|
| 240 |
with gr.Accordion("Debug", open=False):
|
| 241 |
output_mask_component = gr.Image(
|
| 242 |
type='pil', image_mode='RGB', label='Input mask', format="png")
|
| 243 |
+
# with gr.Row():
|
| 244 |
+
# gr.Examples(
|
| 245 |
+
# fn=process,
|
| 246 |
+
# examples=EXAMPLES,
|
| 247 |
+
# inputs=[
|
| 248 |
+
# input_image_editor_component,
|
| 249 |
+
# inpainting_prompt_text_component,
|
| 250 |
+
# masking_prompt_text_component,
|
| 251 |
+
# masking_prompt_text_component,
|
| 252 |
+
# seed_slicer_component,
|
| 253 |
+
# randomize_seed_checkbox_component,
|
| 254 |
+
# strength_slider_component,
|
| 255 |
+
# num_inference_steps_slider_component
|
| 256 |
+
# ],
|
| 257 |
+
# outputs=[
|
| 258 |
+
# output_image_component,
|
| 259 |
+
# output_mask_component
|
| 260 |
+
# ],
|
| 261 |
+
# run_on_click=True,
|
| 262 |
+
# cache_examples=True
|
| 263 |
+
# )
|
| 264 |
|
| 265 |
submit_button_component.click(
|
| 266 |
fn=process,
|