greendra commited on
Commit
c6b3a2f
·
1 Parent(s): dcf3794

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
app.py CHANGED
@@ -92,6 +92,7 @@ def imagebb(prompt, img, seed):
92
  except:
93
  print(r)
94
  bbtries += 1
 
95
  if bbtries < 3:
96
  return imagebb(prompt, img, seed)
97
  else:
@@ -132,7 +133,7 @@ def imgur(prompt, img, seed):
132
  return link, loglink
133
 
134
  sdtries = 0
135
- def sd(prompt):
136
  if prompt == "":
137
  return Image.open('error.png'), "Error! Please enter a prompt"
138
 
@@ -155,10 +156,11 @@ def sd(prompt):
155
  stability_api = client.StabilityInference(
156
  key = sdkey,
157
  verbose=True,
158
- engine="stable-diffusion-v1-5",
159
  )
160
  # convert string prompt to lowercase
161
  prompt = prompt.lower()
 
162
 
163
  # set random seed
164
  seed = random.randint(0, 9999999)
@@ -189,10 +191,12 @@ def sd(prompt):
189
  # send prompt to dream API
190
  # set random seed
191
  answers = stability_api.generate(
192
- prompt=prompt,
193
- steps=15,
194
  seed=seed,
195
- )
 
 
196
 
197
  # convert seed to string
198
  seed = str(seed)
@@ -230,19 +234,19 @@ def sd(prompt):
230
 
231
 
232
 
233
- examples = ["Futuristic utopian city in Coruscant. god beams. white buildings. street view. golden sunset. colorful, cityscape, green trees, future, urban, megapolis, breathtaking, Imaginative, utopia, Wallpaper, beautiful design, scifi, high detail, global illumination, ArtStation, art by Sebastian Wagner, Stephan Martiniere, Leon Tukker, Vitaly-Sokol",
234
- "A dream of a distant galaxy, by Caspar David Friedrich, matte painting trending on artstation HQ",
235
- "1990s movie, orbit space new york city street with many pedestrians as a loading screen, cinestill 800t 18mm, heavy grainy picture, very detailed, high quality, 4k panoramic, dramatic lightning, streetlight at night, rain, mud, foggy, anchray flags",
236
- "Portrait of a woman by Greg Rutkowski, she is about 30 years old, pretty, blond hair with two strans around her face, slavic features, melancholic gaze, pretty aquiline nose, she is wearing a blue utilitarian jumpsuit, highly detailed portrait, digital painting, artstation, concept art, smooth, sharp foccus ilustration, Artstation HQ.",
237
- "A small cabin on top of a snowy mountain in the style of Disney, artstation",
238
- "futuristic space landscape by Jessica Rossier and HR Giger",
239
- "Tiny cute isometric living room in a cutaway box, soft smooth lighting, soft colors, purple and blue color scheme, soft colors, 100mm lens, 3d blender render",
240
- "techno mining tailing in chuquicamata bioremediation white futuristic horizontal architecture, epic, cinematic, hyperealistic, high detailed, corona render, hdr, ray tracing",
241
- "A highly detailed matte painting of Orgrimmar the warrior city by Studio Ghibli, Makoto Shinkai, by Artgerm, by beeple, volumetric lighting, octane render, 4K resolution, trending on artstation, masterpiece",
242
- "Cute close portrait dainty beautiful futurstic white robotic girl, portraits, white cyberpunk inflatable formfitting tops, highly detailed sharp big eyes, white fringeshort hair, transparent intricate details, professional 3d visualisation in pastel colours, by wlop, intricate linework, trending on artstation, unreal engine 5 highly rendered, epic composition, by guweiz, shal. e, laica chrose, final fantasy",]
243
 
