Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	Upload folder using huggingface_hub
Browse files- README.md +2 -2
- space.py +1 -1
- src/README.md +2 -2
- src/backend/gradio_imagemeta/helpers.py +24 -18
- src/demo/space.py +1 -1
- src/pyproject.toml +1 -1
    	
        README.md
    CHANGED
    
    | @@ -10,7 +10,7 @@ app_file: space.py | |
| 10 | 
             
            ---
         | 
| 11 |  | 
| 12 | 
             
            # `gradio_imagemeta`
         | 
| 13 | 
            -
            <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0. | 
| 14 |  | 
| 15 | 
             
            Image Preview with Metadata for Gradio Interface
         | 
| 16 |  | 
| @@ -129,7 +129,7 @@ def save_image_with_metadata( | |
| 129 | 
             
            initial_property_from_meta_config = PropertyConfig()
         | 
| 130 |  | 
| 131 | 
             
            with gr.Blocks(theme=gr.themes.Ocean()) as demo:
         | 
| 132 | 
            -
                gr.Markdown("# ImageMeta Component Demo") | 
| 133 | 
             
                gr.Markdown("""
         | 
| 134 | 
             
                    2. Upload demo image or an image with EXIF or PNG metadata using either the "Upload Imagem (Custom metadata only)" component or the "Upload Imagem (all metadata)" component.
         | 
| 135 | 
             
                    3. Click the 'Info' icon (ⓘ) in the top-left of the image component to view the metadata panel.
         | 
|  | |
| 10 | 
             
            ---
         | 
| 11 |  | 
| 12 | 
             
            # `gradio_imagemeta`
         | 
| 13 | 
            +
            <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.10%20-%20blue"> <a href="https://huggingface.co/spaces/elismasilva/gradio_imagemeta"><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_imagemeta'>Component GitHub Code</a></span></p>
         | 
| 14 |  | 
| 15 | 
             
            Image Preview with Metadata for Gradio Interface
         | 
| 16 |  | 
|  | |
| 129 | 
             
            initial_property_from_meta_config = PropertyConfig()
         | 
| 130 |  | 
| 131 | 
             
            with gr.Blocks(theme=gr.themes.Ocean()) as demo:
         | 
| 132 | 
            +
                gr.Markdown("# ImageMeta Component Demo")    
         | 
| 133 | 
             
                gr.Markdown("""
         | 
| 134 | 
             
                    2. Upload demo image or an image with EXIF or PNG metadata using either the "Upload Imagem (Custom metadata only)" component or the "Upload Imagem (all metadata)" component.
         | 
| 135 | 
             
                    3. Click the 'Info' icon (ⓘ) in the top-left of the image component to view the metadata panel.
         | 
    	
        space.py
    CHANGED
    
    | @@ -132,7 +132,7 @@ def save_image_with_metadata( | |
| 132 | 
             
            initial_property_from_meta_config = PropertyConfig()
         | 
| 133 |  | 
| 134 | 
             
            with gr.Blocks(theme=gr.themes.Ocean()) as demo:
         | 
| 135 | 
            -
                gr.Markdown("# ImageMeta Component Demo") | 
| 136 | 
             
                gr.Markdown(\"\"\"
         | 
| 137 | 
             
                    2. Upload demo image or an image with EXIF or PNG metadata using either the "Upload Imagem (Custom metadata only)" component or the "Upload Imagem (all metadata)" component.
         | 
| 138 | 
             
                    3. Click the 'Info' icon (ⓘ) in the top-left of the image component to view the metadata panel.
         | 
|  | |
| 132 | 
             
            initial_property_from_meta_config = PropertyConfig()
         | 
| 133 |  | 
| 134 | 
             
            with gr.Blocks(theme=gr.themes.Ocean()) as demo:
         | 
| 135 | 
            +
                gr.Markdown("# ImageMeta Component Demo")    
         | 
| 136 | 
             
                gr.Markdown(\"\"\"
         | 
| 137 | 
             
                    2. Upload demo image or an image with EXIF or PNG metadata using either the "Upload Imagem (Custom metadata only)" component or the "Upload Imagem (all metadata)" component.
         | 
| 138 | 
             
                    3. Click the 'Info' icon (ⓘ) in the top-left of the image component to view the metadata panel.
         | 
    	
        src/README.md
    CHANGED
    
    | @@ -10,7 +10,7 @@ app_file: space.py | |
| 10 | 
             
            ---
         | 
| 11 |  | 
| 12 | 
             
            # `gradio_imagemeta`
         | 
| 13 | 
            -
            <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0. | 
| 14 |  | 
| 15 | 
             
            Image Preview with Metadata for Gradio Interface
         | 
| 16 |  | 
| @@ -129,7 +129,7 @@ def save_image_with_metadata( | |
| 129 | 
             
            initial_property_from_meta_config = PropertyConfig()
         | 
| 130 |  | 
| 131 | 
             
            with gr.Blocks(theme=gr.themes.Ocean()) as demo:
         | 
| 132 | 
            -
                gr.Markdown("# ImageMeta Component Demo") | 
| 133 | 
             
                gr.Markdown("""
         | 
| 134 | 
             
                    2. Upload demo image or an image with EXIF or PNG metadata using either the "Upload Imagem (Custom metadata only)" component or the "Upload Imagem (all metadata)" component.
         | 
| 135 | 
             
                    3. Click the 'Info' icon (ⓘ) in the top-left of the image component to view the metadata panel.
         | 
|  | |
| 10 | 
             
            ---
         | 
| 11 |  | 
| 12 | 
             
            # `gradio_imagemeta`
         | 
| 13 | 
            +
            <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.10%20-%20blue"> <a href="https://huggingface.co/spaces/elismasilva/gradio_imagemeta"><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_imagemeta'>Component GitHub Code</a></span></p>
         | 
| 14 |  | 
| 15 | 
             
            Image Preview with Metadata for Gradio Interface
         | 
| 16 |  | 
|  | |
| 129 | 
             
            initial_property_from_meta_config = PropertyConfig()
         | 
| 130 |  | 
| 131 | 
             
            with gr.Blocks(theme=gr.themes.Ocean()) as demo:
         | 
| 132 | 
            +
                gr.Markdown("# ImageMeta Component Demo")    
         | 
| 133 | 
             
                gr.Markdown("""
         | 
| 134 | 
             
                    2. Upload demo image or an image with EXIF or PNG metadata using either the "Upload Imagem (Custom metadata only)" component or the "Upload Imagem (all metadata)" component.
         | 
| 135 | 
             
                    3. Click the 'Info' icon (ⓘ) in the top-left of the image component to view the metadata panel.
         | 
    	
        src/backend/gradio_imagemeta/helpers.py
    CHANGED
    
    | @@ -1,3 +1,4 @@ | |
|  | |
| 1 | 
             
            from dataclasses import fields, is_dataclass
         | 
| 2 | 
             
            import json
         | 
| 3 | 
             
            import os
         | 
| @@ -7,52 +8,57 @@ from PIL import Image, PngImagePlugin, ExifTags | |
| 7 | 
             
            import numpy as np
         | 
| 8 | 
             
            from gradio import image_utils
         | 
| 9 |  | 
| 10 | 
            -
            def infer_type(s:  | 
| 11 | 
             
                """
         | 
| 12 | 
             
                Infers and converts a string to the most likely data type.
         | 
| 13 |  | 
| 14 | 
             
                It attempts conversions in the following order:
         | 
| 15 | 
            -
                1.  | 
| 16 | 
            -
                2.  | 
| 17 | 
            -
                3.  | 
|  | |
| 18 | 
             
                If all conversions fail, it returns the original string.
         | 
| 19 |  | 
| 20 | 
             
                Args:
         | 
| 21 | 
            -
                    s: The input  | 
| 22 |  | 
| 23 | 
             
                Returns:
         | 
| 24 | 
            -
                    The converted 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  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 31 | 
             
                try:
         | 
| 32 | 
            -
                    return int( | 
| 33 | 
             
                except ValueError:
         | 
| 34 | 
            -
                    # Not an integer, continue...
         | 
| 35 | 
             
                    pass
         | 
| 36 |  | 
| 37 | 
            -
                #  | 
| 38 | 
             
                try:
         | 
| 39 | 
            -
                    return float( | 
| 40 | 
             
                except ValueError:
         | 
| 41 | 
            -
                    # Not a float, continue...
         | 
| 42 | 
             
                    pass
         | 
| 43 |  | 
| 44 | 
            -
                #  | 
| 45 | 
            -
                 | 
| 46 | 
            -
                s_lower = s.lower()
         | 
| 47 | 
             
                if s_lower == 'true':
         | 
| 48 | 
             
                    return True
         | 
| 49 | 
             
                if s_lower == 'false':
         | 
| 50 | 
             
                    return False
         | 
| 51 |  | 
| 52 | 
            -
                #  | 
| 53 | 
             
                return s
         | 
| 54 |  | 
| 55 | 
            -
             | 
| 56 | 
             
            def extract_metadata(image_data: str | Path | Image.Image | np.ndarray | None, only_custom_metadata: bool = True) -> Dict[str, Any]:
         | 
| 57 | 
             
                """
         | 
| 58 | 
             
                Extracts metadata from an image.
         | 
|  | |
| 1 | 
            +
            import ast
         | 
| 2 | 
             
            from dataclasses import fields, is_dataclass
         | 
| 3 | 
             
            import json
         | 
| 4 | 
             
            import os
         | 
|  | |
| 8 | 
             
            import numpy as np
         | 
| 9 | 
             
            from gradio import image_utils
         | 
| 10 |  | 
| 11 | 
            +
            def infer_type(s: Any):
         | 
| 12 | 
             
                """
         | 
| 13 | 
             
                Infers and converts a string to the most likely data type.
         | 
| 14 |  | 
| 15 | 
             
                It attempts conversions in the following order:
         | 
| 16 | 
            +
                1. Python literal (list, dict, tuple, etc.) if the string looks like one.
         | 
| 17 | 
            +
                2. Integer
         | 
| 18 | 
            +
                3. Float
         | 
| 19 | 
            +
                4. Boolean (case-insensitive 'true' or 'false')
         | 
| 20 | 
             
                If all conversions fail, it returns the original string.
         | 
| 21 |  | 
| 22 | 
             
                Args:
         | 
| 23 | 
            +
                    s: The input value to be converted.
         | 
| 24 |  | 
| 25 | 
             
                Returns:
         | 
| 26 | 
            +
                    The converted value or the original value.
         | 
| 27 | 
             
                """
         | 
| 28 | 
             
                if not isinstance(s, str):
         | 
| 29 | 
             
                    # If the input is not a string, return it as is.
         | 
| 30 | 
             
                    return s
         | 
| 31 | 
            +
                
         | 
| 32 | 
            +
                # 1. Try to evaluate as a Python literal (list, dict, etc.)
         | 
| 33 | 
            +
                s_stripped = s.strip()    
         | 
| 34 | 
            +
                if s_stripped.startswith(('[', '{')) and s_stripped.endswith((']', '}')):
         | 
| 35 | 
            +
                    try:            
         | 
| 36 | 
            +
                        return ast.literal_eval(s_stripped)
         | 
| 37 | 
            +
                    except (ValueError, SyntaxError, MemoryError, TypeError):            
         | 
| 38 | 
            +
                        pass
         | 
| 39 | 
            +
                
         | 
| 40 | 
            +
                # 2. Try to convert to an integer
         | 
| 41 | 
             
                try:
         | 
| 42 | 
            +
                    return int(s_stripped)
         | 
| 43 | 
             
                except ValueError:
         | 
|  | |
| 44 | 
             
                    pass
         | 
| 45 |  | 
| 46 | 
            +
                # 3. Try to convert to a float
         | 
| 47 | 
             
                try:
         | 
| 48 | 
            +
                    return float(s_stripped)
         | 
| 49 | 
             
                except ValueError:
         | 
|  | |
| 50 | 
             
                    pass
         | 
| 51 |  | 
| 52 | 
            +
                # 4. Check for a boolean value
         | 
| 53 | 
            +
                s_lower = s_stripped.lower()
         | 
|  | |
| 54 | 
             
                if s_lower == 'true':
         | 
| 55 | 
             
                    return True
         | 
| 56 | 
             
                if s_lower == 'false':
         | 
| 57 | 
             
                    return False
         | 
| 58 |  | 
| 59 | 
            +
                # 5. If nothing else worked, return the original string (sem os espaços extras)
         | 
| 60 | 
             
                return s
         | 
| 61 |  | 
|  | |
| 62 | 
             
            def extract_metadata(image_data: str | Path | Image.Image | np.ndarray | None, only_custom_metadata: bool = True) -> Dict[str, Any]:
         | 
| 63 | 
             
                """
         | 
| 64 | 
             
                Extracts metadata from an image.
         | 
    	
        src/demo/space.py
    CHANGED
    
    | @@ -132,7 +132,7 @@ def save_image_with_metadata( | |
| 132 | 
             
            initial_property_from_meta_config = PropertyConfig()
         | 
| 133 |  | 
| 134 | 
             
            with gr.Blocks(theme=gr.themes.Ocean()) as demo:
         | 
| 135 | 
            -
                gr.Markdown("# ImageMeta Component Demo") | 
| 136 | 
             
                gr.Markdown(\"\"\"
         | 
| 137 | 
             
                    2. Upload demo image or an image with EXIF or PNG metadata using either the "Upload Imagem (Custom metadata only)" component or the "Upload Imagem (all metadata)" component.
         | 
| 138 | 
             
                    3. Click the 'Info' icon (ⓘ) in the top-left of the image component to view the metadata panel.
         | 
|  | |
| 132 | 
             
            initial_property_from_meta_config = PropertyConfig()
         | 
| 133 |  | 
| 134 | 
             
            with gr.Blocks(theme=gr.themes.Ocean()) as demo:
         | 
| 135 | 
            +
                gr.Markdown("# ImageMeta Component Demo")    
         | 
| 136 | 
             
                gr.Markdown(\"\"\"
         | 
| 137 | 
             
                    2. Upload demo image or an image with EXIF or PNG metadata using either the "Upload Imagem (Custom metadata only)" component or the "Upload Imagem (all metadata)" component.
         | 
| 138 | 
             
                    3. Click the 'Info' icon (ⓘ) in the top-left of the image component to view the metadata panel.
         | 
    	
        src/pyproject.toml
    CHANGED
    
    | @@ -8,7 +8,7 @@ build-backend = "hatchling.build" | |
| 8 |  | 
| 9 | 
             
            [project]
         | 
| 10 | 
             
            name = "gradio_imagemeta"
         | 
| 11 | 
            -
            version = "0.0. | 
| 12 | 
             
            description = "Image Preview with Metadata for Gradio Interface"
         | 
| 13 | 
             
            readme = "README.md"
         | 
| 14 | 
             
            license = "apache-2.0"
         | 
|  | |
| 8 |  | 
| 9 | 
             
            [project]
         | 
| 10 | 
             
            name = "gradio_imagemeta"
         | 
| 11 | 
            +
            version = "0.0.10"
         | 
| 12 | 
             
            description = "Image Preview with Metadata for Gradio Interface"
         | 
| 13 | 
             
            readme = "README.md"
         | 
| 14 | 
             
            license = "apache-2.0"
         | 
