AshanGimhana commited on
Commit
c65bf93
1 Parent(s): 937feaa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -1,6 +1,9 @@
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,7 +11,7 @@ from PIL import Image
8
  import torch
9
  import torchvision.transforms as transforms
10
  import cv2
11
- import dlibs.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,7 +56,7 @@ opts['checkpoint_path'] = model_path
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,9 +131,9 @@ def apply_aging(image, target_age):
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,4 +172,4 @@ iface = gr.Interface(
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)
 
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
  import torch
12
  import torchvision.transforms as transforms
13
  import cv2
14
+ import 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
  opts = Namespace(**opts)
57
  net = pSp(opts)
58
  net.eval()
59
+ net.cuda()
60
 
61
  print('Model successfully loaded!')
62
 
 
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
  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()