244
  with gr.Blocks(css = """
245
- *, body, #name, #ex, #article, .border-gray-200, .gr-input, .border-gray-100 { background: #0b0f19; color: white; border-color: #4c4c4c; }
246
  .gr-samples-gallery .gr-sample-textbox, #greet_btn, #save_btn, .py-1, .gr-samples-gallery:hover .gr-sample-textbox:hover, .gr-text-input, #output, .wrap.svelte-1c38quw, .h-wrap { background: #1f2937; color: white; border-color: #4c4c4c;}
247
  .py-6 {padding-top: 0;}
248
  """
@@ -250,10 +254,10 @@ with gr.Blocks(css = """
250
  download = gr.HTML(elem_id="download")
251
  output = gr.Image(label="Image Generation", elem_id="output")
252
  name = gr.Textbox(label="Prompt", placeholder="Describe the image you want to generate. Longer and more detailed prompts work better.", elem_id="name")
 
253
  greet_btn = gr.Button("Generate Image", elem_id="greet_btn")
254
  bin = gr.HTML("", visible=False)
255
- ex = gr.Examples(examples=examples, fn=sd, inputs=name, outputs=[output, download], cache_examples=True)
256
- ex.dataset.headers = [""]
257
  greet_btn.click(
258
  None,
259
  [],
@@ -269,7 +273,7 @@ with gr.Blocks(css = """
269
  Cookies.set('creations', parseInt(Cookies.get('creations')) + 1, { expires: 250 / 24 / 60 / 60 }); }
270
  console.log(Cookies.get('creations'));
271
  }""")
272
- greet_btn.click(fn=sd, inputs=name, outputs=[output, download])
273
 
274
 
275
  demo.queue(concurrency_count=3, max_size=20).launch(max_threads=150)
 
92
  except:
93
  print(r)
94
  bbtries += 1
95
+ print(bbtries)
96
  if bbtries < 3:
97
  return imagebb(prompt, img, seed)
98
  else:
 
133
  return link, loglink
134
 
135
  sdtries = 0
136
+ def sd(prompt, negprompt):
137
  if prompt == "":
138
  return Image.open('error.png'), "Error! Please enter a prompt"
139
 
 
156
  stability_api = client.StabilityInference(
157
  key = sdkey,
158
  verbose=True,
159
+ engine="stable-diffusion-512-v2-1",
160
  )
161
  # convert string prompt to lowercase
162
  prompt = prompt.lower()
163
+ negprompt = negprompt.lower()
164
 
165
  # set random seed
166
  seed = random.randint(0, 9999999)
 
191
  # send prompt to dream API
192
  # set random seed
193
  answers = stability_api.generate(
194
+ #prompt=prompt,
195
+ steps=10,
196
  seed=seed,
197
+ prompt = [generation.Prompt(text=prompt,parameters=generation.PromptParameters(weight=1)),
198
+ generation.Prompt(text=negprompt,parameters=generation.PromptParameters(weight=-1))],
199
+ )
200
 
201
  # convert seed to string
202
  seed = str(seed)
 
234
 
235
 
236
 
237
+ examples = [["Futuristic utopian city in Coruscant. god beams. white buildings. street view. golden sunset. colorful, cityscape, green trees, future, urban, megapolis, breathtaking, Imaginative, utopia, Wallpaper, beautiful design, scifi, high detail, global illumination, ArtStation, art by Sebastian Wagner, Stephan Martiniere, Leon Tukker, Vitaly-Sokol","low quality"],
238
+ ["A dream of a distant galaxy, by Caspar David Friedrich, matte painting trending on artstation HQ","low quality"],
239
+ ["1990s movie, orbit space new york city street with many pedestrians as a loading screen, cinestill 800t 18mm, heavy grainy picture, very detailed, high quality, 4k panoramic, dramatic lightning, streetlight at night, rain, mud, foggy, anchray flags","low quality"],
240
+ ["Portrait of a woman by Greg Rutkowski, she is about 30 years old, pretty, blond hair with two strans around her face, slavic features, melancholic gaze, pretty aquiline nose, she is wearing a blue utilitarian jumpsuit, highly detailed portrait, digital painting, artstation, concept art, smooth, sharp foccus ilustration, Artstation HQ.","low quality"],
241
+ ["A small cabin on top of a snowy mountain in the style of Disney, artstation","low quality"],
242
+ ["futuristic space landscape by Jessica Rossier and HR Giger","low quality"],
243
+ ["Tiny cute isometric living room in a cutaway box, soft smooth lighting, soft colors, purple and blue color scheme, soft colors, 100mm lens, 3d blender render","low quality"],
244
+ ["techno mining tailing in chuquicamata bioremediation white futuristic horizontal architecture, epic, cinematic, hyperealistic, high detailed, corona render, hdr, ray tracing","low quality"],
245
+ ["A highly detailed matte painting of Orgrimmar the warrior city by Studio Ghibli, Makoto Shinkai, by Artgerm, by beeple, volumetric lighting, octane render, 4K resolution, trending on artstation, masterpiece","low quality"],
246
+ ["Cute close portrait dainty beautiful futurstic white robotic girl, portraits, white cyberpunk inflatable formfitting tops, highly detailed sharp big eyes, white fringeshort hair, transparent intricate details, professional 3d visualisation in pastel colours, by wlop, intricate linework, trending on artstation, unreal engine 5 highly rendered, epic composition, by guweiz, shal. e, laica chrose, final fantasy","low quality"]]
247
 
248
  with gr.Blocks(css = """
249
+ *, body, #name, #negprompt, #ex, #article, .border-gray-200, .gr-input, .border-gray-100 { background: #0b0f19; color: white; border-color: #4c4c4c; }
250
  .gr-samples-gallery .gr-sample-textbox, #greet_btn, #save_btn, .py-1, .gr-samples-gallery:hover .gr-sample-textbox:hover, .gr-text-input, #output, .wrap.svelte-1c38quw, .h-wrap { background: #1f2937; color: white; border-color: #4c4c4c;}
251
  .py-6 {padding-top: 0;}
252
  """
 
254
  download = gr.HTML(elem_id="download")
255
  output = gr.Image(label="Image Generation", elem_id="output")
256
  name = gr.Textbox(label="Prompt", placeholder="Describe the image you want to generate. Longer and more detailed prompts work better.", elem_id="name")
257
+ negprompt = gr.Textbox(label="Negative Prompt", placeholder="Describe the image you want to avoid. Longer and more detailed prompts work better.", elem_id="negprompt")
258
  greet_btn = gr.Button("Generate Image", elem_id="greet_btn")
259
  bin = gr.HTML("", visible=False)
260
+ ex = gr.Examples(examples=examples, fn=sd, inputs=[name, negprompt], outputs=[output, download], cache_examples=True)
 
261
  greet_btn.click(
262
  None,
263
  [],
 
273
  Cookies.set('creations', parseInt(Cookies.get('creations')) + 1, { expires: 250 / 24 / 60 / 60 }); }
274
  console.log(Cookies.get('creations'));
275
  }""")
276
+ greet_btn.click(fn=sd, inputs=[name, negprompt], outputs=[output, download])
277
 
278
 
279
  demo.queue(concurrency_count=3, max_size=20).launch(max_threads=150)