fffiloni commited on
Commit
7d10f1c
·
1 Parent(s): 6c0e0df

added links to used models

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -2,38 +2,41 @@ import gradio as gr
2
  import os
3
 
4
  title="Prompt Converter"
 
5
  description="""
6
  <p style="text-align:center;">
7
  Stable Diffusion 2 uses OpenCLIP ViT-H model trained on LAION dataset so it knows different things than the OpenAI ViT-L we're all used to prompting.
8
- <br />This demo converts a v1.x stable diffusion prompt to a stable diffusion 2.x prompt, by generating an image through RunwayML Stable Diffusion 1.5, then Interrogate the resulting image through CLIP Interrogator 2 to give you a Stable Diffusion 2 equivalent prompt.
9
  </p>
10
  """
 
11
  stable_diffusion = gr.Blocks.load(name="spaces/runwayml/stable-diffusion-v1-5")
12
  clip_interrogator_2 = gr.Blocks.load(name="spaces/fffiloni/CLIP-Interrogator-2")
13
 
14
  def get_images(prompt):
15
- gallery_dir = stable_diffusion(prompt, fn_index=2)
16
-
17
- img_results = [os.path.join(gallery_dir, img) for img in os.listdir(gallery_dir)]
18
-
19
  return img_results[0]
20
 
21
  def get_new_prompt(img, mode):
22
  interrogate = clip_interrogator_2(img, mode, 12, api_name="clipi2")
23
- #print(interrogate)
24
  return interrogate
25
 
26
  def infer(prompt, mode):
27
- img = get_images(prompt)
28
-
29
- result = get_new_prompt(img, mode)
30
- #print(result)
31
  return result[0]
32
 
33
  prompt_input = gr.Textbox(lines=4, label="Input v1.x Stable Diffusion prompt")
34
  mode_input = gr.Radio(['best', 'classic', 'fast'], label='mode', value='fast')
35
  prompt_output = gr.Textbox(lines=4, label="Converted v2.x Stable Diffusion prompt")
36
- examples=[["girl with steampunk weapons and uniform, serious, finely detailed, made by wlop, boichi, ilya kuvshinov, full body portrait, illustration, grass, sunny, sky, anime, side view, perfect anime face, detailed face, zoomed out, smooth","fast"],
37
- ["a yellow cockatiel riding on the rings of saturn wearing a propeller hat, fantasy, intricate, elegant, highly detailed, digital painting, artstation, concept art, smooth, sharp focus, illustration, art by artgerm and greg rutkowski and alphonse mucha ","classic"],
38
- ["painting, view from inside edward hopper's painting nighthawks, of a group of werebears robbing a bank, foggy ","best"]]
39
- gr.Interface(fn=infer, inputs=[prompt_input,mode_input], outputs=[prompt_output],title=title,description=description,examples=examples).queue(max_size=10,concurrency_count=20).launch(enable_queue=True)
 
 
 
 
 
 
 
2
  import os
3
 
4
  title="Prompt Converter"
5
+
6
  description="""
7
  <p style="text-align:center;">
8
  Stable Diffusion 2 uses OpenCLIP ViT-H model trained on LAION dataset so it knows different things than the OpenAI ViT-L we're all used to prompting.
9
+ <br />This demo converts a v1.x stable diffusion prompt to a stable diffusion 2.x prompt, by generating an image through <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5" target="_blank">RunwayML Stable Diffusion 1.5</a>, then Interrogate the resulting image through <a href="https://huggingface.co/spaces/fffiloni/CLIP-Interrogator-2" target="_blank">CLIP Interrogator 2</a> to give you a Stable Diffusion 2 equivalent prompt.
10
  </p>
11
  """
12
+
13
  stable_diffusion = gr.Blocks.load(name="spaces/runwayml/stable-diffusion-v1-5")
14
  clip_interrogator_2 = gr.Blocks.load(name="spaces/fffiloni/CLIP-Interrogator-2")
15
 
16
  def get_images(prompt):
17
+ gallery_dir = stable_diffusion(prompt, fn_index=2)
18
+ img_results = [os.path.join(gallery_dir, img) for img in os.listdir(gallery_dir)]
 
 
19
  return img_results[0]
20
 
21
  def get_new_prompt(img, mode):
22
  interrogate = clip_interrogator_2(img, mode, 12, api_name="clipi2")
 
23
  return interrogate
24
 
25
  def infer(prompt, mode):
26
+ img = get_images(prompt)
27
+ result = get_new_prompt(img, mode)
 
 
28
  return result[0]
29
 
30
  prompt_input = gr.Textbox(lines=4, label="Input v1.x Stable Diffusion prompt")
31
  mode_input = gr.Radio(['best', 'classic', 'fast'], label='mode', value='fast')
32
  prompt_output = gr.Textbox(lines=4, label="Converted v2.x Stable Diffusion prompt")
33
+
34
+ examples=[
35
+ ["girl with steampunk weapons and uniform, serious, finely detailed, made by wlop, boichi, ilya kuvshinov, full body portrait, illustration, grass, sunny, sky, anime, side view, perfect anime face, detailed face, zoomed out, smooth","fast"],
36
+ ["a yellow cockatiel riding on the rings of saturn wearing a propeller hat, fantasy, intricate, elegant, highly detailed, digital painting, artstation, concept art, smooth, sharp focus, illustration, art by artgerm and greg rutkowski and alphonse mucha ","classic"],
37
+ ["painting, view from inside edward hopper's painting nighthawks, of a group of werebears robbing a bank, foggy ","best"]
38
+ ]
39
+
40
+ demo=gr.Interface(fn=infer, inputs=[prompt_input,mode_input], outputs=[prompt_output],title=title,description=description,examples=examples)
41
+ demo.queue(max_size=10,concurrency_count=20)
42
+ demo.launch(enable_queue=True)