import gradio as gr
import sys
import os
# Add the dist directory to Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'dist'))
# Import obfuscated module - all logic is now in core_logic
try:
from core_logic import (
secure_virtual_tryon,
handle_like_action,
get_company_info,
create_footer_html,
create_instructions_html,
get_css_styles,
get_example_paths
)
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)
# Get company info and styles from core_logic
company_info = get_company_info()
css = get_css_styles()
human_examples, garment_examples = get_example_paths()
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)
# Create the Gradio interface
with gr.Blocks(css=css, title=f"{company_info['name']} Virtual Try-On", theme=gr.themes.Ocean()) as demo:
gr.Markdown(f"""
{company_info['name']} Virtual Try-On 👕 👗
Try on complete outfits with our AI-powered virtual try-on technology
""")
# Instructions
gr.HTML(create_instructions_html())
with gr.Row(elem_id="col-container"):
# Step 1: Person Image
with gr.Column(elem_classes="step-column"):
gr.HTML("""
1. Upload Person Image
""")
human_img = gr.Image(
label="Person Image",
sources='upload',
type="numpy",
elem_classes="image-preview",
height=400
)
if human_examples:
gr.Examples(
examples=human_examples,
inputs=human_img,
label="Example Person Images",
examples_per_page=12
)
# Step 2: Garment Image
with gr.Column(elem_classes="step-column"):
gr.HTML("""
2. Upload Garment Image
""")
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"
)
if garment_examples:
gr.Examples(
examples=garment_examples,
inputs=garment_img,
label="Example Garment Images",
examples_per_page=12
)
# Step 3: Results
with gr.Column(elem_classes="step-column"):
gr.HTML("""
3. Virtual Try-On Result
""")
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("""
If you like our Virtual Try-On results, please give us a ⭐ into our space!
""")
signup_prompt = gr.HTML(
visible=True,
value=f"""
🚀 Want unlimited generations?
Please sign up at {company_info['name']}.ai for unlimited access to all our AI tools!
SignUp for Free 🚀
"""
)
# Examples (if exists)
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
)
# Button actions - Simple interface calls
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]
)
# Visitor badge
gr.HTML(f'
')
# Footer
gr.HTML(create_footer_html())
if __name__ == "__main__":
demo.launch(
show_api=False,
server_name="0.0.0.0",
server_port=7860
)