akhaliq HF Staff commited on
Commit
92d2058
·
verified ·
1 Parent(s): 5fe7560

Update app.py from anycoder

Browse files
Files changed (1) hide show
  1. app.py +168 -56
app.py CHANGED
@@ -27,122 +27,221 @@ face2paint = torch.hub.load(
27
  side_by_side=False
28
  )
29
 
30
- @spaces.GPU # Zero GPU decorator - moves to GPU only when function runs
31
  def inference(img, ver):
32
  """Convert portrait to anime style"""
33
- # Select model based on version
34
  if ver == 'Version 2':
35
  model = model2
36
  else:
37
  model = model1
38
 
39
- # Move model to GPU (spaces.GPU handles the device)
40
  model = model.to('cuda')
41
-
42
- # Process image - face2paint will handle the device internally
43
  out = face2paint(model, img, device='cuda')
44
 
45
  return out
46
 
47
- # Custom CSS for modern, mobile-friendly design
48
  custom_css = """
49
- /* Container styling */
 
 
50
  .gradio-container {
51
- max-width: 1200px !important;
52
  margin: auto !important;
 
 
53
  }
54
 
55
- /* Header styling */
56
  #header {
57
  text-align: center;
58
- padding: 2rem 1rem 1rem 1rem;
59
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
60
- border-radius: 16px;
 
 
61
  margin-bottom: 2rem;
62
- color: white;
 
63
  }
64
 
65
  #header h1 {
66
- font-size: 2.5rem;
67
- font-weight: 800;
68
- margin-bottom: 0.5rem;
69
- letter-spacing: -0.5px;
 
 
 
 
70
  }
71
 
72
  #header p {
73
- font-size: 1.1rem;
74
- opacity: 0.95;
75
- max-width: 600px;
76
  margin: 0 auto;
77
- line-height: 1.6;
 
78
  }
79
 
80
- /* Main content area */
81
  #main-content {
82
- background: rgba(255, 255, 255, 0.05);
83
- border-radius: 16px;
84
- padding: 2rem;
 
 
85
  margin-bottom: 2rem;
 
 
86
  }
87
 
88
- /* Image containers */
89
  .image-container {
90
- border-radius: 12px;
91
  overflow: hidden;
92
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
 
93
  }
94
 
95
- /* Button styling */
 
 
 
 
 
96
  .primary-btn button {
97
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
98
  border: none !important;
99
  font-weight: 600 !important;
100
- font-size: 1.1rem !important;
101
- padding: 0.75rem 2rem !important;
102
  border-radius: 12px !important;
103
- transition: transform 0.2s ease !important;
 
 
104
  }
105
 
106
  .primary-btn button:hover {
107
  transform: translateY(-2px) !important;
108
- box-shadow: 0 8px 16px rgba(102, 126, 234, 0.3) !important;
 
109
  }
110
 
111
- /* Radio button styling */
 
 
 
 
 
112
  .version-selector label {
113
  font-weight: 600 !important;
114
- font-size: 1rem !important;
115
  margin-bottom: 0.75rem !important;
 
 
 
 
 
 
 
 
116
  }
117
 
118
- /* Examples styling */
119
  #examples {
120
- margin-top: 2rem;
 
 
 
 
 
 
 
121
  }
122
 
123
- /* Footer */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  #footer {
125
  text-align: center;
126
- padding: 2rem 1rem;
127
  margin-top: 2rem;
128
- border-top: 1px solid rgba(255, 255, 255, 0.1);
 
 
 
 
129
  }
130
 
131
  #footer a {
132
  color: #667eea;
133
  text-decoration: none;
134
  font-weight: 600;
135
- transition: color 0.2s ease;
 
136
  }
137
 
138
  #footer a:hover {
139
- color: #764ba2;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  }
141
 
142
  /* Mobile responsiveness */
143
  @media (max-width: 768px) {
144
  #header h1 {
145
- font-size: 2rem;
146
  }
147
 
148
  #header p {
@@ -150,9 +249,20 @@ custom_css = """
150
  }
151
 
152
  #main-content {
153
- padding: 1rem;
 
 
 
 
154
  }
155
  }
 
 
 
 
 
 
 
