Spaces:
Runtime error
Runtime error
test examples
Browse files
app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import cv2
|
| 2 |
import random
|
| 3 |
from typing import Tuple, Optional
|
|
@@ -29,14 +31,13 @@ CLIENT = Client("SkalskiP/florence-sam-masking")
|
|
| 29 |
|
| 30 |
EXAMPLES = [
|
| 31 |
[
|
| 32 |
-
None,
|
| 33 |
{
|
| 34 |
"background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
|
| 35 |
"layers": [Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-mask-2-removebg.png", stream=True).raw)],
|
| 36 |
"composite": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-composite-2.png", stream=True).raw),
|
| 37 |
},
|
| 38 |
"little lion",
|
| 39 |
-
|
| 40 |
5,
|
| 41 |
5,
|
| 42 |
42,
|
|
@@ -45,15 +46,14 @@ EXAMPLES = [
|
|
| 45 |
30
|
| 46 |
],
|
| 47 |
[
|
| 48 |
-
None,
|
| 49 |
{
|
| 50 |
-
"background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-
|
| 51 |
-
"layers":
|
| 52 |
-
"composite":
|
| 53 |
},
|
| 54 |
-
"
|
| 55 |
-
|
| 56 |
-
|
| 57 |
5,
|
| 58 |
42,
|
| 59 |
False,
|
|
@@ -118,8 +118,11 @@ def process_mask(
|
|
| 118 |
|
| 119 |
|
| 120 |
def set_client_for_session(request: gr.Request):
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
|
| 125 |
@spaces.GPU(duration=50)
|
|
@@ -163,7 +166,7 @@ def process(
|
|
| 163 |
num_inference_steps_slider: int
|
| 164 |
):
|
| 165 |
if not inpainting_prompt_text:
|
| 166 |
-
gr.Info("Please enter
|
| 167 |
return None, None
|
| 168 |
|
| 169 |
image_path = input_image_editor['background']
|
|
@@ -210,6 +213,9 @@ def process(
|
|
| 210 |
return image, mask
|
| 211 |
|
| 212 |
|
|
|
|
|
|
|
|
|
|
| 213 |
with gr.Blocks() as demo:
|
| 214 |
client_component = gr.State()
|
| 215 |
gr.Markdown(MARKDOWN)
|
|
@@ -303,10 +309,9 @@ with gr.Blocks() as demo:
|
|
| 303 |
output_mask_component = gr.Image(
|
| 304 |
type='pil', image_mode='RGB', label='Input mask', format="png")
|
| 305 |
gr.Examples(
|
| 306 |
-
fn=
|
| 307 |
examples=EXAMPLES,
|
| 308 |
inputs=[
|
| 309 |
-
client_component,
|
| 310 |
input_image_editor_component,
|
| 311 |
inpainting_prompt_text_component,
|
| 312 |
masking_prompt_text_component,
|
|
@@ -322,7 +327,7 @@ with gr.Blocks() as demo:
|
|
| 322 |
output_mask_component
|
| 323 |
],
|
| 324 |
run_on_click=True,
|
| 325 |
-
|
| 326 |
)
|
| 327 |
|
| 328 |
submit_button_component.click(
|
|
|
|
| 1 |
+
from functools import partial
|
| 2 |
+
|
| 3 |
import cv2
|
| 4 |
import random
|
| 5 |
from typing import Tuple, Optional
|
|
|
|
| 31 |
|
| 32 |
EXAMPLES = [
|
| 33 |
[
|
|
|
|
| 34 |
{
|
| 35 |
"background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
|
| 36 |
"layers": [Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-mask-2-removebg.png", stream=True).raw)],
|
| 37 |
"composite": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-composite-2.png", stream=True).raw),
|
| 38 |
},
|
| 39 |
"little lion",
|
| 40 |
+
"",
|
| 41 |
5,
|
| 42 |
5,
|
| 43 |
42,
|
|
|
|
| 46 |
30
|
| 47 |
],
|
| 48 |
[
|
|
|
|
| 49 |
{
|
| 50 |
+
"background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-5.jpeg", stream=True).raw),
|
| 51 |
+
"layers": None,
|
| 52 |
+
"composite": None
|
| 53 |
},
|
| 54 |
+
"big blue eyes",
|
| 55 |
+
"eyes",
|
| 56 |
+
10,
|
| 57 |
5,
|
| 58 |
42,
|
| 59 |
False,
|
|
|
|
| 118 |
|
| 119 |
|
| 120 |
def set_client_for_session(request: gr.Request):
|
| 121 |
+
try:
|
| 122 |
+
x_ip_token = request.headers['x-ip-token']
|
| 123 |
+
return Client("SkalskiP/florence-sam-masking", headers={"X-IP-Token": x_ip_token})
|
| 124 |
+
except:
|
| 125 |
+
return CLIENT
|
| 126 |
|
| 127 |
|
| 128 |
@spaces.GPU(duration=50)
|
|
|
|
| 166 |
num_inference_steps_slider: int
|
| 167 |
):
|
| 168 |
if not inpainting_prompt_text:
|
| 169 |
+
gr.Info("Please enter inpainting text prompt.")
|
| 170 |
return None, None
|
| 171 |
|
| 172 |
image_path = input_image_editor['background']
|
|
|
|
| 213 |
return image, mask
|
| 214 |
|
| 215 |
|
| 216 |
+
process_example = partial(process, client=CLIENT)
|
| 217 |
+
|
| 218 |
+
|
| 219 |
with gr.Blocks() as demo:
|
| 220 |
client_component = gr.State()
|
| 221 |
gr.Markdown(MARKDOWN)
|
|
|
|
| 309 |
output_mask_component = gr.Image(
|
| 310 |
type='pil', image_mode='RGB', label='Input mask', format="png")
|
| 311 |
gr.Examples(
|
| 312 |
+
fn=process_example,
|
| 313 |
examples=EXAMPLES,
|
| 314 |
inputs=[
|
|
|
|
| 315 |
input_image_editor_component,
|
| 316 |
inpainting_prompt_text_component,
|
| 317 |
masking_prompt_text_component,
|
|
|
|
| 327 |
output_mask_component
|
| 328 |
],
|
| 329 |
run_on_click=True,
|
| 330 |
+
cache_examples="lazy"
|
| 331 |
)
|
| 332 |
|
| 333 |
submit_button_component.click(
|