Spaces:
Sleeping
Sleeping
slymnyldrm
commited on
Commit
•
7990be7
1
Parent(s):
1572aa1
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
import torch
|
4 |
+
from torch import autocast
|
5 |
+
from diffusers import StableDiffusionPipeline, DDIMScheduler
|
6 |
+
from IPython.display import display
|
7 |
+
|
8 |
+
model_path = WEIGHTS_DIR # If you want to use previously trained model saved in gdrive, replace this with the full path of model in gdrive
|
9 |
+
|
10 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_path, safety_checker=None, torch_dtype=torch.float16).to("cuda")
|
11 |
+
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
12 |
+
pipe.enable_xformers_memory_efficient_attention()
|
13 |
+
|
14 |
+
g_cuda = torch.Generator(device='cuda')
|
15 |
+
|
16 |
+
def inference(prompt, negative_prompt, num_samples, height=512, width=512, num_inference_steps=50, guidance_scale=7.5, g_seed=52362):
|
17 |
+
with torch.autocast("cuda"), torch.inference_mode():
|
18 |
+
return pipe(
|
19 |
+
prompt, height=int(height), width=int(width),
|
20 |
+
negative_prompt=negative_prompt,
|
21 |
+
num_images_per_prompt=int(num_samples),
|
22 |
+
num_inference_steps=int(num_inference_steps), guidance_scale=guidance_scale,
|
23 |
+
generator=g_cuda.manual_seed(g_seed)
|
24 |
+
).images
|
25 |
+
|
26 |
+
with gr.Blocks() as demo:
|
27 |
+
with gr.Row():
|
28 |
+
with gr.Column():
|
29 |
+
prompt = gr.Textbox(label="Prompt", value="concept art portrait of suleyman_person person, hyper realistic face, intricate, detailed, evil, strong face")
|
30 |
+
negative_prompt = gr.Textbox(label="Negative Prompt", value="")
|
31 |
+
run = gr.Button(value="Generate")
|
32 |
+
with gr.Row():
|
33 |
+
num_samples = gr.Number(label="Number of Samples", value=4)
|
34 |
+
guidance_scale = gr.Number(label="Guidance Scale", value=7.5)
|
35 |
+
with gr.Row():
|
36 |
+
height = gr.Number(label="Height", value=512)
|
37 |
+
width = gr.Number(label="Width", value=512)
|
38 |
+
num_inference_steps = gr.Slider(label="Steps", value=50)
|
39 |
+
with gr.Column():
|
40 |
+
gallery = gr.Gallery()
|
41 |
+
with gr.Row():
|
42 |
+
g_seed = gr.Number(label="Random Number Generator Seed", value=52362)
|
43 |
+
|
44 |
+
run.click(inference, inputs=[prompt, negative_prompt, num_samples, height, width, num_inference_steps, guidance_scale, g_seed], outputs=gallery)
|
45 |
+
|
46 |
+
demo.launch(debug=True, share=True)
|