File size: 1,440 Bytes
7a5ca04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import gradio as gr
import torch
import numpy as np
import modin.pandas as pd
from PIL import Image
from datasets import load_dataset
from diffusers import DiffusionPipeline, EulerDiscreteScheduler

device = "cuda" if torch.cuda.is_available() else "cpu"

scheduler = EulerDiscreteScheduler.from_pretrained("stabilityai/stable-diffusion-2-1", subfolder="scheduler", prediction_type="v_prediction")
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", scheduler=scheduler)
pipe = pipe.to(device)

def genie (prompt, negative_prompt, scale, steps, seed):
     generator = torch.Generator(device=device).manual_seed(seed)
     images = pipe(prompt, negative_prompt=negative_prompt, width=768, height=768, num_inference_steps=steps, guidance_scale=scale, num_images_per_prompt=1, generator=generator).images[0]
     return images
    
gr.Interface(fn=genie, inputs=[gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'), gr.Textbox(label='What you Do Not want the AI to generate.'), gr.Slider(1, 25, 10), gr.Slider(1, maximum=20, value=10, step=1), gr.Slider(minimum=1, step=1, maximum=999999999999999999, randomize=True)], outputs='image', title="Stable Diffusion 2.1 CPU", description="SD 2.1 CPU. <b>WARNING:</b> Extremely Slow. 130s/Iteration. Expect 25-50mins an image for 10-20 iterations respectively.", article = "Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch()