elismasilva commited on
Commit
9e06ad8
·
verified ·
1 Parent(s): d6d67fb

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -10,7 +10,7 @@ app_file: space.py
10
  ---
11
 
12
  # `gradio_propertysheet`
13
- <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.11%20-%20blue"> <a href="https://huggingface.co/spaces/elismasilva/gradio_propertysheet"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Demo-blue"></a><p><span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_propertysheet'>Component GitHub Code</a></span></p>
14
 
15
  The **PropertySheet** component for Gradio allows you to automatically generate a complete and interactive settings panel from a standard Python `dataclass`. It's designed to bring the power of IDE-like property editors directly into your Gradio applications.
16
 
 
10
  ---
11
 
12
  # `gradio_propertysheet`
13
+ <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.12%20-%20blue"> <a href="https://huggingface.co/spaces/elismasilva/gradio_propertysheet"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Demo-blue"></a><p><span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_propertysheet'>Component GitHub Code</a></span></p>
14
 
15
  The **PropertySheet** component for Gradio allows you to automatically generate a complete and interactive settings panel from a standard Python `dataclass`. It's designed to bring the power of IDE-like property editors directly into your Gradio applications.
16
 
src/README.md CHANGED
@@ -10,7 +10,7 @@ app_file: space.py
10
  ---
11
 
12
  # `gradio_propertysheet`
13
- <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.11%20-%20blue"> <a href="https://huggingface.co/spaces/elismasilva/gradio_propertysheet"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Demo-blue"></a><p><span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_propertysheet'>Component GitHub Code</a></span></p>
14
 
15
  The **PropertySheet** component for Gradio allows you to automatically generate a complete and interactive settings panel from a standard Python `dataclass`. It's designed to bring the power of IDE-like property editors directly into your Gradio applications.
16
 
 
10
  ---
11
 
12
  # `gradio_propertysheet`
13
+ <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.12%20-%20blue"> <a href="https://huggingface.co/spaces/elismasilva/gradio_propertysheet"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Demo-blue"></a><p><span>💻 <a href='https://github.com/DEVAIEXP/gradio_component_propertysheet'>Component GitHub Code</a></span></p>
14
 
15
  The **PropertySheet** component for Gradio allows you to automatically generate a complete and interactive settings panel from a standard Python `dataclass`. It's designed to bring the power of IDE-like property editors directly into your Gradio applications.
16
 
src/backend/gradio_propertysheet/helpers.py CHANGED
@@ -1,9 +1,8 @@
1
  from dataclasses import fields, is_dataclass
2
  import dataclasses
3
- from gradio_client.documentation import document
4
- from typing import Any, Dict, Literal, Type, get_args, get_origin, get_type_hints
5
 
6
- @document()
7
  def extract_prop_metadata(cls: Type, field: dataclasses.Field) -> Dict[str, Any]:
8
  """
9
  Inspects a dataclass field and extracts metadata for UI rendering.
@@ -50,7 +49,33 @@ def extract_prop_metadata(cls: Type, field: dataclasses.Field) -> Dict[str, Any]
50
  return metadata
51
 
52
 
53
- @document()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  def build_dataclass_fields(cls: Type, prefix: str = "") -> Dict[str, str]:
55
  """
56
  Recursively builds a mapping of field labels to field paths for a dataclass.
@@ -85,7 +110,7 @@ def build_dataclass_fields(cls: Type, prefix: str = "") -> Dict[str, str]:
85
 
86
  return dataclass_fields
87
 
88
- @document()
89
  def create_dataclass_instance(cls: Type, data: Dict[str, Any]) -> Any:
90
  """
91
  Recursively creates an instance of a dataclass from a nested dictionary.
@@ -119,4 +144,29 @@ def create_dataclass_instance(cls: Type, data: Dict[str, Any]) -> Any:
119
  else:
120
  kwargs[field_name] = field.default
121
 
122
- return cls(**kwargs)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from dataclasses import fields, is_dataclass
2
  import dataclasses
3
+ from typing import Any, Dict, List, Literal, Type, get_args, get_origin, get_type_hints
4
+
5
 
 
6
  def extract_prop_metadata(cls: Type, field: dataclasses.Field) -> Dict[str, Any]:
7
  """
