balthou commited on
Commit
7fadd3c
·
1 Parent(s): 42e82ef

Port to interactive_pipe 0.9.4 (context proxy, KeyboardControl) and gradio 6

Browse files

- Filters use the `context` proxy instead of a `context={}` keyword
argument (removed in interactive_pipe 0.9.0, raises TypeError)
- Position sliders with arrow-key shortcuts use KeyboardControl: the
(default, range, name, [keys]) tuple form is no longer accepted
- requirements.txt: pin interactive-pipe==0.9.4
- README.md: sdk_version 6.32.0 (current gradio), python_version 3.12

Files changed (3) hide show
  1. README.md +2 -1
  2. app.py +10 -14
  3. requirements.txt +1 -1
README.md CHANGED
@@ -4,7 +4,8 @@ emoji: 🔒
4
  colorFrom: indigo
5
  colorTo: green
6
  sdk: gradio
7
- sdk_version: 5.0.2
 
8
  app_file: app.py
9
  pinned: false
10
  license: cc
 
4
  colorFrom: indigo
5
  colorTo: green
6
  sdk: gradio
7
+ sdk_version: 6.32.0
8
+ python_version: "3.12"
9
  app_file: app.py
10
  pinned: false
11
  license: cc
app.py CHANGED
@@ -1,4 +1,5 @@
1
- from interactive_pipe import interactive_pipeline, interactive, Image
 
2
  from typing import Tuple
3
  import numpy as np
4
 
@@ -36,8 +37,7 @@ DIFFICULY_LEVELS = list(DIFFICULY.keys())
36
 
37
  def generate_random_puzzle(
38
  seed: int = 43,
39
- difficulty: str = DIFFICULY_LEVELS[0],
40
- context: dict = {}
41
  ):
42
  """Generate random puzzle configuration and store in context.
43
 
@@ -53,8 +53,7 @@ def generate_random_puzzle(
53
 
54
  def create_puzzle(
55
  img: np.ndarray,
56
- intensity: float = 0.4,
57
- context: dict = {}
58
  ) -> Tuple[np.ndarray, np.ndarray]:
59
  """Extract puzzle piece from image. Make a dark hole where the """
60
  out = img.copy()
@@ -71,8 +70,7 @@ def create_puzzle(
71
  def flip_mirror_piece(
72
  piece: np.ndarray,
73
  flip: bool = False,
74
- mirror: bool = False,
75
- context: dict = {}
76
  ) -> np.ndarray:
77
  """Flip and/or mirror the puzzle piece."""
78
  context["user_flip_mirror"] = (flip, mirror)
@@ -83,8 +81,7 @@ def place_puzzle(
83
  puzzle: np.ndarray,
84
  piece: np.ndarray,
85
  pos_x: float = 0.5,
86
- pos_y: float = 0.5,
87
- context: dict = {}
88
  ) -> np.ndarray:
89
  """Place the puzzle piece at the user-defined position."""
90
  out = puzzle.copy()
@@ -99,7 +96,7 @@ TOLERANCES = {"low": 0.01, "medium": 0.02, "high": 0.05}
99
  TOLERANCE_LEVELS = list(TOLERANCES.keys())
100
 
101
 
102
- def check_puzzle(tolerance: str = "low", context: dict = {}) -> None:
103
  """Check if the user placed the puzzle piece correctly.
104
  Store the result in the context."""
105
  x_gt, y_gt = context["puzzle_pos"]
@@ -116,8 +113,7 @@ def check_puzzle(tolerance: str = "low", context: dict = {}) -> None:
116
  def display_feedback(
117
  puzzle: np.ndarray,
118
  ok_ribbon: np.ndarray,
119
- nok_ribbon: np.ndarray,
120
- context: dict = {}
121
  ) -> np.ndarray:
122
  """Display green/red ribbon on the right side of the puzzle."""
123
  success = context.get("success", False)
@@ -155,8 +151,8 @@ def main(img: np.ndarray, backend="gradio", debug: bool = False):
155
  difficulty=(DIFFICULY_LEVELS[0], DIFFICULY_LEVELS, "Difficulty")
156
  )(generate_random_puzzle)
157
  interactive(
158
- pos_x=(0.5, [0.1, 0.9, 0.005], "Position X", ["left", "right"]),
159
- pos_y=(0.5, [0.1, 0.9, 0.005], "Position Y", ["up", "down"]),
160
  )(place_puzzle)
161
  # left, right, up, down will only supported when using the Qt backend
162
  interactive(
 
1
+ from interactive_pipe import interactive_pipeline, interactive, Image, context
2
+ from interactive_pipe import KeyboardControl
3
  from typing import Tuple
4
  import numpy as np
5
 
 
37
 
38
  def generate_random_puzzle(
39
  seed: int = 43,
40
+ difficulty: str = DIFFICULY_LEVELS[0]
 
41
  ):
42
  """Generate random puzzle configuration and store in context.
43
 
 
53
 
54
  def create_puzzle(
55
  img: np.ndarray,
56
+ intensity: float = 0.4
 
57
  ) -> Tuple[np.ndarray, np.ndarray]:
58
  """Extract puzzle piece from image. Make a dark hole where the """
59
  out = img.copy()
 
70
  def flip_mirror_piece(
71
  piece: np.ndarray,
72
  flip: bool = False,
73
+ mirror: bool = False
 
74
  ) -> np.ndarray:
75
  """Flip and/or mirror the puzzle piece."""
76
  context["user_flip_mirror"] = (flip, mirror)
 
81
  puzzle: np.ndarray,
82
  piece: np.ndarray,
83
  pos_x: float = 0.5,
84
+ pos_y: float = 0.5
 
85
  ) -> np.ndarray:
86
  """Place the puzzle piece at the user-defined position."""
87
  out = puzzle.copy()
 
96
  TOLERANCE_LEVELS = list(TOLERANCES.keys())
97
 
98
 
99
+ def check_puzzle(tolerance: str = "low") -> None:
100
  """Check if the user placed the puzzle piece correctly.
101
  Store the result in the context."""
102
  x_gt, y_gt = context["puzzle_pos"]
 
113
  def display_feedback(
114
  puzzle: np.ndarray,
115
  ok_ribbon: np.ndarray,
116
+ nok_ribbon: np.ndarray
 
117
  ) -> np.ndarray:
118
  """Display green/red ribbon on the right side of the puzzle."""
119
  success = context.get("success", False)
 
151
  difficulty=(DIFFICULY_LEVELS[0], DIFFICULY_LEVELS, "Difficulty")
152
  )(generate_random_puzzle)
153
  interactive(
154
+ pos_x=KeyboardControl(0.5, [0.1, 0.9], step=0.005, name="Position X", keydown="left", keyup="right"),
155
+ pos_y=KeyboardControl(0.5, [0.1, 0.9], step=0.005, name="Position Y", keydown="up", keyup="down"),
156
  )(place_puzzle)
157
  # left, right, up, down will only supported when using the Qt backend
158
  interactive(
requirements.txt CHANGED
@@ -1 +1 @@
1
- interactive-pipe>=0.8.3
 
1
+ interactive-pipe==0.9.4