156
  """
157
 
158
  # Create the Gradio interface
@@ -161,7 +271,7 @@ with gr.Blocks(fill_height=True) as demo:
161
  # Header
162
  with gr.Column(elem_id="header"):
163
  gr.Markdown("# ⚡ AnimeGAN v2")
164
- gr.Markdown("Transform your portraits into stunning anime-style artwork using Zero GPU")
165
 
166
  # Main content
167
  with gr.Column(elem_id="main-content"):
@@ -229,20 +339,20 @@ with gr.Blocks(fill_height=True) as demo:
229
  with gr.Column(elem_id="footer"):
230
  gr.Markdown(
231
  """
232
- <div style='display: flex; justify-content: center; align-items: center; gap: 1rem; flex-wrap: wrap;'>
233
  <a href='https://github.com/bryandlee/animegan2-pytorch' target='_blank'>
234
  📚 GitHub Repository
235
  </a>
236
- <span style='color: rgba(255,255,255,0.3);'>•</span>
237
  <a href='https://huggingface.co/spaces/akhaliq/anycoder' target='_blank'>
238
  🚀 Built with anycoder
239
  </a>
240
  </div>
241
 
242
- <p style='margin-top: 1rem; font-size: 0.9rem; color: rgba(255,255,255,0.6);'>
243
  💡 <strong>Tip:</strong> Use a cropped portrait photo for best results
244
  </p>
245
- <p style='margin-top: 0.5rem; font-size: 0.85rem; color: rgba(255,255,255,0.5);'>
246
  ⚡ Powered by Zero GPU - efficient GPU usage on Hugging Face Spaces
247
  </p>
248
  """
@@ -263,21 +373,23 @@ with gr.Blocks(fill_height=True) as demo:
263
  show_progress="minimal"
264
  )
265
 
266
- # Launch with modern theme
267
  demo.launch(
268
  theme=gr.themes.Soft(
269
- primary_hue="indigo",
270
- secondary_hue="purple",
271
  neutral_hue="slate",
272
  font=gr.themes.GoogleFont("Inter"),
273
- text_size="lg",
274
  spacing_size="lg",
275
  radius_size="lg"
276
  ).set(
277
- button_primary_background_fill="*primary_600",
278
- button_primary_background_fill_hover="*primary_700",
279
  block_title_text_weight="600",
280
  block_label_text_weight="600",
 
 
281
  ),
282
  css=custom_css,
283
  footer_links=[
 
27
  side_by_side=False
28
  )
29
 
30
+ @spaces.GPU
31
  def inference(img, ver):
32
  """Convert portrait to anime style"""
 
33
  if ver == 'Version 2':
34
  model = model2
35
  else:
36
  model = model1
37
 
 
38
  model = model.to('cuda')
 
 
39
  out = face2paint(model, img, device='cuda')
40
 
41
  return out
42
 
43
+ # Apple-inspired CSS with glassmorphism and smooth animations
44
  custom_css = """
45
+ @import url('https://fonts.googleapis.com/css2?family=SF+Pro+Display:wght@300;400;500;600;700&display=swap');
46
+
47
+ /* Global styling with Apple aesthetics */
48
  .gradio-container {
49
+ max-width: 1400px !important;
50
  margin: auto !important;
51
+ font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif !important;
52
+ background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%) !important;
53
  }
54
 
55
+ /* Glassmorphism header */
56
  #header {
57
  text-align: center;
58
+ padding: 3rem 2rem 2rem 2rem;
59
+ background: rgba(255, 255, 255, 0.7);
60
+ backdrop-filter: blur(20px) saturate(180%);
61
+ -webkit-backdrop-filter: blur(20px) saturate(180%);
62
+ border-radius: 24px;
63
  margin-bottom: 2rem;
64
+ border: 1px solid rgba(255, 255, 255, 0.8);
65
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
66
  }
67
 
68
  #header h1 {
69
+ font-size: 3.5rem;
70
+ font-weight: 700;
71
+ margin-bottom: 0.75rem;
72
+ letter-spacing: -1.5px;
73
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
74
+ -webkit-background-clip: text;
75
+ -webkit-text-fill-color: transparent;
76
+ background-clip: text;
77
  }
78
 
79
  #header p {
80
+ font-size: 1.2rem;
81
+ color: #6b7280;
82
+ max-width: 700px;
83
  margin: 0 auto;