8
  Inspects a dataclass field and extracts metadata for UI rendering.
 
49
  return metadata
50
 
51
 
52
+ def build_path_to_metadata_key_map(cls: Type, prefix_list: List[str]) -> Dict[str, str]:
53
+ """
54
+ Builds a map from a dataclass field path (e.g., 'image_settings.model') to the
55
+ expected key in the metadata dictionary (e.g., 'Image Settings - Model').
56
+ """
57
+ path_map = {}
58
+ if not is_dataclass(cls):
59
+ return {}
60
+
61
+ for f in fields(cls):
62
+ current_path = f.name
63
+
64
+ if is_dataclass(f.type):
65
+ parent_label = f.metadata.get("label", f.name.replace("_", " ").title())
66
+ new_prefix_list = prefix_list + [parent_label]
67
+ nested_map = build_path_to_metadata_key_map(f.type, new_prefix_list)
68
+ for nested_path, metadata_key in nested_map.items():
69
+ path_map[f"{current_path}.{nested_path}"] = metadata_key
70
+ else:
71
+ label = f.metadata.get("label", f.name.replace("_", " ").title())
72
+ full_prefix = " - ".join(prefix_list)
73
+ metadata_key = f"{full_prefix} - {label}" if full_prefix else label
74
+ path_map[current_path] = metadata_key
75
+
76
+ return path_map
77
+
78
+
79
  def build_dataclass_fields(cls: Type, prefix: str = "") -> Dict[str, str]:
80
  """
81
  Recursively builds a mapping of field labels to field paths for a dataclass.
 
110
 
111
  return dataclass_fields
112
 
113
+
114
  def create_dataclass_instance(cls: Type, data: Dict[str, Any]) -> Any:
115
  """
116
  Recursively creates an instance of a dataclass from a nested dictionary.
 
144
  else:
145
  kwargs[field_name] = field.default
146
 
147
+ return cls(**kwargs)
148
+
149
+
150
+ def flatten_dataclass_with_labels(instance: Any, prefix_labels: List[str] = []) -> Dict[str, Any]:
151
+ """
152
+ Recursively flattens a dataclass instance, creating a dictionary
153
+ where the key is a hierarchical, dash-separated label string.
154
+ """
155
+ flat_map = {}
156
+ if not is_dataclass(instance):
157
+ return {}
158
+
159
+ for f in fields(instance):
160
+ value = getattr(instance, f.name)
161
+
162
+ if is_dataclass(value):
163
+ group_label = f.metadata.get("label", f.name.replace("_", " ").title())
164
+ new_prefix_list = prefix_labels + [group_label]
165
+ flat_map.update(flatten_dataclass_with_labels(value, new_prefix_list))
166
+ else:
167
+ field_label = f.metadata.get("label", f.name.replace("_", " ").title())
168
+ all_labels = prefix_labels + [field_label]
169
+ hierarchical_key = " - ".join(all_labels)
170
+ flat_map[hierarchical_key] = value
171
+
172
+ return flat_map
src/backend/gradio_propertysheet/propertysheet.py CHANGED
@@ -7,6 +7,7 @@ from gradio.components.base import Component
7
  from gradio_propertysheet.helpers import extract_prop_metadata
8
  from gradio_client.documentation import document
9
  from gradio.events import Events, EventListener
 
10
  def prop_meta(**kwargs) -> dataclasses.Field:
11
  """
12
  A helper function to create a dataclass field with Gradio-specific metadata.
 
7
  from gradio_propertysheet.helpers import extract_prop_metadata
8
  from gradio_client.documentation import document
9
  from gradio.events import Events, EventListener
10
+
11
  def prop_meta(**kwargs) -> dataclasses.Field:
12
  """
13
  A helper function to create a dataclass field with Gradio-specific metadata.
src/pyproject.toml CHANGED
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
8
 
9
  [project]
10
  name = "gradio_propertysheet"
11
- version = "0.0.11"
12
  description = "Property sheet"
13
  readme = "README.md"
14
  license = "apache-2.0"
 
8
 
9
  [project]
10
  name = "gradio_propertysheet"
11
+ version = "0.0.12"
12
  description = "Property sheet"
13
  readme = "README.md"
14
  license = "apache-2.0"