geekyrakshit commited on
Commit
d6e73d2
1 Parent(s): 1f065a3

update: app + dependencies

Browse files
Files changed (2) hide show
  1. app.py +13 -17
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,17 +1,14 @@
 
 
1
  import gradio as gr
2
 
3
  import torch
4
- import numpy as np
5
- import modin.pandas as pd
6
- from PIL import Image
7
  from diffusers import DiffusionPipeline
8
 
9
- import wandb
10
  from wandb_addons.diffusers import get_wandb_callback
11
 
12
 
13
  device = "cuda" if torch.cuda.is_available() else "cpu"
14
- pipeline = None
15
 
16
  if torch.cuda.is_available():
17
  torch.cuda.empty_cache()
@@ -28,7 +25,6 @@ else:
28
 
29
  def generate_image(
30
  wandb_project,
31
- wandb_entity,
32
  wandb_api_key,
33
  prompt,
34
  negative_prompt,
@@ -39,10 +35,11 @@ def generate_image(
39
  seed,
40
  guidance_rescale,
41
  ):
42
- wandb.login(key=wandb_api_key)
43
  generator = torch.Generator(device="cuda").manual_seed(seed)
44
  configs = {
45
- "guidance_rescale": 0.0,
 
46
  "seed": seed,
47
  }
48
  callback = get_wandb_callback(
@@ -50,7 +47,7 @@ def generate_image(
50
  prompt=prompt,
51
  negative_prompt=negative_prompt,
52
  wandb_project=wandb_project,
53
- wandb_entity=wandb_entity,
54
  configs=configs,
55
  )
56
  image = pipeline(
@@ -59,8 +56,8 @@ def generate_image(
59
  generator=generator,
60
  height=height,
61
  width=width,
 
62
  callback=callback,
63
- eta=configs["eta"],
64
  guidance_rescale=configs["guidance_rescale"],
65
  ).images[0]
66
  if torch.cuda.is_available():
@@ -71,9 +68,8 @@ def generate_image(
71
  gr.Interface(
72
  fn=generate_image,
73
  inputs=[
74
- gr.Textbox(label="Wandb Project Name", value="Stable-Diffusion-XL"),
75
- gr.Textbox(label="Wandb Entity Name (Username/Team-name)"),
76
- gr.Textbox(label="Wandb API Key", type="password"),
77
  gr.Textbox(
78
  label="Prompt",
79
  lines=3,
@@ -90,7 +86,7 @@ gr.Interface(
90
  minimum=10,
91
  maximum=100,
92
  value=50,
93
- step=128,
94
  label="Number of Inference Steps",
95
  ),
96
  gr.Slider(
@@ -98,7 +94,7 @@ gr.Interface(
98
  maximum=15.0,
99
  value=5.0,
100
  step=0.25,
101
- label="Guidance Scale: How Closely the model follows the Prompt",
102
  ),
103
  gr.Slider(
104
  minimum=0, step=1, maximum=999999999999999999, randomize=True, label="Seed"
@@ -106,7 +102,7 @@ gr.Interface(
106
  gr.Slider(
107
  minimum=0.0,
108
  maximum=1.0,
109
- value=0.7,
110
  step=0.1,
111
  label="Guidance Rescale Factor",
112
  ),
@@ -114,4 +110,4 @@ gr.Interface(
114
  outputs="image",
115
  title="Reproducible Stable Diffusion XL",
116
  description="Generate images using Stable Diffusion.",
117
- )
 
1
+ import os
2
+
3
  import gradio as gr
4
 
5
  import torch
 
 
 
6
  from diffusers import DiffusionPipeline
7
 
 
8
  from wandb_addons.diffusers import get_wandb_callback
9
 
10
 
11
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
12
 
13
  if torch.cuda.is_available():
14
  torch.cuda.empty_cache()
 
25
 
26
  def generate_image(
27
  wandb_project,
 
28
  wandb_api_key,
29
  prompt,
30
  negative_prompt,
 
35
  seed,
36
  guidance_rescale,
37
  ):
38
+ os.environ["WANDB_API_KEY"] = wandb_api_key
39
  generator = torch.Generator(device="cuda").manual_seed(seed)
40
  configs = {
41
+ "guidance_scale": guidance_scale,
42
+ "guidance_rescale": guidance_rescale,
43
  "seed": seed,
44
  }
45
  callback = get_wandb_callback(
 
47
  prompt=prompt,
48
  negative_prompt=negative_prompt,
49
  wandb_project=wandb_project,
50
+ num_inference_steps=num_inference_steps,
51
  configs=configs,
52
  )
53
  image = pipeline(
 
56
  generator=generator,
57
  height=height,
58
  width=width,
59
+ num_inference_steps=num_inference_steps,
60
  callback=callback,
 
61
  guidance_rescale=configs["guidance_rescale"],
62
  ).images[0]
63
  if torch.cuda.is_available():
 
68
  gr.Interface(
69
  fn=generate_image,
70
  inputs=[
71
+ gr.Textbox(label="WandB Project Name", value="Stable-Diffusion-XL"),
72
+ gr.Textbox(label="WandB API Key", type="password"),
 
73
  gr.Textbox(
74
  label="Prompt",
75
  lines=3,
 
86
  minimum=10,
87
  maximum=100,
88
  value=50,
89
+ step=10,
90
  label="Number of Inference Steps",
91
  ),
92
  gr.Slider(
 
94
  maximum=15.0,
95
  value=5.0,
96
  step=0.25,
97
+ label="Guidance Scale (How Closely the model follows the Prompt)",
98
  ),
99
  gr.Slider(
100
  minimum=0, step=1, maximum=999999999999999999, randomize=True, label="Seed"
 
102
  gr.Slider(
103
  minimum=0.0,
104
  maximum=1.0,
105
+ value=0.0,
106
  step=0.1,
107
  label="Guidance Rescale Factor",
108
  ),
 
110
  outputs="image",
111
  title="Reproducible Stable Diffusion XL",
112
  description="Generate images using Stable Diffusion.",
113
+ ).launch(debug=True, max_threads=80)
requirements.txt CHANGED
@@ -1,9 +1,9 @@
 
1
  transformers
2
  diffusers
3
  accelerate
4
  torch
5
  ftfy
6
- modin[all]
7
  xformers
8
  invisible_watermark
9
  weave
 
1
+ gradio
2
  transformers
3
  diffusers
4
  accelerate
5
  torch
6
  ftfy
 
7
  xformers
8
  invisible_watermark
9
  weave