rezaarmand commited on
Commit
187b850
1 Parent(s): a1eec31

adding paper link and fixing cuda cpu problem

Browse files
Files changed (1) hide show
  1. app.py +24 -18
app.py CHANGED
@@ -90,7 +90,10 @@ def predict(prompt, weights, seed, scale=7.5, steps=50):
90
  with torch.no_grad():
91
  has_cuda = torch.cuda.is_available()
92
  with autocast('cpu' if not has_cuda else 'cuda'):
93
- generator = torch.Generator('cuda').manual_seed(int(seed))
 
 
 
94
  image_perpneg = pipe(prompt, guidance_scale=float(scale), generator=generator,
95
  num_inference_steps=steps, weights=weights)["images"][0]
96
  return image_perpneg
@@ -115,25 +118,25 @@ with app:
115
  """
116
  ### **<p align='center'>Demo created by Huangjie Zheng and Reza Armandpour</p>**.
117
  """
118
- )
119
-
120
  with gr.Row():
121
  with gr.Column():
122
- with gr.Tab(label="FUll prompt"):
123
- gr.Markdown(
124
- "### **Provide a list of prompts and their weights separated by | **"
125
- )
126
- prompt = gr.Textbox(label="List of prompts:", show_label=True)
127
- weights = gr.Textbox(
128
- label="List of weights:", show_label=True
129
- )
130
- seed = gr.Textbox(
131
- label="Seed:", show_label=True
132
- )
133
- scale = gr.Textbox(
134
- label="Guidance scale:", show_label=True
135
- )
136
- image_gen_btn = gr.Button(value="Generate")
137
 
138
  with gr.Column():
139
  img_output = gr.Image(
@@ -156,6 +159,9 @@ with app:
156
  inputs=[prompt, weights, seed, scale],
157
  outputs=[img_output],
158
  )
 
 
 
159
 
160
  gr.Markdown(
161
  """
 
90
  with torch.no_grad():
91
  has_cuda = torch.cuda.is_available()
92
  with autocast('cpu' if not has_cuda else 'cuda'):
93
+ if has_cuda:
94
+ generator = torch.Generator('cuda').manual_seed(int(seed))
95
+ else:
96
+ generator = torch.Generator().manual_seed(int(seed))
97
  image_perpneg = pipe(prompt, guidance_scale=float(scale), generator=generator,
98
  num_inference_steps=steps, weights=weights)["images"][0]
99
  return image_perpneg
 
118
  """
119
  ### **<p align='center'>Demo created by Huangjie Zheng and Reza Armandpour</p>**.
120
  """
121
+ )
122
+
123
  with gr.Row():
124
  with gr.Column():
125
+ # with gr.Tab(label="FUll prompt"):
126
+ gr.Markdown(
127
+ "### **Provide a list of prompts and their weights separated by | **"
128
+ )
129
+ prompt = gr.Textbox(label="List of prompts:", show_label=True)
130
+ weights = gr.Textbox(
131
+ label="List of weights:", show_label=True
132
+ )
133
+ seed = gr.Textbox(
134
+ label="Seed:", show_label=True
135
+ )
136
+ scale = gr.Textbox(
137
+ label="Guidance scale:", show_label=True
138
+ )
139
+ image_gen_btn = gr.Button(value="Generate")
140
 
141
  with gr.Column():
142
  img_output = gr.Image(
 
159
  inputs=[prompt, weights, seed, scale],
160
  outputs=[img_output],
161
  )
162
+ gr.Markdown("""
163
+ \n This is the repository for using Perp-Neg sampling with Stable Diffusion model, as presented in [Re-imagine the Negative Prompt Algorithm: Transform 2D Diffusion into 3D, alleviate Janus problem and Beyond.](https://Perp-Neg.github.i).
164
+ """)
165
 
166
  gr.Markdown(
167
  """