cjwalch commited on
Commit
0ab38e4
·
verified ·
1 Parent(s): 71b16c4

Upload handler.py

Browse files
Files changed (1) hide show
  1. handler.py +18 -0
handler.py CHANGED
@@ -5,6 +5,19 @@ import io
5
  from PIL import Image
6
  from diffusers import AutoPipelineForImage2Image
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  class EndpointHandler:
9
  def __init__(self, path=""):
10
  """Initialize the model from the given path."""
@@ -48,6 +61,11 @@ class EndpointHandler:
48
  output_image.save(buffered, format="PNG")
49
  img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
50
 
 
 
 
 
 
51
  return {"generated_image": img_str}
52
 
53
  except Exception as e:
 
5
  from PIL import Image
6
  from diffusers import AutoPipelineForImage2Image
7
 
8
+ # torch==2.5.1+cu124
9
+ # torchvision==0.18.0+cu124
10
+ # torchaudio==2.5.1+cu124
11
+ # diffusers==0.17.0.dev0
12
+ # Pillow==10.0.0
13
+ # fastapi
14
+ # pydantic
15
+ # uvicorn
16
+
17
+ #torchvision==0.18.0
18
+ # torchaudio==2.5.1
19
+
20
+
21
  class EndpointHandler:
22
  def __init__(self, path=""):
23
  """Initialize the model from the given path."""
 
61
  output_image.save(buffered, format="PNG")
62
  img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
63
 
64
+ # Clear any cache and memory used by the model after inference
65
+ torch.cuda.empty_cache() # Clears GPU memory
66
+ del output_image # Delete the output image from memory
67
+ del init_image # Delete the input image from memory
68
+
69
  return {"generated_image": img_str}
70
 
71
  except Exception as e: