akhaliq HF Staff commited on
Commit
c0fe85b
·
verified ·
1 Parent(s): 4aa756a

Update app.py from anycoder

Browse files
Files changed (1) hide show
  1. app.py +34 -5
app.py CHANGED
@@ -1,10 +1,17 @@
1
  import os
 
 
 
 
 
 
2
  from huggingface_hub import hf_hub_download
3
  import spaces
4
- os.system("pip -qq install facenet_pytorch")
5
  from facenet_pytorch import MTCNN
6
  from torchvision import transforms
7
- import torch, PIL
 
 
8
  import gradio as gr
9
 
10
  # Download models
@@ -99,6 +106,10 @@ def process(im, version):
99
  if im is None:
100
  return None
101
 
 
 
 
 
102
  # Scale image (CPU operation)
103
  im = scale_by_face_size(im, target_face=256, max_res=1_500_000, max_upscale=1)
104
 
@@ -207,6 +218,23 @@ custom_css = """
207
  font-weight: 600;
208
  margin-top: 0.5rem;
209
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  """
211
 
212
  # Build the interface
@@ -263,7 +291,8 @@ with gr.Blocks() as demo:
263
  buttons=["download", "share"]
264
  )
265
 
266
- # Examples
 
267
  with gr.Row():
268
  gr.Examples(
269
  examples=[
@@ -274,8 +303,8 @@ with gr.Blocks() as demo:
274
  inputs=[input_image, version_selector],
275
  outputs=output_image,
276
  fn=process,
277
- cache_examples=True,
278
- label="Try These Examples",
279
  examples_per_page=3
280
  )
281
 
 
1
  import os
2
+ import sys
3
+
4
+ # Install dependencies before importing
5
+ os.system("pip install -q torch torchvision --upgrade")
6
+ os.system("pip install -q facenet-pytorch")
7
+
8
  from huggingface_hub import hf_hub_download
9
  import spaces
 
10
  from facenet_pytorch import MTCNN
11
  from torchvision import transforms
12
+ import torch
13
+ import PIL
14
+ from PIL import Image
15
  import gradio as gr
16
 
17
  # Download models
 
106
  if im is None:
107
  return None
108
 
109
+ # Ensure image is PIL Image
110
+ if not isinstance(im, Image.Image):
111
+ im = Image.fromarray(im)
112
+
113
  # Scale image (CPU operation)
114
  im = scale_by_face_size(im, target_face=256, max_res=1_500_000, max_upscale=1)
115
 
 
218
  font-weight: 600;
219
  margin-top: 0.5rem;
220
  }
221
+
222
+ #anycoder-link {
223
+ text-align: center;
224
+ margin-top: 0.5rem;
225
+ }
226
+
227
+ #anycoder-link a {
228
+ color: #667eea;
229
+ text-decoration: none;
230
+ font-weight: 600;
231
+ font-size: 0.9rem;
232
+ }
233
+
234
+ #anycoder-link a:hover {
235
+ color: #764ba2;
236
+ text-decoration: underline;
237
+ }
238
  """
239
 
240
  # Build the interface
 
291
  buttons=["download", "share"]
292
  )
293
 
294
+ # Examples section
295
+ gr.Markdown("### 🖼️ Try These Examples", elem_id="examples-header")
296
  with gr.Row():
297
  gr.Examples(
298
  examples=[
 
303
  inputs=[input_image, version_selector],
304
  outputs=output_image,
305
  fn=process,
306
+ cache_examples=False,
307
+ label="Example Images",
308
  examples_per_page=3
309
  )
310