File size: 4,305 Bytes
efa0ffc 5197766 efa0ffc 5197766 efa0ffc 5197766 efa0ffc 5197766 efa0ffc 5197766 efa0ffc 5197766 efa0ffc 5197766 efa0ffc 5197766 efa0ffc 5197766 efa0ffc 5197766 efa0ffc 5197766 efa0ffc 5197766 efa0ffc 5197766 efa0ffc 5197766 efa0ffc 5197766 efa0ffc |
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
import gradio as gr
import numpy as np
from PIL import Image
import os
# Simplified category index
CATEGORY_INDEX = {
1: {'id': 1, 'name': 'face'},
2: {'id': 2, 'name': 'red_tile'},
3: {'id': 3, 'name': 'white_tile'},
4: {'id': 4, 'name': 'blue_tile'},
5: {'id': 5, 'name': 'orange_tile'},
6: {'id': 6, 'name': 'green_tile'},
7: {'id': 7, 'name': 'yellow_tile'}
}
def predict_image(image):
"""
Make predictions on input image - Demo version
"""
if image is None:
return "Please upload an image", None
try:
# Convert to PIL image if needed
if isinstance(image, np.ndarray):
image = Image.fromarray(image)
# Get image information
width, height = image.size
# Demo response since model is not trained yet
result_text = f"""π² Rubik's Cube Analysis Results
π Image Information:
- Dimensions: {width} Γ {height} pixels
- Format: {getattr(image, 'format', 'PIL Image')}
π Detection Status:
β
Image uploaded successfully
β
Image format is valid
β οΈ AI model is currently in development
π Demo Mode:
This is a preview of the Rubik's cube recognition system.
The complete RetinaNet model will detect:
π― Target Detection Classes:
- Cube faces
- Red tiles
- White tiles
- Blue tiles
- Orange tiles
- Green tiles
- Yellow tiles
π Coming Soon:
- Real-time object detection
- Bounding box visualization
- Confidence scores
- 3D cube state analysis
"""
return result_text, image
except Exception as e:
error_msg = f"Error processing image: {str(e)}\n\nThis is a demo version."
return error_msg, image
def create_demo():
"""Create the Gradio interface"""
with gr.Blocks(
title="π² Rubik's Cube Recognition System",
theme=gr.themes.Soft()
) 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;">
Deep Learning-based Rubik's Cube Detection using RetinaNet Architecture
</p>
</div>
""")
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("### π€ Upload Image")
input_image = gr.Image(
label="Upload Rubik's Cube Image",
type="pil",
height=350
)
analyze_btn = gr.Button(
"π Analyze Image",
variant="primary",
size="lg"
)
gr.Markdown("""
### π‘ Tips
- Upload clear images of Rubik's cubes
- Good lighting recommended
- JPG/PNG formats supported
""")
with gr.Column(scale=1):
gr.Markdown("### π Analysis Results")
result_text = gr.Textbox(
label="Detection Report",
lines=12,
max_lines=15,
show_copy_button=True
)
output_image = gr.Image(
label="Processed Image",
type="pil",
height=350
)
# Event handlers
analyze_btn.click(
fn=predict_image,
inputs=[input_image],
outputs=[result_text, output_image]
)
input_image.change(
fn=predict_image,
inputs=[input_image],
outputs=[result_text, output_image]
)
gr.HTML("""
<div style="text-align: center; padding: 20px; margin-top: 20px; border-top: 1px solid #eee;">
<p><strong>π¬ Technology Stack:</strong> TensorFlow β’ RetinaNet β’ SpineNet-49 β’ Gradio</p>
<p><strong>π§ Contact:</strong> <a href="https://huggingface.co/itsyuimorii">@itsyuimorii</a></p>
</div>
""")
return demo
# Launch the application
if __name__ == "__main__":
demo = create_demo()
demo.launch(
server_name="0.0.0.0",
server_port=7860,
show_error=True
)
|