jclyo1 commited on
Commit
00a296f
1 Parent(s): 621839f
Files changed (1) hide show
  1. main.py +13 -5
main.py CHANGED
@@ -10,7 +10,7 @@ import os
10
  import json
11
 
12
  import torch
13
- from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
14
 
15
 
16
  print(f"Is CUDA available: {torch.cuda.is_available()}")
@@ -21,18 +21,26 @@ app = FastAPI()
21
  def generate_image(prompt):
22
  print(f"Is CUDA available: {torch.cuda.is_available()}")
23
 
24
- model_id = "CompVis/stable-diffusion-v1-4" #stabilityai/stable-diffusion-2-1
 
25
 
26
  # Use the DPMSolverMultistepScheduler (DPM-Solver++) scheduler here instead
27
  #pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
28
- pipe = StableDiffusionPipeline.from_pretrained(model_id)
 
29
  #pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
30
- pipe = pipe.to("cuda")
 
 
 
 
 
 
31
 
32
  #prompt = "a photo of an astronaut riding a horse on mars"
33
 
34
  #image = pipe(prompt, num_inference_steps=5).images[0]
35
- image = pipe(prompt).images[0]
36
 
37
  print(image)
38
  image.save("static/ai.jpg")
 
10
  import json
11
 
12
  import torch
13
+ from diffusers import DiffusionPipeline
14
 
15
 
16
  print(f"Is CUDA available: {torch.cuda.is_available()}")
 
21
  def generate_image(prompt):
22
  print(f"Is CUDA available: {torch.cuda.is_available()}")
23
 
24
+ #model_id = "CompVis/stable-diffusion-v1-4" #stabilityai/stable-diffusion-2-1
25
+ model_id = "runwayml/stable-diffusion-v1-5"
26
 
27
  # Use the DPMSolverMultistepScheduler (DPM-Solver++) scheduler here instead
28
  #pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
29
+ #pipe = StableDiffusionPipeline.from_pretrained(model_id)
30
+
31
  #pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
32
+ #pipe = pipe.to("cuda")
33
+
34
+ pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
35
+ pipeline = pipeline.to("cuda")
36
+ generator = torch.Generator("cuda").manual_seed(0)
37
+ image = pipeline(prompt, generator=generator).images[0]
38
+
39
 
40
  #prompt = "a photo of an astronaut riding a horse on mars"
41
 
42
  #image = pipe(prompt, num_inference_steps=5).images[0]
43
+ #image = pipe(prompt).images[0]
44
 
45
  print(image)
46
  image.save("static/ai.jpg")