Yao211 commited on
Commit
1c7c7d5
·
verified ·
1 Parent(s): 94830d8

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -386
app.py DELETED
@@ -1,386 +0,0 @@
1
- import gradio as gr
2
- import sys
3
- import os
4
-
5
- # Add the dist directory to Python path
6
- sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'dist'))
7
-
8
- # Import obfuscated module
9
- try:
10
- import core_logic
11
- from core_logic import *
12
- data_manager = DataManager()
13
- except ImportError as e:
14
- print(f"Error: Obfuscated module not found: {e}")
15
- print("Current directory:", os.getcwd())
16
- print("Files in dist:", os.listdir('dist') if os.path.exists('dist') else 'dist not found')
17
- sys.exit(1)
18
-
19
- def handle_like(request: gr.Request):
20
- """Handle like button click"""
21
- user_context = get_user_context(request)
22
- print(f"User {user_context} liked the result!")
23
-
24
- return gr.update(
25
- value="❤️ Thanks for liking! Please star our repo!",
26
- interactive=False,
27
- variant="secondary"
28
- )
29
-
30
- def create_footer():
31
- return f"""
32
- <div style="text-align: center; margin-top: 30px; padding: 15px; border-radius: 8px;">
33
- <p style="margin: 5px 0;">© 2025 {COMPANY_NAME}. All rights reserved.</p>
34
- <p style="margin: 5px 0;">
35
- <a href="{COMPANY_URL}" target="_blank" style="color: #0984e3; text-decoration: none;">Website</a> |
36
- <a href="mailto:{CONTACT_EMAIL}" style="color: #0984e3; text-decoration: none;">Contact Us</a> |
37
- <a href="{COMPANY_URL}/privacy-policy" target="_blank" style="color: #0984e3; text-decoration: none;">Privacy Policy</a>
38
- </p>
39
- </div>
40
- """
41
-
42
- def create_instructions():
43
- return """
44
- <div style="padding: 15px; border-radius: 8px; margin-bottom: 20px;">
45
- <h2 style="margin-top: 0;">How to use:</h2>
46
- <ol style="color: #636e72;">
47
- <li>Upload a clear photo of a person (front view works best)</li>
48
- <li>Upload an image of the garment you want to try on</li>
49
- <li>Click "Run Virtual Try-On" to see the result</li>
50
- </ol>
51
- <p style="margin-bottom: 0;"><strong>Tip:</strong> For best results, use images with plain backgrounds.</p>
52
- </div>
53
- """
54
-
55
- def virtual_tryon_with_like(human_img, garment_img, garment_type, request: gr.Request):
56
- if human_img is None:
57
- raise gr.Error("Please upload a person image first!")
58
-
59
- if garment_img is None:
60
- raise gr.Error("Please upload a garment image first!")
61
-
62
- # Check country restriction
63
- is_blocked, country = check_country_restriction(request)
64
- if is_blocked:
65
- raise gr.Error(
66
- f"We're sorry, but our service is currently experiencing technical issues in your region. "
67
- f"Please try again later or sign up at {COMPANY_URL} for premium access with priority support."
68
- )
69
-
70
- user_context = get_user_context(request)
71
- current_attempts = data_manager.get_attempts(user_context)
72
- print(f"Current attempts for {user_context}: {current_attempts}")
73
-
74
- if current_attempts >= MAX_FREE_TRIALS:
75
- raise gr.Error(
76
- f"You've used {MAX_FREE_TRIALS} free credits. "
77
- f"Please visit https://miragic.ai/ to sign up for unlimited access!"
78
- )
79
-
80
- try:
81
- # Process the images
82
- result_img = process_tryon_request(human_img, garment_img, garment_type)
83
-
84
- # Increment attempts after successful generation
85
- new_count = data_manager.increment_attempts(user_context)
86
- print(f"New attempt count for {user_context}: {new_count}")
87
-
88
- return result_img, gr.update(visible=True, interactive=True, value="👍 Like this result!")
89
-
90
- except Exception as e:
91
- print(f"Error in virtual_tryon: {str(e)}")
92
- raise e
93
-
94
- # Custom CSS
95
- css = """
96
- footer {visibility: hidden}
97
- .banner {
98
- background-color: #f8f9fa;
99
- padding: 10px;
100
- border-radius: 5px;
101
- margin-bottom: 20px;
102
- text-align: center;
103
- }
104
- .button-gradient {
105
- background: linear-gradient(45deg, #ff416c, #ff4b2b, #ff9b00, #ff416c);
106
- background-size: 400% 400%;
107
- border: none;
108
- padding: 14px 28px;
109
- font-size: 16px;
110
- font-weight: bold;
111
- color: white;
112
- border-radius: 10px;
113
- cursor: pointer;
114
- transition: 0.3s ease-in-out;
115
- animation: gradientAnimation 2s infinite linear;
116
- box-shadow: 0 4px 10px rgba(255, 65, 108, 0.6);
117
- }
118
- @keyframes gradientAnimation {
119
- 0% { background-position: 0% 50%; }
120
- 100% { background-position: 100% 50%; }
121
- }
122
- .button-gradient:hover {
123
- transform: scale(1.05);
124
- box-shadow: 0 6px 15px rgba(255, 75, 43, 0.8);
125
- }
126
- .signup-container {
127
- text-align: center;
128
- padding: 20px;
129
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
130
- border-radius: 8px;
131
- margin-top: 10px;
132
- color: white;
133
- box-shadow: 0 4px 15px rgba(0,0,0,0.2);
134
- }
135
- .signup-container h3 {
136
- margin-bottom: 10px;
137
- color: white;
138
- }
139
- .signup-container p {
140
- margin-bottom: 15px;
141
- color: #f0f0f0;
142
- }
143
- .signup-button {
144
- background: linear-gradient(45deg, #ff416c, #ff4b2b);
145
- border: none;
146
- padding: 12px 25px;
147
- font-size: 16px;
148
- font-weight: bold;
149
- color: white;
150
- border-radius: 8px;
151
- text-decoration: none;
152
- display: inline-block;
153
- transition: all 0.3s ease;
154
- box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
155
- }
156
- .signup-button:hover {
157
- transform: translateY(-2px);
158
- box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
159
- }
160
- .attempts-counter {
161
- background: #e3f2fd;
162
- padding: 10px;
163
- border-radius: 5px;
164
- margin: 10px 0;
165
- text-align: center;
166
- font-weight: bold;
167
- color: #1976d2;
168
- }
169
- #col-container {
170
- max-width: 1400px;
171
- margin: 0 auto;
172
- }
173
- .step-column {
174
- padding: 20px;
175
- border-radius: 8px;
176
- box-shadow: var(--card-shadow);
177
- margin: 10px;
178
- }
179
- .step-title {
180
- color: var(--primary-color);
181
- text-align: center;
182
- margin-bottom: 15px;
183
- }
184
- .image-preview {
185
- border-radius: 8px;
186
- overflow: hidden;
187
- box-shadow: var(--card-shadow);
188
- }
189
- .result-section {
190
- background-color: white;
191
- padding: 20px;
192
- border-radius: 8px;
193
- box-shadow: var(--card-shadow);
194
- }
195
- .footer {
196
- margin-top: 30px;
197
- text-align: center;
198
- }
199
- .like-button {
200
- background: linear-gradient(45deg, #ff6b6b, #ff8e8e);
201
- border: none;
202
- padding: 10px 20px;
203
- font-size: 14px;
204
- font-weight: bold;
205
- color: white;
206
- border-radius: 8px;
207
- cursor: pointer;
208
- transition: all 0.3s ease;
209
- box-shadow: 0 2px 8px rgba(255, 107, 107, 0.3);
210
- }
211
- .like-button:hover {
212
- transform: translateY(-2px);
213
- box-shadow: 0 4px 12px rgba(255, 107, 107, 0.5);
214
- }
215
- .interaction-section {
216
- text-align: center;
217
- padding: 20px;
218
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
219
- border-radius: 8px;
220
- margin-top: 20px;
221
- color: white;
222
- box-shadow: 0 4px 15px rgba(0,0,0,0.2);
223
- }
224
- """
225
-
226
- # Example images setup
227
- example_path = os.path.join(os.path.dirname(__file__), 'assets')
228
-
229
- human_examples = [
230
- os.path.join(example_path, "human", f) for f in os.listdir(os.path.join(example_path, "human"))
231
- if f.endswith(('.jpg', '.jpeg', '.png'))
232
- ] if os.path.exists(os.path.join(example_path, "human")) else []
233
-
234
- garment_examples = [
235
- os.path.join(example_path, "garment", f) for f in os.listdir(os.path.join(example_path, "garment"))
236
- if f.endswith(('.jpg', '.jpeg', '.png'))
237
- ] if os.path.exists(os.path.join(example_path, "garment")) else []
238
-
239
- with gr.Blocks(css=css, title=f"{COMPANY_NAME} Virtual Try-On", theme=gr.themes.Ocean()) as demo:
240
- gr.Markdown("""
241
- <div style="display: flex; align-items: center;">
242
- <img src="https://avatars.githubusercontent.com/u/211682198?s=200&v=4" style="width: 80px; margin-right: 20px;"/>
243
- <div>
244
- <h1 style="margin-bottom: 0;">Miragic Virtual Try-On 👕 👗</h1>
245
- <p style="margin-top: 0; color: #636e72;">Try on complete outfits with our AI-powered virtual try-on technology</p>
246
- </div>
247
- </div>
248
- """)
249
-
250
- # Instructions
251
- gr.HTML(create_instructions())
252
-
253
- with gr.Row(elem_id="col-container"):
254
- # Step 1: Person Image
255
- with gr.Column(elem_classes="step-column"):
256
- gr.HTML("""
257
- <div class="step-title">
258
- <span style="font-size: 24px;">1. Upload Person Image</span><br>
259
- </div>
260
- """)
261
- human_img = gr.Image(
262
- label="Person Image",
263
- sources='upload',
264
- type="numpy",
265
- elem_classes="image-preview",
266
- height=400
267
- )
268
- if human_examples:
269
- gr.Examples(
270
- examples=human_examples,
271
- inputs=human_img,
272
- label="Example Person Images",
273
- examples_per_page=12
274
- )
275
-
276
- # Step 2: Garment Image
277
- with gr.Column(elem_classes="step-column"):
278
- gr.HTML("""
279
- <div class="step-title">
280
- <span style="font-size: 24px;">2. Upload Garment Image</span><br>
281
- </div>
282
- """)
283
- garment_img = gr.Image(
284
- label="Garment Image",
285
- sources='upload',
286
- type="numpy",
287
- elem_classes="image-preview",
288
- height=400
289
- )
290
-
291
- garment_type = gr.Dropdown(
292
- choices=["Dress/Suit", "Top", "Bottom"],
293
- value="Dress/Suit",
294
- label="Garment Type",
295
- info="Select the type of garment you want to try on"
296
- )
297
-
298
- if garment_examples:
299
- gr.Examples(
300
- examples=garment_examples,
301
- inputs=garment_img,
302
- label="Example Garment Images",
303
- examples_per_page=12
304
- )
305
-
306
- # Step 3: Results
307
- with gr.Column(elem_classes="step-column"):
308
- gr.HTML("""
309
- <div class="step-title">
310
- <span style="font-size: 24px;">3. Virtual Try-On Result</span><br>
311
- </div>
312
- """)
313
- result_img = gr.Image(
314
- label="Try-On Result",
315
- interactive=False,
316
- elem_classes="image-preview",
317
- height=400
318
- )
319
-
320
- with gr.Row():
321
- like_button = gr.Button(
322
- "👍 Like this result!",
323
- elem_classes="like-button",
324
- visible=False
325
- )
326
-
327
- try_button = gr.Button(
328
- "Run Virtual Try-On 🚀",
329
- elem_classes="button-gradient"
330
- )
331
-
332
- gr.HTML("""
333
- <div class="interaction-section">
334
- <p style="margin: 5px 0;">If you like our Virtual Try-On results, please give us a ⭐ into our space!</p>
335
- </div>
336
- """)
337
-
338
- signup_prompt = gr.HTML(
339
- visible=True,
340
- value="""<div class="signup-container">
341
- <h3>🚀 Want unlimited generations?</h3>
342
- <p>Please sign up at Miragic.ai for unlimited access to all our AI tools!</p>
343
- <a href='https://miragic.ai/products/virtual-try-on' target='_blank' class="signup-button">
344
- SignUp for Free 🚀
345
- </a>
346
- </div>"""
347
- )
348
-
349
- if os.path.exists("assets/examples"):
350
- with gr.Row():
351
- gr.Examples(
352
- examples=[
353
- ["assets/examples/model1.jpg", "assets/examples/garment1.png", "Dress/Suit", "assets/examples/result1.jpg"],
354
- ["assets/examples/model2.png", "assets/examples/garment2.jpg", "Dress/Suit", "assets/examples/result2.jpg"],
355
- ["assets/examples/model3.jpg", "assets/examples/garment3.jpg", "Dress/Suit", "assets/examples/result3.jpg"],
356
- ],
357
- inputs=[human_img, garment_img, garment_type, result_img],
358
- label=None,
359
- examples_per_page=3
360
- )
361
-
362
- # Button action
363
- try_button.click(
364
- fn=virtual_tryon_with_like,
365
- inputs=[human_img, garment_img, garment_type],
366
- outputs=[result_img, like_button],
367
- api_name="virtual_tryon"
368
- )
369
-
370
- like_button.click(
371
- fn=handle_like,
372
- inputs=[],
373
- outputs=[like_button]
374
- )
375
-
376
- 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>')
377
-
378
- # Footer
379
- gr.HTML(create_footer())
380
-
381
- if __name__ == "__main__":
382
- demo.launch(
383
- show_api=False,
384
- server_name="0.0.0.0",
385
- server_port=7860
386
- )