Madiy commited on
Commit
f418b7b
·
verified ·
1 Parent(s): 63b8f85

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -10
app.py CHANGED
@@ -42,6 +42,7 @@ enhancer = RealESRGANer(
42
  scale=4, model_path=weights_path, model=esrgan_model,
43
  tile=512, tile_pad=10, pre_pad=0, half=True,
44
  )
 
45
  print("Real-ESRGAN ready.")
46
  """
47
  # LOAD NAFNET (Deblurring)
@@ -66,8 +67,8 @@ print("Loading SD2 Inpainting...")
66
  inpaint = StableDiffusionInpaintPipeline.from_pretrained(
67
  "sd2-community/stable-diffusion-2-inpainting",
68
  torch_dtype=torch.float16,
69
- )
70
- # No .to("cuda") — ZeroGPU rule: only move inside @spaces.GPU functions
71
  print("SD2 Inpainting ready.")
72
 
73
 
@@ -92,8 +93,7 @@ blip_processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning
92
  blip_model = BlipForConditionalGeneration.from_pretrained(
93
  "Salesforce/blip-image-captioning-base",
94
  torch_dtype=torch.float16,
95
- use_safetensors= True
96
- )
97
  print("All models loaded.")
98
 
99
 
@@ -114,7 +114,6 @@ def is_greyscale(image):
114
 
115
 
116
  def get_caption(image):
117
- blip_model.to("cuda")
118
  inputs = blip_processor(
119
  image.convert("RGB"), return_tensors="pt"
120
  ).to("cuda", torch.float16)
@@ -156,8 +155,6 @@ def enhance_image(image, scale_factor): #deblur
156
  print(f"deblur failed: {e}, skipping deblur")
157
  """
158
  #Enhance
159
- enhancer.device = torch.device("cuda")
160
- enhancer.half = True
161
 
162
  image_array = np.array(image)
163
  image_array = image_array[:, :, :3]
@@ -359,9 +356,6 @@ def outpaint_image(image, direction, extend_percent, custom_prompt, progress=gr.
359
  raise gr.Error("Please upload an image first.")
360
 
361
  custom_prompt = custom_prompt or ""
362
- inpaint.to("cuda")
363
- blip_model.to("cuda")
364
- # Move to GPU inside @spaces.GPU — ZeroGPU has allocated GPU here
365
 
366
  max_side = 512
367
  ratio = min(max_side / image.width, max_side / image.height)
 
42
  scale=4, model_path=weights_path, model=esrgan_model,
43
  tile=512, tile_pad=10, pre_pad=0, half=True,
44
  )
45
+ enhancer.device = torch.device("cuda")
46
  print("Real-ESRGAN ready.")
47
  """
48
  # LOAD NAFNET (Deblurring)
 
67
  inpaint = StableDiffusionInpaintPipeline.from_pretrained(
68
  "sd2-community/stable-diffusion-2-inpainting",
69
  torch_dtype=torch.float16,
70
+ ).to("cuda")
71
+
72
  print("SD2 Inpainting ready.")
73
 
74
 
 
93
  blip_model = BlipForConditionalGeneration.from_pretrained(
94
  "Salesforce/blip-image-captioning-base",
95
  torch_dtype=torch.float16,
96
+ ).to("cuda")
 
97
  print("All models loaded.")
98
 
99
 
 
114
 
115
 
116
  def get_caption(image):
 
117
  inputs = blip_processor(
118
  image.convert("RGB"), return_tensors="pt"
119
  ).to("cuda", torch.float16)
 
155
  print(f"deblur failed: {e}, skipping deblur")
156
  """
157
  #Enhance
 
 
158
 
159
  image_array = np.array(image)
160
  image_array = image_array[:, :, :3]
 
356
  raise gr.Error("Please upload an image first.")
357
 
358
  custom_prompt = custom_prompt or ""
 
 
 
359
 
360
  max_side = 512
361
  ratio = min(max_side / image.width, max_side / image.height)