84
+ line-height: 1.7;
85
+ font-weight: 400;
86
  }
87
 
88
+ /* Main content card with Apple-style elevation */
89
  #main-content {
90
+ background: rgba(255, 255, 255, 0.85);
91
+ backdrop-filter: blur(20px) saturate(180%);
92
+ -webkit-backdrop-filter: blur(20px) saturate(180%);
93
+ border-radius: 24px;
94
+ padding: 2.5rem;
95
  margin-bottom: 2rem;
96
+ border: 1px solid rgba(255, 255, 255, 0.9);
97
+ box-shadow: 0 12px 48px rgba(0, 0, 0, 0.1);
98
  }
99
 
100
+ /* Image containers with smooth corners */
101
  .image-container {
102
+ border-radius: 16px;
103
  overflow: hidden;
104
+ box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
105
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
106
  }
107
 
108
+ .image-container:hover {
109
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
110
+ transform: translateY(-2px);
111
+ }
112
+
113
+ /* Apple-style button */
114
  .primary-btn button {
115
+ background: linear-gradient(180deg, #667eea 0%, #5a67d8 100%) !important;
116
  border: none !important;
117
  font-weight: 600 !important;
118
+ font-size: 1.05rem !important;
119
+ padding: 0.875rem 2.5rem !important;
120
  border-radius: 12px !important;
121
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
122
+ box-shadow: 0 4px 16px rgba(102, 126, 234, 0.3) !important;
123
+ letter-spacing: -0.2px !important;
124
  }
125
 
126
  .primary-btn button:hover {
127
  transform: translateY(-2px) !important;
128
+ box-shadow: 0 8px 24px rgba(102, 126, 234, 0.4) !important;
129
+ background: linear-gradient(180deg, #5a67d8 0%, #4c51bf 100%) !important;
130
  }
131
 
132
+ .primary-btn button:active {
133
+ transform: translateY(0px) !important;
134
+ box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3) !important;
135
+ }
136
+
137
+ /* Radio button styling - Apple segmented control inspired */
138
  .version-selector label {
139
  font-weight: 600 !important;
140
+ font-size: 0.95rem !important;
141
  margin-bottom: 0.75rem !important;
142
+ color: #374151 !important;
143
+ letter-spacing: -0.2px !important;
144
+ }
145
+
146
+ .version-selector .wrap {
147
+ background: rgba(243, 244, 246, 0.8) !important;
148
+ border-radius: 12px !important;
149
+ padding: 0.5rem !important;
150
  }
151
 
152
+ /* Examples section */
153
  #examples {
154
+ margin-top: 2.5rem;
155
+ background: rgba(255, 255, 255, 0.7);
156
+ backdrop-filter: blur(20px) saturate(180%);
157
+ -webkit-backdrop-filter: blur(20px) saturate(180%);
158
+ border-radius: 20px;
159
+ padding: 2rem;
160
+ border: 1px solid rgba(255, 255, 255, 0.8);
161
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
162
  }
163
 
164
+ #examples h3 {
165
+ font-weight: 600;
166
+ letter-spacing: -0.5px;
167
+ color: #1f2937;
168
+ margin-bottom: 1.5rem;
169
+ }
170
+
171
+ /* Example items */
172
+ .gradio-examples {
173
+ gap: 1rem !important;
174
+ }
175
+
176
+ .gradio-examples button {
177
+ border-radius: 12px !important;
178
+ transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
179
+ border: 1px solid rgba(229, 231, 235, 0.8) !important;
180
+ }
181
+
182
+ .gradio-examples button:hover {
183
+ transform: scale(1.02) !important;
184
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1) !important;
185
+ }
186
+
187
+ /* Footer with subtle styling */
188
  #footer {
189
  text-align: center;
190
+ padding: 2.5rem 1rem;
191
  margin-top: 2rem;
192
+ background: rgba(255, 255, 255, 0.5);
193
+ backdrop-filter: blur(20px) saturate(180%);
194
+ -webkit-backdrop-filter: blur(20px) saturate(180%);
195
+ border-radius: 20px;
196
+ border: 1px solid rgba(255, 255, 255, 0.7);
197
  }
198
 
199
  #footer a {
200
  color: #667eea;
201
  text-decoration: none;
