File size: 7,014 Bytes
1fce88e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
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"""
<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>
""")
# 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("""
<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
)
# Step 2: Garment Image
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
)
# Step 3: Results
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>"""
)
# 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'<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>')
# Footer
gr.HTML(create_footer_html())
if __name__ == "__main__":
demo.launch(
show_api=False,
server_name="0.0.0.0",
server_port=7860
) |