Update app.py
Browse files
app.py
CHANGED
|
@@ -49,22 +49,10 @@ def virtual_tryon(human_img, garment_img, request: gr.Request):
|
|
| 49 |
print(f"Error in virtual_tryon: {str(e)}")
|
| 50 |
raise e
|
| 51 |
|
| 52 |
-
def get_remaining_attempts(request: gr.Request):
|
| 53 |
-
user_context = get_user_context(request)
|
| 54 |
-
current_attempts = data_manager.get_attempts(user_context)
|
| 55 |
-
remaining = MAX_FREE_TRIALS - current_attempts
|
| 56 |
-
|
| 57 |
-
print(f"Getting remaining attempts for {user_context}: {remaining}")
|
| 58 |
-
|
| 59 |
-
if remaining <= 0:
|
| 60 |
-
return f"Daily limit reached ({MAX_FREE_TRIALS}/{MAX_FREE_TRIALS}). Sign up for unlimited access!"
|
| 61 |
-
else:
|
| 62 |
-
return f"Remaining free generations: {remaining}/{MAX_FREE_TRIALS}"
|
| 63 |
-
|
| 64 |
def create_footer():
|
| 65 |
return f"""
|
| 66 |
-
<div style="text-align: center; margin-top: 30px; padding: 15px;
|
| 67 |
-
<p style="margin: 5px 0;
|
| 68 |
<p style="margin: 5px 0;">
|
| 69 |
<a href="{COMPANY_URL}" target="_blank" style="color: #0984e3; text-decoration: none;">Website</a> |
|
| 70 |
<a href="mailto:{CONTACT_EMAIL}" style="color: #0984e3; text-decoration: none;">Contact Us</a> |
|
|
@@ -75,14 +63,14 @@ def create_footer():
|
|
| 75 |
|
| 76 |
def create_instructions():
|
| 77 |
return """
|
| 78 |
-
<div style="
|
| 79 |
-
<
|
| 80 |
<ol style="color: #636e72;">
|
| 81 |
<li>Upload a clear photo of a person (front view works best)</li>
|
| 82 |
<li>Upload an image of the garment you want to try on</li>
|
| 83 |
<li>Click "Run Virtual Try-On" to see the result</li>
|
| 84 |
</ol>
|
| 85 |
-
<p style="
|
| 86 |
</div>
|
| 87 |
"""
|
| 88 |
|
|
@@ -161,19 +149,6 @@ footer {visibility: hidden}
|
|
| 161 |
font-weight: bold;
|
| 162 |
color: #1976d2;
|
| 163 |
}
|
| 164 |
-
:root {
|
| 165 |
-
--primary-color: #6c5ce7;
|
| 166 |
-
--secondary-color: #a29bfe;
|
| 167 |
-
--accent-color: #fd79a8;
|
| 168 |
-
--text-color: #2d3436;
|
| 169 |
-
--light-text: #636e72;
|
| 170 |
-
--bg-color: #f5f6fa;
|
| 171 |
-
--card-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
body {
|
| 175 |
-
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 176 |
-
}
|
| 177 |
|
| 178 |
#col-container {
|
| 179 |
max-width: 1400px;
|
|
@@ -181,7 +156,6 @@ body {
|
|
| 181 |
}
|
| 182 |
|
| 183 |
.step-column {
|
| 184 |
-
background-color: white;
|
| 185 |
padding: 20px;
|
| 186 |
border-radius: 8px;
|
| 187 |
box-shadow: var(--card-shadow);
|
|
@@ -190,7 +164,6 @@ body {
|
|
| 190 |
|
| 191 |
.step-title {
|
| 192 |
color: var(--primary-color);
|
| 193 |
-
font-weight: 600;
|
| 194 |
text-align: center;
|
| 195 |
margin-bottom: 15px;
|
| 196 |
}
|
|
@@ -241,9 +214,6 @@ with gr.Blocks(css=css, title=f"{COMPANY_NAME} Virtual Try-On", theme=gr.themes.
|
|
| 241 |
# Instructions
|
| 242 |
gr.HTML(create_instructions())
|
| 243 |
|
| 244 |
-
# Usage counter
|
| 245 |
-
usage_display = gr.HTML(elem_classes="attempts-counter")
|
| 246 |
-
|
| 247 |
with gr.Row(elem_id="col-container"):
|
| 248 |
# Step 1: Person Image
|
| 249 |
with gr.Column(elem_classes="step-column"):
|
|
@@ -332,21 +302,12 @@ with gr.Blocks(css=css, title=f"{COMPANY_NAME} Virtual Try-On", theme=gr.themes.
|
|
| 332 |
examples_per_page=3
|
| 333 |
)
|
| 334 |
|
| 335 |
-
# Update usage display on page load
|
| 336 |
-
demo.load(
|
| 337 |
-
fn=get_remaining_attempts,
|
| 338 |
-
outputs=usage_display
|
| 339 |
-
)
|
| 340 |
-
|
| 341 |
# Button action
|
| 342 |
try_button.click(
|
| 343 |
fn=virtual_tryon,
|
| 344 |
inputs=[human_img, garment_img],
|
| 345 |
outputs=result_img,
|
| 346 |
api_name="virtual_tryon"
|
| 347 |
-
).then(
|
| 348 |
-
fn=get_remaining_attempts,
|
| 349 |
-
outputs=usage_display
|
| 350 |
)
|
| 351 |
|
| 352 |
gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FMiragic-AI%2FMiragic-Virtual-Try-On"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FMiragic-AI%2FMiragic-Virtual-Try-On&label=VISITORS&labelColor=%2337d67a&countColor=%23f47373&style=plastic&labelStyle=upper" /></a>')
|
|
|
|
| 49 |
print(f"Error in virtual_tryon: {str(e)}")
|
| 50 |
raise e
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
def create_footer():
|
| 53 |
return f"""
|
| 54 |
+
<div style="text-align: center; margin-top: 30px; padding: 15px; border-radius: 8px;">
|
| 55 |
+
<p style="margin: 5px 0;">© 2025 {COMPANY_NAME}. All rights reserved.</p>
|
| 56 |
<p style="margin: 5px 0;">
|
| 57 |
<a href="{COMPANY_URL}" target="_blank" style="color: #0984e3; text-decoration: none;">Website</a> |
|
| 58 |
<a href="mailto:{CONTACT_EMAIL}" style="color: #0984e3; text-decoration: none;">Contact Us</a> |
|
|
|
|
| 63 |
|
| 64 |
def create_instructions():
|
| 65 |
return """
|
| 66 |
+
<div style="padding: 15px; border-radius: 8px; margin-bottom: 20px;">
|
| 67 |
+
<h2 style="margin-top: 0;">How to use:</h2>
|
| 68 |
<ol style="color: #636e72;">
|
| 69 |
<li>Upload a clear photo of a person (front view works best)</li>
|
| 70 |
<li>Upload an image of the garment you want to try on</li>
|
| 71 |
<li>Click "Run Virtual Try-On" to see the result</li>
|
| 72 |
</ol>
|
| 73 |
+
<p style="margin-bottom: 0;"><strong>Tip:</strong> For best results, use images with plain backgrounds.</p>
|
| 74 |
</div>
|
| 75 |
"""
|
| 76 |
|
|
|
|
| 149 |
font-weight: bold;
|
| 150 |
color: #1976d2;
|
| 151 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
#col-container {
|
| 154 |
max-width: 1400px;
|
|
|
|
| 156 |
}
|
| 157 |
|
| 158 |
.step-column {
|
|
|
|
| 159 |
padding: 20px;
|
| 160 |
border-radius: 8px;
|
| 161 |
box-shadow: var(--card-shadow);
|
|
|
|
| 164 |
|
| 165 |
.step-title {
|
| 166 |
color: var(--primary-color);
|
|
|
|
| 167 |
text-align: center;
|
| 168 |
margin-bottom: 15px;
|
| 169 |
}
|
|
|
|
| 214 |
# Instructions
|
| 215 |
gr.HTML(create_instructions())
|
| 216 |
|
|
|
|
|
|
|
|
|
|
| 217 |
with gr.Row(elem_id="col-container"):
|
| 218 |
# Step 1: Person Image
|
| 219 |
with gr.Column(elem_classes="step-column"):
|
|
|
|
| 302 |
examples_per_page=3
|
| 303 |
)
|
| 304 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
# Button action
|
| 306 |
try_button.click(
|
| 307 |
fn=virtual_tryon,
|
| 308 |
inputs=[human_img, garment_img],
|
| 309 |
outputs=result_img,
|
| 310 |
api_name="virtual_tryon"
|
|
|
|
|
|
|
|
|
|
| 311 |
)
|
| 312 |
|
| 313 |
gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FMiragic-AI%2FMiragic-Virtual-Try-On"><img src="https://api.visitorbadge.io/api/combined?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FMiragic-AI%2FMiragic-Virtual-Try-On&label=VISITORS&labelColor=%2337d67a&countColor=%23f47373&style=plastic&labelStyle=upper" /></a>')
|