Pierre Chapuis commited on
Commit
9e26efb
·
unverified ·
1 Parent(s): 6ca913f

client update

Browse files
Files changed (4) hide show
  1. pyproject.toml +1 -1
  2. requirements.lock +1 -1
  3. requirements.txt +1 -1
  4. src/app.py +7 -14
pyproject.toml CHANGED
@@ -12,7 +12,7 @@ dependencies = [
12
  "pillow>=10.4.0",
13
  "gradio-imageslider>=0.0.20",
14
  "pillow-heif>=0.18.0",
15
- "finegrain @ git+ssh://[email protected]/finegrain-ai/finegrain-python@08e74457ec3390c1401609931941c8f80284efd6#subdirectory=finegrain",
16
  ]
17
  readme = "README.md"
18
  requires-python = ">= 3.12, <3.13"
 
12
  "pillow>=10.4.0",
13
  "gradio-imageslider>=0.0.20",
14
  "pillow-heif>=0.18.0",
15
+ "finegrain @ git+ssh://[email protected]/finegrain-ai/finegrain-python@d6ef5700816ca26100e776257e8a9363fc812394#subdirectory=finegrain",
16
  ]
17
  readme = "README.md"
18
  requires-python = ">= 3.12, <3.13"
requirements.lock CHANGED
@@ -39,7 +39,7 @@ ffmpy==0.5.0
39
  # via gradio
40
  filelock==3.17.0
41
  # via huggingface-hub
42
- finegrain @ git+ssh://[email protected]/finegrain-ai/finegrain-python@08e74457ec3390c1401609931941c8f80284efd6#subdirectory=finegrain
43
  # via eraser
44
  fonttools==4.55.5
45
  # via matplotlib
 
39
  # via gradio
40
  filelock==3.17.0
41
  # via huggingface-hub
42
+ finegrain @ git+ssh://[email protected]/finegrain-ai/finegrain-python@d6ef5700816ca26100e776257e8a9363fc812394#subdirectory=finegrain
43
  # via eraser
44
  fonttools==4.55.5
45
  # via matplotlib
requirements.txt CHANGED
@@ -3,4 +3,4 @@ gradio_imageslider>=0.0.20
3
  environs>=11.0.0
4
  pillow>=10.4.0
5
  pillow-heif>=0.18.0
6
- git+https://github.com/finegrain-ai/finegrain-python@08e74457ec3390c1401609931941c8f80284efd6#subdirectory=finegrain
 
3
  environs>=11.0.0
4
  pillow>=10.4.0
5
  pillow-heif>=0.18.0
6
+ git+https://github.com/finegrain-ai/finegrain-python@d6ef5700816ca26100e776257e8a9363fc812394#subdirectory=finegrain
src/app.py CHANGED
@@ -18,9 +18,9 @@ env = Env()
18
  env.read_env()
19
 
20
  with env.prefixed("ERASER_"):
21
- API_URL: str = str(env.str("API_URL", "https://api.finegrain.ai/editor"))
22
  API_USER: str | None = env.str("API_USER")
23
  API_PASSWORD: str | None = env.str("API_PASSWORD")
 
24
  CA_BUNDLE: str | None = env.str("CA_BUNDLE", None)
25
 
26
 
@@ -28,9 +28,11 @@ with env.prefixed("ERASER_"):
28
  def _ctx() -> EditorAPIContext:
29
  assert API_USER is not None
30
  assert API_PASSWORD is not None
31
- ctx = EditorAPIContext(uri=API_URL, user=API_USER, password=API_PASSWORD, priority="low")
32
  if CA_BUNDLE:
33
  ctx.verify = CA_BUNDLE
 
 
34
  return ctx
35
 
36
 
@@ -49,14 +51,6 @@ class ProcessParams:
49
  bbox: tuple[int, int, int, int] | None = None
50
 
51
 
52
- async def call_or_raise(ctx: EditorAPIContext, uri: str, params: dict[str, Any]) -> str:
53
- st, ok = await ctx.call_skill(uri, params)
54
- if ok:
55
- return st
56
- meta = await ctx.get_meta(st)
57
- raise RuntimeError(f"skill {uri} failed with {st}: {meta}")
58
-
59
-
60
  async def _process(ctx: EditorAPIContext, params: ProcessParams) -> Image.Image:
61
  with io.BytesIO() as f:
62
  params.image.save(f, format="JPEG")
@@ -68,15 +62,14 @@ async def _process(ctx: EditorAPIContext, params: ProcessParams) -> Image.Image:
68
  segment_params = {"bbox": list(params.bbox)}
69
  else:
70
  assert params.prompt
71
- segment_input_st = await call_or_raise(
72
- ctx,
73
  f"infer-bbox/{st_input}",
74
  {"product_name": params.prompt},
75
  )
76
  segment_params = {}
77
 
78
- st_mask = await call_or_raise(ctx, f"segment/{segment_input_st}", segment_params)
79
- st_erased = await call_or_raise(ctx, f"erase/{st_input}/{st_mask}", {"mode": "free"})
80
 
81
  response = await ctx.request(
82
  "GET",
 
18
  env.read_env()
19
 
20
  with env.prefixed("ERASER_"):
 
21
  API_USER: str | None = env.str("API_USER")
22
  API_PASSWORD: str | None = env.str("API_PASSWORD")
23
+ API_URL: str | None = env.str("API_URL", None)
24
  CA_BUNDLE: str | None = env.str("CA_BUNDLE", None)
25
 
26
 
 
28
  def _ctx() -> EditorAPIContext:
29
  assert API_USER is not None
30
  assert API_PASSWORD is not None
31
+ ctx = EditorAPIContext(user=API_USER, password=API_PASSWORD, priority="low")
32
  if CA_BUNDLE:
33
  ctx.verify = CA_BUNDLE
34
+ if API_URL:
35
+ ctx.base_url = API_URL
36
  return ctx
37
 
38
 
 
51
  bbox: tuple[int, int, int, int] | None = None
52
 
53
 
 
 
 
 
 
 
 
 
54
  async def _process(ctx: EditorAPIContext, params: ProcessParams) -> Image.Image:
55
  with io.BytesIO() as f:
56
  params.image.save(f, format="JPEG")
 
62
  segment_params = {"bbox": list(params.bbox)}
63
  else:
64
  assert params.prompt
65
+ segment_input_st = await ctx.ensure_skill(
 
66
  f"infer-bbox/{st_input}",
67
  {"product_name": params.prompt},
68
  )
69
  segment_params = {}
70
 
71
+ st_mask = await ctx.ensure_skill(f"segment/{segment_input_st}", segment_params)
72
+ st_erased = await ctx.ensure_skill(f"erase/{st_input}/{st_mask}", {"mode": "free"})
73
 
74
  response = await ctx.request(
75
  "GET",