Hmham9263's picture
Create app.py
84f9e8e verified
Raw
History Blame Contribute Delete
3.11 kB
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("""
<div style="background: linear-gradient(135deg, #6B21A8, #4C1D95);
padding: 25px; border-radius: 18px; color: white; margin-bottom: 25px;">
<div style="display: flex; align-items: center; gap: 15px;">
<div style="font-size: 42px;">πŸŒ€</div>
<div>
<h1 style="margin:0; font-size: 2.1rem; font-weight: 700;">Smart Items Representer</h1>
<p style="margin: 4px 0 0; opacity: 0.9;">2D to 3D AR Tool β€’ Powered by Meta SAM 3D</p>
</div>
</div>
<p style="margin-top: 12px; font-size: 0.95rem; opacity: 0.85;">
MUHAMMAD AHMAD β€’ SU92-BSAIM-F23-135 β€’ Superior University β€’ Section 6-C
</p>
</div>
""")
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("""
<div style="text-align:center; margin-top:20px;">
<p><strong>AR works best on mobile Chrome</strong></p>
<p>After uploading, use the AR button on your phone</p>
</div>
""")
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()