Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- README.md +3 -4
- space.py +1 -1
- src/README.md +3 -4
- src/backend/gradio_mediagallery/helpers.py +24 -17
- src/demo/space.py +1 -1
- src/pyproject.toml +1 -1
README.md
CHANGED
|
@@ -10,16 +10,15 @@ app_file: space.py
|
|
| 10 |
---
|
| 11 |
|
| 12 |
# `gradio_mediagallery`
|
| 13 |
-
<img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.
|
| 14 |
|
| 15 |
Media Gallery Explorer with Metadata Image Extraction for Gradio UI
|
| 16 |
## Installation
|
| 17 |
|
| 18 |
```bash
|
| 19 |
-
pip install gradio_mediagallery
|
| 20 |
```
|
| 21 |
|
| 22 |
-
|
| 23 |
## Usage
|
| 24 |
|
| 25 |
```python
|
|
@@ -49,7 +48,7 @@ def handle_load_metadata(image_data: gr.EventData) -> List[Any]:
|
|
| 49 |
return transfer_metadata(
|
| 50 |
output_fields=output_fields,
|
| 51 |
metadata=image_data._data,
|
| 52 |
-
remove_prefix_from_keys=
|
| 53 |
)
|
| 54 |
|
| 55 |
# UI layout and logic
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
# `gradio_mediagallery`
|
| 13 |
+
<img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.7%20-%20blue"> <a href="https://huggingface.co/spaces/elismasilva/gradio_mediagallery"><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_mediagallery'>Component GitHub Code</a></span></p>
|
| 14 |
|
| 15 |
Media Gallery Explorer with Metadata Image Extraction for Gradio UI
|
| 16 |
## Installation
|
| 17 |
|
| 18 |
```bash
|
| 19 |
+
pip install gradio_mediagallery
|
| 20 |
```
|
| 21 |
|
|
|
|
| 22 |
## Usage
|
| 23 |
|
| 24 |
```python
|
|
|
|
| 48 |
return transfer_metadata(
|
| 49 |
output_fields=output_fields,
|
| 50 |
metadata=image_data._data,
|
| 51 |
+
remove_prefix_from_keys=True
|
| 52 |
)
|
| 53 |
|
| 54 |
# UI layout and logic
|
space.py
CHANGED
|
@@ -64,7 +64,7 @@ def handle_load_metadata(image_data: gr.EventData) -> List[Any]:
|
|
| 64 |
return transfer_metadata(
|
| 65 |
output_fields=output_fields,
|
| 66 |
metadata=image_data._data,
|
| 67 |
-
remove_prefix_from_keys=
|
| 68 |
)
|
| 69 |
|
| 70 |
# UI layout and logic
|
|
|
|
| 64 |
return transfer_metadata(
|
| 65 |
output_fields=output_fields,
|
| 66 |
metadata=image_data._data,
|
| 67 |
+
remove_prefix_from_keys=True
|
| 68 |
)
|
| 69 |
|
| 70 |
# UI layout and logic
|
src/README.md
CHANGED
|
@@ -10,16 +10,15 @@ app_file: space.py
|
|
| 10 |
---
|
| 11 |
|
| 12 |
# `gradio_mediagallery`
|
| 13 |
-
<img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.
|
| 14 |
|
| 15 |
Media Gallery Explorer with Metadata Image Extraction for Gradio UI
|
| 16 |
## Installation
|
| 17 |
|
| 18 |
```bash
|
| 19 |
-
pip install gradio_mediagallery
|
| 20 |
```
|
| 21 |
|
| 22 |
-
|
| 23 |
## Usage
|
| 24 |
|
| 25 |
```python
|
|
@@ -49,7 +48,7 @@ def handle_load_metadata(image_data: gr.EventData) -> List[Any]:
|
|
| 49 |
return transfer_metadata(
|
| 50 |
output_fields=output_fields,
|
| 51 |
metadata=image_data._data,
|
| 52 |
-
remove_prefix_from_keys=
|
| 53 |
)
|
| 54 |
|
| 55 |
# UI layout and logic
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
# `gradio_mediagallery`
|
| 13 |
+
<img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.7%20-%20blue"> <a href="https://huggingface.co/spaces/elismasilva/gradio_mediagallery"><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_mediagallery'>Component GitHub Code</a></span></p>
|
| 14 |
|
| 15 |
Media Gallery Explorer with Metadata Image Extraction for Gradio UI
|
| 16 |
## Installation
|
| 17 |
|
| 18 |
```bash
|
| 19 |
+
pip install gradio_mediagallery
|
| 20 |
```
|
| 21 |
|
|
|
|
| 22 |
## Usage
|
| 23 |
|
| 24 |
```python
|
|
|
|
| 48 |
return transfer_metadata(
|
| 49 |
output_fields=output_fields,
|
| 50 |
metadata=image_data._data,
|
| 51 |
+
remove_prefix_from_keys=True
|
| 52 |
)
|
| 53 |
|
| 54 |
# UI layout and logic
|
src/backend/gradio_mediagallery/helpers.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from dataclasses import fields, is_dataclass
|
| 2 |
import os
|
| 3 |
import numpy as np
|
|
@@ -5,49 +6,55 @@ from pathlib import Path
|
|
| 5 |
from typing import Any, Dict, List, Optional, Type
|
| 6 |
from PIL import Image, PngImagePlugin, ExifTags
|
| 7 |
|
| 8 |
-
def infer_type(s:
|
| 9 |
"""
|
| 10 |
Infers and converts a string to the most likely data type.
|
| 11 |
|
| 12 |
It attempts conversions in the following order:
|
| 13 |
-
1.
|
| 14 |
-
2.
|
| 15 |
-
3.
|
|
|
|
| 16 |
If all conversions fail, it returns the original string.
|
| 17 |
|
| 18 |
Args:
|
| 19 |
-
s: The input
|
| 20 |
|
| 21 |
Returns:
|
| 22 |
-
The converted 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
try:
|
| 30 |
-
return int(
|
| 31 |
except ValueError:
|
| 32 |
-
# Not an integer, continue...
|
| 33 |
pass
|
| 34 |
|
| 35 |
-
#
|
| 36 |
try:
|
| 37 |
-
return float(
|
| 38 |
except ValueError:
|
| 39 |
-
# Not a float, continue...
|
| 40 |
pass
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
s_lower = s.lower()
|
| 45 |
if s_lower == 'true':
|
| 46 |
return True
|
| 47 |
if s_lower == 'false':
|
| 48 |
return False
|
| 49 |
|
| 50 |
-
#
|
| 51 |
return s
|
| 52 |
|
| 53 |
def build_path_to_metadata_key_map(cls: Type, prefix_list: List[str]) -> Dict[str, str]:
|
|
|
|
| 1 |
+
import ast
|
| 2 |
from dataclasses import fields, is_dataclass
|
| 3 |
import os
|
| 4 |
import numpy as np
|
|
|
|
| 6 |
from typing import Any, Dict, List, Optional, Type
|
| 7 |
from PIL import Image, PngImagePlugin, ExifTags
|
| 8 |
|
| 9 |
+
def infer_type(s: Any):
|
| 10 |
"""
|
| 11 |
Infers and converts a string to the most likely data type.
|
| 12 |
|
| 13 |
It attempts conversions in the following order:
|
| 14 |
+
1. Python literal (list, dict, tuple, etc.) if the string looks like one.
|
| 15 |
+
2. Integer
|
| 16 |
+
3. Float
|
| 17 |
+
4. Boolean (case-insensitive 'true' or 'false')
|
| 18 |
If all conversions fail, it returns the original string.
|
| 19 |
|
| 20 |
Args:
|
| 21 |
+
s: The input value to be converted.
|
| 22 |
|
| 23 |
Returns:
|
| 24 |
+
The converted value or the original value.
|
| 25 |
"""
|
| 26 |
if not isinstance(s, str):
|
| 27 |
# If the input is not a string, return it as is.
|
| 28 |
return s
|
| 29 |
+
|
| 30 |
+
# 1. Try to evaluate as a Python literal (list, dict, etc.)
|
| 31 |
+
s_stripped = s.strip()
|
| 32 |
+
if s_stripped.startswith(('[', '{')) and s_stripped.endswith((']', '}')):
|
| 33 |
+
try:
|
| 34 |
+
return ast.literal_eval(s_stripped)
|
| 35 |
+
except (ValueError, SyntaxError, MemoryError, TypeError):
|
| 36 |
+
pass
|
| 37 |
+
|
| 38 |
+
# 2. Try to convert to an integer
|
| 39 |
try:
|
| 40 |
+
return int(s_stripped)
|
| 41 |
except ValueError:
|
|
|
|
| 42 |
pass
|
| 43 |
|
| 44 |
+
# 3. Try to convert to a float
|
| 45 |
try:
|
| 46 |
+
return float(s_stripped)
|
| 47 |
except ValueError:
|
|
|
|
| 48 |
pass
|
| 49 |
|
| 50 |
+
# 4. Check for a boolean value
|
| 51 |
+
s_lower = s_stripped.lower()
|
|
|
|
| 52 |
if s_lower == 'true':
|
| 53 |
return True
|
| 54 |
if s_lower == 'false':
|
| 55 |
return False
|
| 56 |
|
| 57 |
+
# 5. If nothing else worked, return the original string (sem os espaços extras)
|
| 58 |
return s
|
| 59 |
|
| 60 |
def build_path_to_metadata_key_map(cls: Type, prefix_list: List[str]) -> Dict[str, str]:
|
src/demo/space.py
CHANGED
|
@@ -64,7 +64,7 @@ def handle_load_metadata(image_data: gr.EventData) -> List[Any]:
|
|
| 64 |
return transfer_metadata(
|
| 65 |
output_fields=output_fields,
|
| 66 |
metadata=image_data._data,
|
| 67 |
-
remove_prefix_from_keys=
|
| 68 |
)
|
| 69 |
|
| 70 |
# UI layout and logic
|
|
|
|
| 64 |
return transfer_metadata(
|
| 65 |
output_fields=output_fields,
|
| 66 |
metadata=image_data._data,
|
| 67 |
+
remove_prefix_from_keys=True
|
| 68 |
)
|
| 69 |
|
| 70 |
# UI layout and logic
|
src/pyproject.toml
CHANGED
|
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
|
|
| 8 |
|
| 9 |
[project]
|
| 10 |
name = "gradio_mediagallery"
|
| 11 |
-
version = "0.0.
|
| 12 |
description = "Media Gallery Explorer with Metadata Image Extraction for Gradio UI"
|
| 13 |
readme = "README.md"
|
| 14 |
license = "Apache-2.0"
|
|
|
|
| 8 |
|
| 9 |
[project]
|
| 10 |
name = "gradio_mediagallery"
|
| 11 |
+
version = "0.0.7"
|
| 12 |
description = "Media Gallery Explorer with Metadata Image Extraction for Gradio UI"
|
| 13 |
readme = "README.md"
|
| 14 |
license = "Apache-2.0"
|