elismasilva commited on
Commit
487eaaa
·
verified ·
1 Parent(s): e01363c

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.18%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.19%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.18%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.19%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,51 +1,58 @@
 
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 infer_type(s: str):
7
  """
8
  Infers and converts a string to the most likely data type.
9
 
10
  It attempts conversions in the following order:
11
- 1. Integer
12
- 2. Float
13
- 3. Boolean (case-insensitive 'true' or 'false')
 
14
  If all conversions fail, it returns the original string.
15
 
16
  Args:
17
- s: The input string to be converted.
18
 
19
  Returns:
20
- The converted value (int, float, bool) or the original string.
21
  """
22
  if not isinstance(s, str):
23
  # If the input is not a string, return it as is.
24
  return s
25
-
26
- # 1. Try to convert to an integer
 
 
 
 
 
 
 
 
27
  try:
28
- return int(s)
29
  except ValueError:
30
- # Not an integer, continue...
31
  pass
32
 
33
- # 2. Try to convert to a float
34
  try:
35
- return float(s)
36
  except ValueError:
37
- # Not a float, continue...
38
  pass
39
 
40
- # 3. Check for a boolean value
41
- # This explicit check is important because bool('False') evaluates to True.
42
- s_lower = s.lower()
43
  if s_lower == 'true':
44
  return True
45
  if s_lower == 'false':
46
  return False
47
 
48
- # 4. If nothing else worked, return the original string
49
  return s
50
 
51
  def extract_prop_metadata(cls: Type, field: dataclasses.Field) -> Dict[str, Any]:
 
1
+ import ast
2
  from dataclasses import fields, is_dataclass
3
  import dataclasses
4
  from typing import Any, Dict, List, Literal, Type, get_args, get_origin, get_type_hints
5
 
6
 
7
+ def infer_type(s: Any):
8
  """
9
  Infers and converts a string to the most likely data type.
10
 
11
  It attempts conversions in the following order:
12
+ 1. Python literal (list, dict, tuple, etc.) if the string looks like one.
13
+ 2. Integer
14
+ 3. Float
15
+ 4. Boolean (case-insensitive 'true' or 'false')
16
  If all conversions fail, it returns the original string.
17
 
18
  Args:
19
+ s: The input value to be converted.
20
 
21
  Returns:
22
+ The converted value or the original value.
23
  """
24
  if not isinstance(s, str):
25
  # If the input is not a string, return it as is.
26
  return s
27
+
28
+ # 1. Try to evaluate as a Python literal (list, dict, etc.)
29
+ s_stripped = s.strip()
30
+ if s_stripped.startswith(('[', '{')) and s_stripped.endswith((']', '}')):
31
+ try:
32
+ return ast.literal_eval(s_stripped)
33
+ except (ValueError, SyntaxError, MemoryError, TypeError):
34
+ pass
35
+
36
+ # 2. Try to convert to an integer
37
  try:
38
+ return int(s_stripped)
39
  except ValueError:
 
40
  pass
41
 
42
+ # 3. Try to convert to a float
43
  try:
44
+ return float(s_stripped)
45
  except ValueError:
 
46
  pass
47
 
48
+ # 4. Check for a boolean value
49
+ s_lower = s_stripped.lower()
 
50
  if s_lower == 'true':
51
  return True
52
  if s_lower == 'false':
53
  return False
54
 
55
+ # 5. If nothing else worked, return the original string (sem os espaços extras)
56
  return s
57
 
58
  def extract_prop_metadata(cls: Type, field: dataclasses.Field) -> Dict[str, Any]:
src/pyproject.toml CHANGED
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
8
 
9
  [project]
10
  name = "gradio_propertysheet"
11
- version = "0.0.18"
12
  description = "Property sheet"
13
  readme = "README.md"
14
  license = "apache-2.0"
 
8
 
9
  [project]
10
  name = "gradio_propertysheet"
11
+ version = "0.0.19"
12
  description = "Property sheet"
13
  readme = "README.md"
14
  license = "apache-2.0"