import gradio as gr import numpy as np from PIL import Image import os def analyze_rubiks_cube(image): """ Simplified function to analyze Rubik's Cube images """ if image is None: return "Please upload an image", None try: # Basic image processing if isinstance(image, np.ndarray): image = Image.fromarray(image) # Get image information width, height = image.size # Simple color analysis image_array = np.array(image) # Calculate main colors colors = { 'red': 0, 'green': 0, 'blue': 0, 'yellow': 0, 'orange': 0, 'white': 0 } # Simplified color detection logic result_text = f""" 🎲 Rubik's Cube Image Analysis Results 📊 Image Information: - Size: {width} x {height} pixels - Format: {image.format if hasattr(image, 'format') else 'PIL Image'} 🔍 Detection Status: ✅ Image uploaded successfully ✅ Image format is correct ⚠️ Complete AI model is still in training 📝 Note: This is a demo version of the Rubik's cube recognition system. The complete RetinaNet model needs to be trained before accurate cube detection can be performed. 🚀 Feature Preview: - Cube face detection - Color tile recognition (Red, White, Blue, Orange, Green, Yellow) - 3D position analysis - Cube state evaluation """ return result_text, image except Exception as e: error_msg = f"Error processing image: {str(e)}" return error_msg, image def create_interface(): """ Create Gradio interface """ with gr.Blocks( title="🎲 Rubik's Cube Recognition System", theme=gr.themes.Soft(), css=""" .gradio-container { max-width: 1200px; margin: auto; } """ ) as demo: gr.HTML("""

🎲 Rubik's Cube Recognition System

Intelligent Rubik's Cube Detection and Analysis Platform Based on Deep Learning

""") with gr.Row(): with gr.Column(scale=1): gr.Markdown("### 📤 Upload Image") input_image = gr.Image( label="Select Rubik's Cube Image", type="pil", height=400 ) analyze_btn = gr.Button( "🔍 Start Analysis", variant="primary", size="lg", scale=1 ) gr.Markdown(""" ### 💡 Usage Tips - Supports JPG, PNG formats - Clear images with good lighting recommended - Better results when cube takes up larger portion of image """) with gr.Column(scale=1): gr.Markdown("### 📊 Analysis Results") result_output = gr.Textbox( label="Detection Report", lines=15, max_lines=20, show_copy_button=True ) output_image = gr.Image( label="Processed Image", type="pil", height=400 ) gr.HTML("""

🔬 Technical Features

🧠 AI Model
RetinaNet + SpineNet-49
🎯 Detection Accuracy
7-class Object Detection
⚡ Processing Speed
Real-time Inference
🌐 Deployment Platform
Hugging Face Spaces
""") # Bind events analyze_btn.click( fn=analyze_rubiks_cube, inputs=[input_image], outputs=[result_output, output_image] ) input_image.change( fn=analyze_rubiks_cube, inputs=[input_image], outputs=[result_output, output_image] ) return demo if __name__ == "__main__": demo = create_interface() demo.launch( server_name="0.0.0.0", server_port=7860, show_error=True )