Manjushri commited on
Commit
058e9d8
1 Parent(s): d82d67b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -21
app.py CHANGED
@@ -1,25 +1,22 @@
1
- from stable_diffusion_tf.stable_diffusion import Text2Image
2
- from PIL import Image
3
  import gradio as gr
 
 
4
  import modin.pandas as pd
 
 
5
 
6
- generator = Text2Image(
7
- img_height=512,
8
- img_width=512,
9
- jit_compile=False)
10
-
11
- def txt2img(prompt, guide, steps, Temp):
12
- img = generator.generate(prompt,
13
- num_steps=steps,
14
- unconditional_guidance_scale=guide,
15
- temperature=Temp,
16
- batch_size=1)
17
- image=Image.fromarray(img[0])
18
- return image
19
 
20
- iface = gr.Interface(fn=txt2img, inputs=[
21
- gr.Textbox(label = 'Input Text Prompt: 77 Token (Keyword) Limit'),
22
- gr.Slider(1, 25, value = 10, step = 1, label = 'Guidance Scale: How close to follow Prompt'),
23
- gr.Slider(20, 75, value = 25, step = 1, label = 'Number of Iterations: Anything above 50 may produce the Over Baked Effect'),
24
- gr.Slider(.1, 100, value = 1, label='Temperature: Changes probability of Diffusion to Image Array, more info in community comments')], outputs = 'image',title='Stable Diffusion with Keras and TensorFlow CPU or GPU', description='Now Using Keras and TensorFlow with Stable Diffusion. This allows very complex image generation with less code footprint, and less text. Simply type in what you wish to see, adjust the sliders (optional) and click submit. For more information on Keras see https://keras.io/about/ For more informationon about Stable Diffusion or Suggestions for prompts, keywords, artists or styles see https://github.com/Maks-s/sd-akashic <br><br><b>DISCLAIMER: This Text to Image Pipeline has the potential to produce NSFW, Disturbing, or Offensive Images. I am not responsible for what images you produce or what you do with them. By using this Gradio API you consent to taking full responsibility for the images you produce and agree that you are at least 18 years of age.', article = "Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>")
25
- iface.launch(max_threads=True)
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import torch
3
+ import numpy as np
4
  import modin.pandas as pd
5
+ from PIL import Image
6
+ from diffusers import DiffusionPipeline
7
 
8
+ device = "cuda" if torch.cuda.is_available() else "cpu"
9
+ pipe = DiffusionPipeline.from_pretrained("prompthero/openjourney-v2", safety_checker=None)
10
+ pipe = pipe.to(device)
 
 
 
 
 
 
 
 
 
 
11
 
12
+ def genie (prompt, scale, steps, seed):
13
+ generator = torch.Generator(device=device).manual_seed(seed)
14
+ images = pipe(prompt, num_inference_steps=steps, guidance_scale=scale, generator=generator).images[0]
15
+ return images
16
+
17
+ gr.Interface(fn=genie, inputs=[gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'),
18
+ gr.Slider(1, maximum=15, value=10, step=.25),
19
+ gr.Slider(1, maximum=50, value=25, step=1),
20
+ gr.Slider(minimum=1, step=1, maximum=987654321, randomize=True)],
21
+ outputs='image', title="OpenJourney V2 CPU", description="OJ V2 CPU. <b>WARNING:</b> Extremely Slow. 35s/Iteration. Expect 8-16mins an image for 15-30 iterations respectively. 50 iterations takes ~28mins.",
22
+ article = "Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(debug=True, max_threads=True)