itsyuimorii's picture
Upload folder using huggingface_hub
efa0ffc verified
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("""
<div style="text-align: center; padding: 20px;">
<h1>🎲 Rubik's Cube Recognition System</h1>
<p style="font-size: 18px; color: #666;">
Intelligent Rubik's Cube Detection and Analysis Platform Based on Deep Learning
</p>
</div>
""")
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("""
<div style="text-align: center; padding: 20px; border-top: 1px solid #eee; margin-top: 20px;">
<h3>πŸ”¬ Technical Features</h3>
<div style="display: flex; justify-content: space-around; flex-wrap: wrap;">
<div style="margin: 10px;">
<strong>🧠 AI Model</strong><br>
RetinaNet + SpineNet-49
</div>
<div style="margin: 10px;">
<strong>🎯 Detection Accuracy</strong><br>
7-class Object Detection
</div>
<div style="margin: 10px;">
<strong>⚑ Processing Speed</strong><br>
Real-time Inference
</div>
<div style="margin: 10px;">
<strong>🌐 Deployment Platform</strong><br>
Hugging Face Spaces
</div>
</div>
</div>
""")
# 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
)