Spaces:
Runtime error
Runtime error
| 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. |