import gradio as gr
# Beautiful Purple Theme
theme = gr.themes.Soft(
primary_hue="purple",
secondary_hue="violet",
neutral_hue="slate"
).set(
button_primary_background_fill="#6B21A8",
button_primary_background_fill_hover="#581C87",
)
def process_image(image):
if image is None:
return None, "Please upload a photo first!"
return image, "✅ Image processed! For best 3D quality, use the official Meta demo below."
with gr.Blocks(theme=theme, title="Smart Items Representer") as demo:
# Professional Header
gr.HTML("""
🌀
Smart Items Representer
2D to 3D AR Tool • Powered by Meta SAM 3D
MUHAMMAD AHMAD • SU92-BSAIM-F23-135 • Superior University • Section 6-C
""")
with gr.Tab("🚀 Create 3D Model"):
with gr.Row():
with gr.Column():
img_input = gr.Image(label="Upload 2D Photo (Food, Product, Furniture)", type="pil", height=350)
process_btn = gr.Button("✨ Process with AI", variant="primary", size="lg")
with gr.Column():
img_output = gr.Image(label="Processed Preview", height=350)
status_box = gr.Textbox(label="Status", interactive=False)
process_btn.click(process_image, inputs=img_input, outputs=[img_output, status_box])
gr.Markdown("### Best Quality: Use Official Meta SAM 3D")
gr.Button("🔗 Open Meta SAM 3D Demo (Recommended)",
link="https://www.aidemos.meta.com/segment-anything/editor/convert-image-to-3d")
gr.Markdown("Upload your photo there → Download GLB → View in AR below")
with gr.Tab("📱 View in AR"):
gr.Markdown("""
### Real-Time Augmented Reality
1. Generate your 3D model using the tab above (or Meta demo)
2. Download the `.glb` file
3. Upload it in the box below to view in your real environment
""")
glb_upload = gr.File(label="Upload your .glb file", file_types=[".glb"])
gr.HTML("""
AR works best on mobile Chrome
After uploading, use the AR button on your phone
""")
with gr.Tab("📋 About"):
gr.Markdown("""
**Smart Items Representer**
Turn any 2D image into an interactive 3D hologram using Meta SAM 3D + WebXR.
Ready for FYP, Startup, and Research Paper.
""")
demo.launch()