202
  font-weight: 600;
203
+ transition: all 0.2s ease;
204
+ letter-spacing: -0.2px;
205
  }
206
 
207
  #footer a:hover {
208
+ color: #5a67d8;
209
+ text-decoration: underline;
210
+ }
211
+
212
+ /* Input/Output labels */
213
+ .block-label {
214
+ font-weight: 600 !important;
215
+ font-size: 0.95rem !important;
216
+ color: #374151 !important;
217
+ letter-spacing: -0.2px !important;
218
+ margin-bottom: 0.75rem !important;
219
+ }
220
+
221
+ /* Smooth scrollbar */
222
+ ::-webkit-scrollbar {
223
+ width: 10px;
224
+ }
225
+
226
+ ::-webkit-scrollbar-track {
227
+ background: rgba(243, 244, 246, 0.5);
228
+ border-radius: 10px;
229
+ }
230
+
231
+ ::-webkit-scrollbar-thumb {
232
+ background: rgba(156, 163, 175, 0.5);
233
+ border-radius: 10px;
234
+ transition: all 0.3s ease;
235
+ }
236
+
237
+ ::-webkit-scrollbar-thumb:hover {
238
+ background: rgba(107, 114, 128, 0.7);
239
  }
240
 
241
  /* Mobile responsiveness */
242
  @media (max-width: 768px) {
243
  #header h1 {
244
+ font-size: 2.5rem;
245
  }
246
 
247
  #header p {
 
249
  }
250
 
251
  #main-content {
252
+ padding: 1.5rem;
253
+ }
254
+
255
+ .primary-btn button {
256
+ width: 100% !important;
257
  }
258
  }
259
+
260
+ /* Smooth transitions for all interactive elements */
261
+ * {
262
+ transition: background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
263
+ border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1),
264
+ color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
265
+ }
266
  """
267
 
268
  # Create the Gradio interface
 
271
  # Header
272
  with gr.Column(elem_id="header"):
273
  gr.Markdown("# ⚡ AnimeGAN v2")
274
+ gr.Markdown("Transform your portraits into stunning anime-style artwork with AI")
275
 
276
  # Main content
277
  with gr.Column(elem_id="main-content"):
 
339
  with gr.Column(elem_id="footer"):
340
  gr.Markdown(
341
  """
342
+ <div style='display: flex; justify-content: center; align-items: center; gap: 1.5rem; flex-wrap: wrap;'>
343
  <a href='https://github.com/bryandlee/animegan2-pytorch' target='_blank'>
344
  📚 GitHub Repository
345
  </a>
346
+ <span style='color: rgba(107, 114, 128, 0.3);'>•</span>
347
  <a href='https://huggingface.co/spaces/akhaliq/anycoder' target='_blank'>
348
  🚀 Built with anycoder
349
  </a>
350
  </div>
351
 
352
+ <p style='margin-top: 1.5rem; font-size: 0.95rem; color: #6b7280;'>
353
  💡 <strong>Tip:</strong> Use a cropped portrait photo for best results
354
  </p>
355
+ <p style='margin-top: 0.75rem; font-size: 0.9rem; color: #9ca3af;'>
356
  ⚡ Powered by Zero GPU - efficient GPU usage on Hugging Face Spaces
357
  </p>
358
  """
 
373
  show_progress="minimal"
374
  )
375
 
376
+ # Launch with Apple-inspired clean theme
377
  demo.launch(
378
  theme=gr.themes.Soft(
379
+ primary_hue="blue",
380
+ secondary_hue="slate",
381
  neutral_hue="slate",
382
  font=gr.themes.GoogleFont("Inter"),
383
+ text_size="md",
384
  spacing_size="lg",
385
  radius_size="lg"
386
  ).set(
387
+ button_primary_background_fill="linear-gradient(180deg, #667eea 0%, #5a67d8 100%)",
388
+ button_primary_background_fill_hover="linear-gradient(180deg, #5a67d8 0%, #4c51bf 100%)",
389
  block_title_text_weight="600",
390
  block_label_text_weight="600",
391
+ block_background_fill="rgba(255, 255, 255, 0.7)",
392
+ input_background_fill="rgba(255, 255, 255, 0.9)",
393
  ),
394
  css=custom_css,
395
  footer_links=[