poulpy5 commited on
Commit
c25f393
·
verified ·
1 Parent(s): 1368d57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -28
app.py CHANGED
@@ -57,41 +57,23 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
57
 
58
 
59
  @spaces.GPU(enable_queue=True)
60
- def generate(
61
- prompt: str,
62
- negative_prompt: str = "",
63
- use_negative_prompt: bool = False,
64
- seed: int = 0,
65
- width: int = 1024,
66
- height: int = 1024,
67
- guidance_scale: float = 3,
68
- randomize_seed: bool = False,
69
- use_resolution_binning: bool = True,
70
- progress=gr.Progress(track_tqdm=True),
71
- ):
72
- pipe.to(device)
73
- seed = int(randomize_seed_fn(seed, randomize_seed))
74
- generator = torch.Generator().manual_seed(seed)
75
-
76
- if not use_negative_prompt:
77
- negative_prompt = None # type: ignore
78
 
79
  images = pipe(
80
  prompt=prompt,
81
  negative_prompt=negative_prompt,
82
- width=width,
83
- height=height,
84
  guidance_scale=guidance_scale,
85
- num_inference_steps=25,
86
- generator=generator,
87
- num_images_per_prompt=NUM_IMAGES_PER_PROMPT,
88
- use_resolution_binning=use_resolution_binning,
89
- output_type="pil",
90
  ).images
 
91
 
92
- image_paths = [save_image(img) for img in images]
93
- print(image_paths)
94
- return image_paths, seed
95
 
96
 
97
  examples = [
 
57
 
58
 
59
  @spaces.GPU(enable_queue=True)
60
+ def generate(prompt, negative_prompt, guidance_scale, num_inference_steps):
61
+ # Ensure consistent data type
62
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
63
+ dtype = torch.float32 # or torch.float16 if you're using half precision
64
+
65
+ pipe = pipe.to(device)
66
+ pipe.text_encoder = pipe.text_encoder.to(dtype)
67
+ pipe.unet = pipe.unet.to(dtype)
 
 
 
 
 
 
 
 
 
 
68
 
69
  images = pipe(
70
  prompt=prompt,
71
  negative_prompt=negative_prompt,
 
 
72
  guidance_scale=guidance_scale,
73
+ num_inference_steps=num_inference_steps,
 
 
 
 
74
  ).images
75
+ return images[0]
76
 
 
 
 
77
 
78
 
79
  examples = [