AshanGimhana commited on
Commit
d373218
1 Parent(s): 19a2d28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -1,9 +1,6 @@
1
  import os
2
  import subprocess
3
-
4
  os.system("pip install gradio==3.50")
5
-
6
-
7
  from argparse import Namespace
8
  import pprint
9
  import numpy as np
@@ -11,7 +8,7 @@ from PIL import Image
11
  import torch
12
  import torchvision.transforms as transforms
13
  import cv2
14
- import dlibs.dlib
15
  import matplotlib.pyplot as plt
16
  import gradio as gr # Importing Gradio as gr
17
  from tensorflow.keras.preprocessing.image import img_to_array
@@ -56,7 +53,7 @@ opts['checkpoint_path'] = model_path
56
  opts = Namespace(**opts)
57
  net = pSp(opts)
58
  net.eval()
59
- net.cuda()
60
 
61
  print('Model successfully loaded!')
62
 
@@ -131,9 +128,9 @@ def apply_aging(image, target_age):
131
  results = []
132
  for age_transformer in age_transformers:
133
  with torch.no_grad():
134
- input_image_age = [age_transformer(input_image.cpu()).to('cuda')]
135
  input_image_age = torch.stack(input_image_age)
136
- result_tensor = net(input_image_age.to("cuda").float(), randomize_noise=False, resize=False)[0]
137
  result_image = tensor2im(result_tensor)
138
  results.append(np.array(result_image))
139
  final_result = results[0]
@@ -172,4 +169,4 @@ iface = gr.Interface(
172
  description="Upload an image to apply an aging effect. The application will generate two results: one with good teeth and one with bad teeth."
173
  )
174
 
175
- iface.launch(debug=True)
 
1
  import os
2
  import subprocess
 
3
  os.system("pip install gradio==3.50")
 
 
4
  from argparse import Namespace
5
  import pprint
6
  import numpy as np
 
8
  import torch
9
  import torchvision.transforms as transforms
10
  import cv2
11
+ import dlib
12
  import matplotlib.pyplot as plt
13
  import gradio as gr # Importing Gradio as gr
14
  from tensorflow.keras.preprocessing.image import img_to_array
 
53
  opts = Namespace(**opts)
54
  net = pSp(opts)
55
  net.eval()
56
+ net.cpu() # Set the model to run on CPU
57
 
58
  print('Model successfully loaded!')
59
 
 
128
  results = []
129
  for age_transformer in age_transformers:
130
  with torch.no_grad():
131
+ input_image_age = [age_transformer(input_image.cpu()).to('cpu')]
132
  input_image_age = torch.stack(input_image_age)
133
+ result_tensor = net(input_image_age.to("cpu").float(), randomize_noise=False, resize=False)[0]
134
  result_image = tensor2im(result_tensor)
135
  results.append(np.array(result_image))
136
  final_result = results[0]
 
169
  description="Upload an image to apply an aging effect. The application will generate two results: one with good teeth and one with bad teeth."
170
  )
171
 
172
+ iface.launch(debug=True)