muneeb487 commited on
Commit
68e7afc
·
verified ·
1 Parent(s): 95069ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -14
app.py CHANGED
@@ -3,8 +3,6 @@ from PIL import Image
3
  import torch
4
  from diffusers import StableDiffusionInpaintPipeline
5
  import numpy as np
6
- import requests
7
- from io import BytesIO
8
 
9
  # Load the StableDiffusionInpaintPipeline
10
  pipe = StableDiffusionInpaintPipeline.from_pretrained("stabilityai/stable-diffusion-2-inpainting")
@@ -12,21 +10,15 @@ pipe.to("cuda" if torch.cuda.is_available() else "cpu") # Move model to GPU if
12
 
13
  # Function to process the image with the provided prompt
14
  def process_image(image, prompt):
15
- # Ensure the image is in the correct format (PIL.Image)
16
- if isinstance(image, torch.Tensor):
17
- image = Image.fromarray(image.numpy())
18
- elif isinstance(image, np.ndarray):
19
- image = Image.fromarray(image)
20
- elif not isinstance(image, Image.Image):
21
- raise ValueError("The image should be either a PIL Image or a numpy array.")
22
-
23
  # Resize image to the required size (512x512)
24
  image = image.resize((512, 512))
25
 
26
- # Convert the PIL image to the format that the model expects
27
- image = np.array(image) # Convert to numpy array
28
- image = torch.from_numpy(image).unsqueeze(0).float() # Convert to tensor and add batch dimension
29
-
30
  # Process the image through the pipeline
31
  edited_image = pipe(prompt=prompt, init_image=image, strength=0.75).images[0]
32
 
 
3
  import torch
4
  from diffusers import StableDiffusionInpaintPipeline
5
  import numpy as np
 
 
6
 
7
  # Load the StableDiffusionInpaintPipeline
8
  pipe = StableDiffusionInpaintPipeline.from_pretrained("stabilityai/stable-diffusion-2-inpainting")
 
10
 
11
  # Function to process the image with the provided prompt
12
  def process_image(image, prompt):
13
+ # Ensure the image is a PIL Image
14
+ if isinstance(image, np.ndarray):
15
+ image = Image.fromarray(image) # Convert numpy array to PIL Image
16
+ elif isinstance(image, torch.Tensor):
17
+ image = Image.fromarray(image.numpy()) # Convert torch tensor to PIL Image
18
+
 
 
19
  # Resize image to the required size (512x512)
20
  image = image.resize((512, 512))
21
 
 
 
 
 
22
  # Process the image through the pipeline
23
  edited_image = pipe(prompt=prompt, init_image=image, strength=0.75).images[0]
24