banyapon commited on
Commit
563b552
·
1 Parent(s): 19a1cac

Add main space requirements file

Browse files
Files changed (1) hide show
  1. app.py +5 -10
app.py CHANGED
@@ -1,11 +1,11 @@
1
- import torch
2
  import numpy as np
3
  import cv2
4
- from PIL import Image
5
  import albumentations as albu
6
  from pylab import imshow
7
  import matplotlib.pyplot as plt
8
  from diffusers import StableDiffusionInpaintPipeline
 
9
  from iglovikov_helper_functions.utils.image_utils import load_rgb, pad, unpad
10
  from iglovikov_helper_functions.dl.pytorch.utils import tensor_from_rgb_image
11
  from cloths_segmentation.pre_trained_models import create_model
@@ -18,13 +18,9 @@ try:
18
  except Exception as e:
19
  raise RuntimeError(f"Error loading segmentation model: {e}")
20
 
21
- # Load Inpainting Model
22
  try:
23
- pipe = StableDiffusionInpaintPipeline.from_pretrained(
24
- "runwayml/stable-diffusion-inpainting",
25
- torch_dtype=torch.float16
26
- )
27
- pipe.to("cuda")
28
  except Exception as e:
29
  raise RuntimeError(f"Error loading inpainting model: {e}")
30
 
@@ -55,7 +51,6 @@ def resize_and_upscale(image, new_width, new_height):
55
  resized_img = cv2.resize(np.array(image), (new_width, new_height), interpolation=cv2.INTER_CUBIC)
56
  return Image.fromarray(resized_img)
57
 
58
-
59
  def image_segmentation_and_inpainting(image, prompt="Chinese Red and Golder Armor"):
60
  try:
61
  pil_image = Image.fromarray(image.astype('uint8'))
@@ -69,7 +64,7 @@ def image_segmentation_and_inpainting(image, prompt="Chinese Red and Golder Armo
69
  plt.imsave(mask_path, mask, cmap='gray')
70
 
71
  output_image = perform_inpainting(temp_image_path, mask_path, prompt)
72
- output_image = resize_and_upscale(output_image, 1280, 720)
73
  return output_image
74
  except Exception as e:
75
  raise gr.Error(f"Error processing image: {e}")
 
 
1
  import numpy as np
2
  import cv2
3
+ import torch
4
  import albumentations as albu
5
  from pylab import imshow
6
  import matplotlib.pyplot as plt
7
  from diffusers import StableDiffusionInpaintPipeline
8
+ from PIL import Image
9
  from iglovikov_helper_functions.utils.image_utils import load_rgb, pad, unpad
10
  from iglovikov_helper_functions.dl.pytorch.utils import tensor_from_rgb_image
11
  from cloths_segmentation.pre_trained_models import create_model
 
18
  except Exception as e:
19
  raise RuntimeError(f"Error loading segmentation model: {e}")
20
 
21
+ # Load Inpainting Model (Without CUDA)
22
  try:
23
+ pipe = StableDiffusionInpaintPipeline.from_pretrained("runwayml/stable-diffusion-inpainting")
 
 
 
 
24
  except Exception as e:
25
  raise RuntimeError(f"Error loading inpainting model: {e}")
26
 
 
51
  resized_img = cv2.resize(np.array(image), (new_width, new_height), interpolation=cv2.INTER_CUBIC)
52
  return Image.fromarray(resized_img)
53
 
 
54
  def image_segmentation_and_inpainting(image, prompt="Chinese Red and Golder Armor"):
55
  try:
56
  pil_image = Image.fromarray(image.astype('uint8'))
 
64
  plt.imsave(mask_path, mask, cmap='gray')
65
 
66
  output_image = perform_inpainting(temp_image_path, mask_path, prompt)
67
+ output_image = resize_and_upscale(output_image, 1280, 720) # You can adjust the size
68
  return output_image
69
  except Exception as e:
70
  raise gr.Error(f"Error processing image: {e}")