ngd1210 commited on
Commit
fd32459
·
1 Parent(s): 7a74dd9

Added filter documentation and UI updates

Browse files

- Added Markdown for filter documentation
- Updated UI to display filter docs
- Enhanced dot_effect filter with docstring
- Improved process function readability
- Fixed output list in filter_select change

Files changed (3) hide show
  1. __pycache__/registry.cpython-312.pyc +0 -0
  2. app.py +10 -3
  3. filters.py +11 -2
__pycache__/registry.cpython-312.pyc ADDED
Binary file (2.01 kB). View file
 
app.py CHANGED
@@ -34,6 +34,8 @@ def create_app():
34
 
35
  with gr.Column():
36
  output_image = gr.Image(label="Filtered Image")
 
 
37
 
38
  # Xử lý cập nhật UI
39
  def update_controls(filter_name):
@@ -41,11 +43,16 @@ def create_app():
41
  for group_name, group in filter_groups.items():
42
  visibility = (group_name == filter_name)
43
  updates.append(gr.update(visible=visibility)) # Changed from gr.Group.update
44
- return updates
 
 
 
 
 
45
 
46
 
47
  # Xử lý ảnh khi button click
48
- def process(image, filter_name, *args): # Update process function to take image, filter_name and *args
49
  if image is None:
50
  return None
51
 
@@ -72,7 +79,7 @@ def create_app():
72
  filter_select.change(
73
  update_controls,
74
  inputs=filter_select,
75
- outputs=list(filter_groups.values()), # Pass list of groups as outputs
76
  api_name=False
77
  )
78
 
 
34
 
35
  with gr.Column():
36
  output_image = gr.Image(label="Filtered Image")
37
+
38
+ filter_doc = gr.Markdown()
39
 
40
  # Xử lý cập nhật UI
41
  def update_controls(filter_name):
 
43
  for group_name, group in filter_groups.items():
44
  visibility = (group_name == filter_name)
45
  updates.append(gr.update(visible=visibility)) # Changed from gr.Group.update
46
+
47
+ # Get filter documentation
48
+ doc = registry.filters[filter_name].__doc__ or "No documentation available."
49
+ updates.append(gr.update(value=doc))
50
+
51
+ return updates + [filter_doc.update(value=doc)]
52
 
53
 
54
  # Xử lý ảnh khi button click
55
+ def process(image, filter_name, *args): # Update process function to take image, filter_name and *args
56
  if image is None:
57
  return None
58
 
 
79
  filter_select.change(
80
  update_controls,
81
  inputs=filter_select,
82
+ outputs=list(filter_groups.values()) + [filter_doc], # Pass list of groups as outputs
83
  api_name=False
84
  )
85
 
filters.py CHANGED
@@ -2,7 +2,6 @@ import cv2
2
  import numpy as np
3
  from registry import registry
4
 
5
-
6
  @registry.register("Original")
7
  def original(image):
8
  return image
@@ -22,6 +21,16 @@ def original(image):
22
  "dot_spacing": 1,
23
  })
24
  def dot_effect(image, dot_size: int = 10, dot_spacing: int = 2, invert: bool = False):
 
 
 
 
 
 
 
 
 
 
25
  # Convert to grayscale if image is color
26
  if len(image.shape) == 3:
27
  gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
@@ -65,4 +74,4 @@ def dot_effect(image, dot_size: int = 10, dot_spacing: int = 2, invert: bool = F
65
  (dot_color),
66
  -1)
67
 
68
- return canvas
 
2
  import numpy as np
3
  from registry import registry
4
 
 
5
  @registry.register("Original")
6
  def original(image):
7
  return image
 
21
  "dot_spacing": 1,
22
  })
23
  def dot_effect(image, dot_size: int = 10, dot_spacing: int = 2, invert: bool = False):
24
+ """
25
+ **Convert your image into a dotted pattern.**
26
+ __Args:__
27
+ `image` (numpy.ndarray): Input image (BGR or grayscale)
28
+ `dot_size` (int): Size of each dot
29
+ `dot_spacing` (int): Spacing between dots
30
+ `invert` (bool): Invert the dots
31
+ __Returns:__
32
+ numpy.ndarray: Dotted image
33
+ """
34
  # Convert to grayscale if image is color
35
  if len(image.shape) == 3:
36
  gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
 
74
  (dot_color),
75
  -1)
76
 
77
+ return canvas