jclyo1 commited on
Commit
6e2b814
1 Parent(s): 0e016e5

EulerScheduler

Browse files
Files changed (1) hide show
  1. main.py +4 -25
main.py CHANGED
@@ -11,7 +11,7 @@ import json
11
  import uuid
12
 
13
  import torch
14
- from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
15
 
16
 
17
  print(f"Is CUDA available: {torch.cuda.is_available()}")
@@ -21,41 +21,20 @@ app = FastAPI()
21
  @app.get("/generate")
22
  def generate_image(prompt, inference_steps, model):
23
  torch.cuda.empty_cache()
24
-
25
  print(f"Is CUDA available: {torch.cuda.is_available()}")
26
 
27
- #model_id = "CompVis/stable-diffusion-v1-4" #stabilityai/stable-diffusion-2-1
28
-
29
- # Use the DPMSolverMultistepScheduler (DPM-Solver++) scheduler here instead
30
- #pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
31
- #pipe = StableDiffusionPipeline.from_pretrained(model_id)
32
 
33
- #pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
34
- #pipe = pipe.to("cuda")
35
 
36
- pipeline = DiffusionPipeline.from_pretrained(str(model))
37
  pipeline = pipeline.to("cuda")
38
- #generator = torch.Generator("gpu").manual_seed(0)
39
- pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
40
- #image = pipeline(prompt, generator=generator).images[0]
41
  image = pipeline(prompt, num_inference_steps=int(inference_steps)).images[0]
42
 
43
-
44
- #prompt = "a photo of an astronaut riding a horse on mars"
45
-
46
- #image = pipe(prompt, num_inference_steps=5).images[0]
47
- #image = pipe(prompt).images[0]
48
-
49
-
50
  filename = str(uuid.uuid4()) + ".jpg"
51
-
52
- #print(f"after filename assignment")
53
-
54
  image.save(filename)
55
 
56
  print(filename)
57
- #print(f"after save")
58
-
59
 
60
  # Data to be written
61
  assertion = {
 
11
  import uuid
12
 
13
  import torch
14
+ from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler, EulerDiscreteScheduler
15
 
16
 
17
  print(f"Is CUDA available: {torch.cuda.is_available()}")
 
21
  @app.get("/generate")
22
  def generate_image(prompt, inference_steps, model):
23
  torch.cuda.empty_cache()
 
24
  print(f"Is CUDA available: {torch.cuda.is_available()}")
25
 
26
+ pipeline = DiffusionPipeline.from_pretrained(str(model))
 
 
 
 
27
 
28
+ #pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
29
+ pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config)
30
 
 
31
  pipeline = pipeline.to("cuda")
 
 
 
32
  image = pipeline(prompt, num_inference_steps=int(inference_steps)).images[0]
33
 
 
 
 
 
 
 
 
34
  filename = str(uuid.uuid4()) + ".jpg"
 
 
 
35
  image.save(filename)
36
 
37
  print(filename)
 
 
38
 
39
  # Data to be written
40
  assertion = {