| import gradio as gr
|
| import sys
|
| import os
|
|
|
|
|
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'dist'))
|
|
|
|
|
| try:
|
| from core_logic import (
|
| secure_virtual_tryon,
|
| handle_like_action,
|
| get_company_info,
|
| create_footer_html,
|
| create_instructions_html,
|
| get_css_styles
|
| )
|
| print("Core logic module loaded successfully")
|
| except ImportError as e:
|
| print(f"Error: Obfuscated module not found: {e}")
|
| print("Current directory:", os.getcwd())
|
| print("Files in dist:", os.listdir('dist') if os.path.exists('dist') else 'dist not found')
|
| sys.exit(1)
|
|
|
|
|
| company_info = get_company_info()
|
| css = get_css_styles()
|
|
|
| def virtual_tryon_interface(human_img, garment_img, garment_type, request: gr.Request):
|
| """Simple interface function that calls the secure core logic"""
|
| return secure_virtual_tryon(human_img, garment_img, garment_type, request)
|
|
|
| def like_button_interface(request: gr.Request):
|
| """Simple interface function for like button"""
|
| return handle_like_action(request)
|
|
|
|
|
| with gr.Blocks(css=css, title=f"{company_info['name']} Virtual Try-On", theme=gr.themes.Ocean()) as demo:
|
| with gr.Row():
|
| with gr.Column(0.7):
|
| gr.Markdown(f"""
|
| <div style="display: flex; align-items: center;">
|
| <img src="https://avatars.githubusercontent.com/u/211682198?s=200&v=4" style="width: 80px; margin-right: 20px;"/>
|
| <div>
|
| <h1 style="margin-bottom: 0;">{company_info['name']} Virtual Try-On π π</h1>
|
| <p style="margin-top: 0; color: #636e72;">Try on complete outfits with our AI-powered virtual try-on technology</p>
|
| </div>
|
| </div>
|
| """)
|
|
|
| gr.HTML(create_instructions_html())
|
| with gr.Column(0.3):
|
| gr.Markdown(f"""
|
| <div style="display: flex; align-items: center;">
|
| <img src="https://github.com/Miragic-AI/Virtual-Try-On/raw/main/images/qr.png" style="width: 260px; margin-left: 100px;"/>
|
| </div>
|
| """)
|
|
|
| with gr.Row(elem_id="col-container"):
|
|
|
| with gr.Column(elem_classes="step-column"):
|
| gr.HTML("""
|
| <div class="step-title">
|
| <span style="font-size: 24px;">1. Upload Person Image</span><br>
|
| </div>
|
| """)
|
| human_img = gr.Image(
|
| label="Person Image",
|
| sources='upload',
|
| type="numpy",
|
| elem_classes="image-preview",
|
| height=400
|
| )
|
|
|
| gr.Examples(
|
| examples=[
|
| "assets/human/1.jpg",
|
| "assets/human/2.jpg",
|
| "assets/human/3.jpg",
|
| "assets/human/4.jpg",
|
| "assets/human/5.jpg",
|
| "assets/human/6.jpg",
|
| "assets/human/7.jpg",
|
| "assets/human/8.jpg",
|
| "assets/human/9.jpg",
|
| "assets/human/10.jpg",
|
| "assets/human/11.jpg",
|
| "assets/human/12.jpg"
|
| ],
|
| inputs=human_img,
|
| label="Example Person Images",
|
| examples_per_page=12
|
| )
|
|
|
|
|
| with gr.Column(elem_classes="step-column"):
|
| gr.HTML("""
|
| <div class="step-title">
|
| <span style="font-size: 24px;">2. Upload Garment Image</span><br>
|
| </div>
|
| """)
|
| garment_img = gr.Image(
|
| label="Garment Image",
|
| sources='upload',
|
| type="numpy",
|
| elem_classes="image-preview",
|
| height=400
|
| )
|
|
|
| garment_type = gr.Dropdown(
|
| choices=["Dress/Suit", "Top", "Bottom"],
|
| value="Dress/Suit",
|
| label="Garment Type",
|
| info="Select the type of garment you want to try on"
|
| )
|
|
|
| gr.Examples(
|
| examples=[
|
| "assets/garment/1.jpg",
|
| "assets/garment/2.jpg",
|
| "assets/garment/3.jpg",
|
| "assets/garment/4.jpg",
|
| "assets/garment/5.jpg",
|
| "assets/garment/6.jpg",
|
| "assets/garment/7.jpg",
|
| "assets/garment/8.jpg",
|
| "assets/garment/9.jpg",
|
| "assets/garment/10.jpg",
|
| "assets/garment/11.jpg",
|
| "assets/garment/12.jpg"
|
| ],
|
| inputs=garment_img,
|
| label="Example Garment Images",
|
| examples_per_page=12
|
| )
|
|
|
|
|
| with gr.Column(elem_classes="step-column"):
|
| gr.HTML("""
|
| <div class="step-title">
|
| <span style="font-size: 24px;">3. Virtual Try-On Result</span><br>
|
| </div>
|
| """)
|
| result_img = gr.Image(
|
| label="Try-On Result",
|
| interactive=False,
|
| elem_classes="image-preview",
|
| height=400
|
| )
|
|
|
| with gr.Row():
|
| like_button = gr.Button(
|
| "π Like this result!",
|
| elem_classes="like-button",
|
| visible=False
|
| )
|
|
|
| try_button = gr.Button(
|
| "Run Virtual Try-On π",
|
| elem_classes="button-gradient"
|
| )
|
|
|
| gr.HTML("""
|
| <div class="interaction-section">
|
| <p style="margin: 5px 0;">If you like our Virtual Try-On results, please give us a β into our space!</p>
|
| </div>
|
| """)
|
|
|
| signup_prompt = gr.HTML(
|
| visible=True,
|
| value=f"""<div class="signup-container">
|
| <h3>π Want unlimited generations?</h3>
|
| <p>Please sign up at {company_info['name']}.ai for unlimited access to all our AI tools!</p>
|
| <a href='{company_info['url']}/products/virtual-try-on' target='_blank' class="signup-button">
|
| SignUp for Free π
|
| </a>
|
| </div>"""
|
| )
|
|
|
|
|
| if os.path.exists("assets/examples"):
|
| with gr.Row():
|
| gr.Examples(
|
| examples=[
|
| ["assets/examples/model1.jpg", "assets/examples/garment1.png", "Dress/Suit", "assets/examples/result1.jpg"],
|
| ["assets/examples/model2.png", "assets/examples/garment2.jpg", "Dress/Suit", "assets/examples/result2.jpg"],
|
| ["assets/examples/model3.jpg", "assets/examples/garment3.jpg", "Dress/Suit", "assets/examples/result3.jpg"],
|
| ],
|
| inputs=[human_img, garment_img, garment_type, result_img],
|
| label=None,
|
| examples_per_page=3
|
| )
|
|
|
|
|
| try_button.click(
|
| fn=virtual_tryon_interface,
|
| inputs=[human_img, garment_img, garment_type],
|
| outputs=[result_img, like_button],
|
| api_name="virtual_tryon"
|
| )
|
|
|
| like_button.click(
|
| fn=like_button_interface,
|
| inputs=[],
|
| outputs=[like_button]
|
| )
|
|
|
|
|
| gr.HTML(f'<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2F{company_info["name"]}-AI%2F{company_info["name"]}-Virtual-Try-On"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2F{company_info["name"]}-AI%2F{company_info["name"]}-Virtual-Try-On&label=VISITORS&labelColor=%2337d67a&countColor=%23f47373&style=plastic&labelStyle=upper" /></a>')
|
|
|
|
|
| gr.HTML(create_footer_html())
|
|
|
| if __name__ == "__main__":
|
| demo.launch(
|
| show_api=False,
|
| server_name="0.0.0.0",
|
| server_port=7860
|
| ) |