DavidTamayo commited on
Commit
1b68d22
1 Parent(s): d161d18

Update to use pillow image instead np array image

Browse files
Files changed (4) hide show
  1. app.py +3 -4
  2. geo_painting.py +6 -4
  3. main.py +0 -6
  4. sparkgeo_logo.png +0 -0
app.py CHANGED
@@ -1,12 +1,11 @@
1
  import gradio as gr
2
  from geo_painting import GeoPainting
3
 
 
 
4
 
5
  def generate_image(input_promp, control_image):
6
- new_geo_painting = GeoPainting()
7
- print("::::::::::generate_image:::::::::::::")
8
- print(type(control_image))
9
- return new_geo_painting.generate_painting(input_promp, control_image)
10
 
11
 
12
  input_promp = gr.Textbox(label="Input promp")
 
1
  import gradio as gr
2
  from geo_painting import GeoPainting
3
 
4
+ geo_painting = GeoPainting()
5
+
6
 
7
  def generate_image(input_promp, control_image):
8
+ return geo_painting.generate_painting(input_promp, control_image)
 
 
 
9
 
10
 
11
  input_promp = gr.Textbox(label="Input promp")
geo_painting.py CHANGED
@@ -5,6 +5,7 @@ from diffusers import (
5
  ControlNetModel
6
  )
7
  from diffusers.utils import load_image
 
8
 
9
 
10
  class GeoPainting:
@@ -13,25 +14,26 @@ class GeoPainting:
13
  DEFAULT_DIFFUSER_MODEL = "geospatial_diffuser"
14
 
15
  def __init__(self, controlnet_model_path=DEFAULT_CONTROLNET_MODEL, diffuser_model=DEFAULT_DIFFUSER_MODEL):
16
- self.controlnet = ControlNetModel.from_pretrained(controlnet_model_path, torch_dtype=torch.float32)
17
  self.generator = torch.Generator(device="cpu").manual_seed(2)
18
  self.pipe = StableDiffusionControlNetPipeline.from_pretrained(
19
  diffuser_model,
20
  low_cpu_mem_usage=False,
21
  device_map=None,
22
  controlnet=self.controlnet,
23
- torch_dtype=torch.float32
24
  )
25
  self.pipe.scheduler = UniPCMultistepScheduler.from_config(self.pipe.scheduler.config)
26
  if torch.cuda.is_available():
 
27
  self.pipe.enable_model_cpu_offload()
28
  self.pipe.enable_xformers_memory_efficient_attention()
29
 
30
  def generate_painting(self, input_promp, control_image):
31
  print(":::::::::::::::::")
32
  print(type(control_image))
33
-
34
- image = load_image("sparkgeo_logo.png")
35
 
36
  output = self.pipe(
37
  input_promp,
 
5
  ControlNetModel
6
  )
7
  from diffusers.utils import load_image
8
+ from PIL import Image
9
 
10
 
11
  class GeoPainting:
 
14
  DEFAULT_DIFFUSER_MODEL = "geospatial_diffuser"
15
 
16
  def __init__(self, controlnet_model_path=DEFAULT_CONTROLNET_MODEL, diffuser_model=DEFAULT_DIFFUSER_MODEL):
17
+ self.controlnet = ControlNetModel.from_pretrained(controlnet_model_path, torch_dtype=torch.float16)
18
  self.generator = torch.Generator(device="cpu").manual_seed(2)
19
  self.pipe = StableDiffusionControlNetPipeline.from_pretrained(
20
  diffuser_model,
21
  low_cpu_mem_usage=False,
22
  device_map=None,
23
  controlnet=self.controlnet,
24
+ torch_dtype=torch.float16
25
  )
26
  self.pipe.scheduler = UniPCMultistepScheduler.from_config(self.pipe.scheduler.config)
27
  if torch.cuda.is_available():
28
+ print(":::::::CUDA AVAILABLE::GPU:HUGGINGFACE:::::::")
29
  self.pipe.enable_model_cpu_offload()
30
  self.pipe.enable_xformers_memory_efficient_attention()
31
 
32
  def generate_painting(self, input_promp, control_image):
33
  print(":::::::::::::::::")
34
  print(type(control_image))
35
+ image = Image.fromarray(control_image.astype('uint8'))
36
+ print(type(image))
37
 
38
  output = self.pipe(
39
  input_promp,
main.py DELETED
@@ -1,6 +0,0 @@
1
- from geo_painting import GeoPainting
2
- from PIL import Image
3
-
4
- new_geo_painting = GeoPainting()
5
- image = Image.open("sparkgeo_logo.png")
6
- new_geo_painting.generate_painting("rivers with lakes and sand", image)
 
 
 
 
 
 
 
sparkgeo_logo.png DELETED
Binary file (28.9 kB)