Spaces:
Runtime error
Runtime error
UdacityNoob
commited on
Commit
β’
994f306
1
Parent(s):
c258254
Develop first demo
Browse files- app.py +33 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import torch
|
3 |
+
import gradio as gr
|
4 |
+
from torch import autocast
|
5 |
+
from diffusers import StableDiffusionPipeline
|
6 |
+
|
7 |
+
# get hf user access token as an environment variable
|
8 |
+
TOKEN_KEY = os.getenv('AUTH_TOKEN')
|
9 |
+
|
10 |
+
# setup pipeline
|
11 |
+
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", revision="fp16", torch_dtype=torch.float16, use_auth_token=TOKEN_KEY)
|
12 |
+
# pipe = pipe.to('cuda')
|
13 |
+
|
14 |
+
# define gradio function
|
15 |
+
def generate(prompt:str, seed:int, guidance:float, steps:int):
|
16 |
+
generator = torch.Generator("cuda").manual_seed(int(seed))
|
17 |
+
with autocast("cuda"):
|
18 |
+
image = pipe(prompt=prompt, generator=generator, guidance_scale=guidance, steps=50).images[0]
|
19 |
+
return image
|
20 |
+
|
21 |
+
# create the gradio UI
|
22 |
+
demo = gr.Interface(
|
23 |
+
fn=generate,
|
24 |
+
inputs=[gr.Textbox(placeholder="castle on a mountain"), gr.Number(value=123456), gr.Slider(0,10)],
|
25 |
+
outputs="image",
|
26 |
+
allow_flagging="never",
|
27 |
+
)
|
28 |
+
|
29 |
+
# allow queueing or incoming requests, max=3
|
30 |
+
demo.queue(concurrency_count=3)
|
31 |
+
|
32 |
+
# launch demo
|
33 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
scipy
|
2 |
+
ftfy
|
3 |
+
torch>=1.10.0
|
4 |
+
transformers
|
5 |
+
diffusers==0.3.0
|