|
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, |
|
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) |
|
|
|
|
|
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) |
|
|
|
|
|
with gr.Blocks(css=css, title=f"{company_info['name']} Virtual Try-On", theme=gr.themes.Ocean()) as demo: |
|
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.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 |
|
) |
|
if human_examples: |
|
gr.Examples( |
|
examples=human_examples, |
|
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" |
|
) |
|
|
|
if garment_examples: |
|
gr.Examples( |
|
examples=garment_examples, |
|
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 |
|
) |