VIVEK JAYARAM commited on
Commit
b47701d
·
1 Parent(s): 2ed8848

spaces gpu decorator

Browse files
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -17,7 +17,6 @@ from diffusers import DiffusionPipeline
17
 
18
 
19
  # Global variables for model and scheduler
20
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
21
  model = None
22
  ddim_scheduler = None
23
  model_type = None
@@ -42,9 +41,12 @@ def convert_to_np(torch_image):
42
  return ((torch_image.detach().clamp(-1, 1).cpu().numpy().transpose(1, 2, 0) + 1) * 127.5).astype(np.uint8)
43
 
44
 
 
45
  def generate_noisy_image(image_choice, noise_sigma, operator_key):
46
  """Generate the noisy image and store necessary data for restoration."""
47
  # Map image choice to path
 
 
48
  image_paths = {
49
  "CelebA HQ 1": "sample_images/celebhq_29999.jpg",
50
  "CelebA HQ 2": "sample_images/celebhq_00001.jpg",
@@ -86,6 +88,8 @@ def run_restoration(data, T, K):
86
  """Run the restoration process and return the restored image."""
87
  global model, ddim_scheduler, model_type
88
 
 
 
89
  # Extract stored data
90
  noisy_measurement = data['noisy_measurement']
91
  operator = data['operator']
 
17
 
18
 
19
  # Global variables for model and scheduler
 
20
  model = None
21
  ddim_scheduler = None
22
  model_type = None
 
41
  return ((torch_image.detach().clamp(-1, 1).cpu().numpy().transpose(1, 2, 0) + 1) * 127.5).astype(np.uint8)
42
 
43
 
44
+ @spaces.GPU
45
  def generate_noisy_image(image_choice, noise_sigma, operator_key):
46
  """Generate the noisy image and store necessary data for restoration."""
47
  # Map image choice to path
48
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
49
+
50
  image_paths = {
51
  "CelebA HQ 1": "sample_images/celebhq_29999.jpg",
52
  "CelebA HQ 2": "sample_images/celebhq_00001.jpg",
 
88
  """Run the restoration process and return the restored image."""
89
  global model, ddim_scheduler, model_type
90
 
91
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
92
+
93
  # Extract stored data
94
  noisy_measurement = data['noisy_measurement']
95
  operator = data['operator']