Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import cv2
|
| 4 |
+
import torch
|
| 5 |
+
import numpy as np
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import re
|
| 8 |
+
from datasets import load_dataset
|
| 9 |
+
from diffusers import DiffusionPipeline, EulerDiscreteScheduler
|
| 10 |
+
|
| 11 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 12 |
+
|
| 13 |
+
scheduler = EulerDiscreteScheduler.from_pretrained("stabilityai/stable-diffusion-2", subfolder="scheduler", prediction_type="v_prediction")
|
| 14 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2", scheduler=scheduler)
|
| 15 |
+
pipe = pipe.to(device)
|
| 16 |
+
|
| 17 |
+
def genie (prompt, scale, steps, seed):
|
| 18 |
+
generator = torch.Generator(device=device).manual_seed(seed)
|
| 19 |
+
images = pipe(prompt, width=768, height=768, num_inference_steps=steps, guidance_scale=scale, num_images_per_prompt=1, generator=generator).images
|
| 20 |
+
return images[0]
|
| 21 |
+
gr.Interface(fn=genie, inputs=['text', gr.Slider(1, 10, 20), gr.Slider(), gr.Slider(maximum=987654321)], outputs='image').launch(debug=True)
|