Pierre Chapuis
commited on
use new context for every request
Browse files- src/app.py +10 -7
src/app.py
CHANGED
@@ -23,11 +23,14 @@ with env.prefixed("ERASER_"):
|
|
23 |
API_PASSWORD: str | None = env.str("API_PASSWORD")
|
24 |
CA_BUNDLE: str | None = env.str("CA_BUNDLE", None)
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
|
33 |
def resize(image: Image.Image, shortest_side: int = 768) -> Image.Image:
|
@@ -100,7 +103,7 @@ def process_bbox(prompts: dict[str, Any]) -> tuple[Image.Image, Image.Image]:
|
|
100 |
if resized_img.width != img.width:
|
101 |
bbox = [int(v * resized_img.width / img.width) for v in bbox]
|
102 |
|
103 |
-
output_image =
|
104 |
_process,
|
105 |
ProcessParams(
|
106 |
image=resized_img,
|
@@ -116,7 +119,7 @@ def on_change_bbox(prompts: dict[str, Any] | None):
|
|
116 |
|
117 |
def process_prompt(img: Image.Image, prompt: str) -> tuple[Image.Image, Image.Image]:
|
118 |
resized_img = resize(img)
|
119 |
-
output_image =
|
120 |
_process,
|
121 |
ProcessParams(image=resized_img, prompt=prompt),
|
122 |
)
|
|
|
23 |
API_PASSWORD: str | None = env.str("API_PASSWORD")
|
24 |
CA_BUNDLE: str | None = env.str("CA_BUNDLE", None)
|
25 |
|
26 |
+
|
27 |
+
def _ctx() -> EditorAPIContext:
|
28 |
+
assert API_USER is not None
|
29 |
+
assert API_PASSWORD is not None
|
30 |
+
ctx = EditorAPIContext(uri=API_URL, user=API_USER, password=API_PASSWORD, priority="low")
|
31 |
+
if CA_BUNDLE:
|
32 |
+
ctx.verify = CA_BUNDLE
|
33 |
+
return ctx
|
34 |
|
35 |
|
36 |
def resize(image: Image.Image, shortest_side: int = 768) -> Image.Image:
|
|
|
103 |
if resized_img.width != img.width:
|
104 |
bbox = [int(v * resized_img.width / img.width) for v in bbox]
|
105 |
|
106 |
+
output_image = _ctx().run_one_sync(
|
107 |
_process,
|
108 |
ProcessParams(
|
109 |
image=resized_img,
|
|
|
119 |
|
120 |
def process_prompt(img: Image.Image, prompt: str) -> tuple[Image.Image, Image.Image]:
|
121 |
resized_img = resize(img)
|
122 |
+
output_image = _ctx().run_one_sync(
|
123 |
_process,
|
124 |
ProcessParams(image=resized_img, prompt=prompt),
|
125 |
)
|