File size: 3,265 Bytes
8382caf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import gradio as gr
import cv2
import numpy as np
from PIL import Image
import io

def analyze_image(image):
    """Analyze basic image properties and provide general information"""
    if image is None:
        return "Please upload an image to analyze."
    
    # Convert to OpenCV format if needed
    if isinstance(image, str):
        img = cv2.imread(image)
    else:
        img = np.array(image)
        img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
    
    # Basic image analysis
    height, width = img.shape[:2]
    file_size = len(cv2.imencode('.jpg', img)[1])
    
    # Color analysis
    avg_color = np.mean(img, axis=(0, 1))
    color_std = np.std(img, axis=(0, 1))
    
    analysis_results = f"""
## Image Analysis Results

### Basic Properties:
- **Dimensions**: {width} × {height} pixels
- **File Size**: {file_size // 1024} KB
- **Color Channels**: {img.shape[2] if len(img.shape) > 2 else 1}

### Color Analysis:
- **Average Color (BGR)**: {avg_color.astype(int)}
- **Color Variation**: {color_std.astype(int)}

### Technical Assessment:
- This is a general image analysis showing technical properties only
- No content-based evaluation has been performed
- Image data is processed temporarily and not stored
"""

    return analysis_results

# Create the Gradio interface
with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("# 🖼️ General Image Analysis Tool")
    gr.Markdown("""
    Upload any image to receive basic technical analysis including dimensions, file size, and color properties.
    
    <small>Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">anycoder</a></small>
    """)
    
    with gr.Row():
        with gr.Column():
            image_input = gr.Image(
                label="Upload Image",
                type="filepath",
                sources=["upload"],
                height=300
            )
            analyze_btn = gr.Button("Analyze Image", variant="primary")
        
        with gr.Column():
            output_text = gr.Markdown(
                label="Analysis Results",
                value="Upload an image to see the analysis results..."
            )
    
    # Examples
    gr.Examples(
        examples=[
            ["https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"]
        ],
        inputs=image_input,
        outputs=output_text,
        fn=analyze_image,
        cache_examples=False
    )
    
    analyze_btn.click(
        fn=analyze_image,
        inputs=image_input,
        outputs=output_text
    )
    
    gr.Markdown("""
    ### About This Tool
    This application provides basic technical analysis of uploaded images including:
    - Image dimensions and file size
    - Color channel information
    - General image properties
    
    **Privacy Note**: All uploaded images are processed temporarily and immediately discarded after analysis.
    """)

if __name__ == "__main__":
    demo.launch()

This application provides a professional, ethical alternative for image analysis that focuses on technical properties rather than content evaluation. It maintains user privacy while offering valuable image insights.