Spaces:
Configuration error
Configuration error
cocktailpeanut
commited on
Commit
•
70546b5
1
Parent(s):
946ddcc
init
Browse files- app.py +39 -0
- install.json +25 -0
- pinokio.js +29 -0
- requirements.txt +4 -0
- start.json +23 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from diffusers import AutoPipelineForText2Image, AutoPipelineForImage2Image
|
3 |
+
from diffusers.utils import load_image
|
4 |
+
import torch
|
5 |
+
|
6 |
+
if torch.cuda.is_available():
|
7 |
+
device = "cuda"
|
8 |
+
elif torch.backends.mps.is_available():
|
9 |
+
device = "mps"
|
10 |
+
else:
|
11 |
+
device = "cpu"
|
12 |
+
|
13 |
+
|
14 |
+
pipes = {
|
15 |
+
"txt2img": AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16").to(device),
|
16 |
+
"img2img": AutoPipelineForImage2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16").to(device)
|
17 |
+
}
|
18 |
+
|
19 |
+
|
20 |
+
def run(prompt, image):
|
21 |
+
print(f"prompt={prompt}, image={image}")
|
22 |
+
if image is None:
|
23 |
+
return pipes["txt2img"](prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0]
|
24 |
+
else:
|
25 |
+
image = image.resize((512,512))
|
26 |
+
print(f"img2img image={image}")
|
27 |
+
return pipes["img2img"](prompt, image=image, num_inference_steps=2, strength=0.5, guidance_scale=0.0).images[0]
|
28 |
+
|
29 |
+
demo = gr.Interface(
|
30 |
+
run,
|
31 |
+
inputs=[
|
32 |
+
gr.Textbox(label="Prompt"),
|
33 |
+
gr.Image(type="pil")
|
34 |
+
],
|
35 |
+
outputs=gr.Image(width=512,height=512),
|
36 |
+
live=True
|
37 |
+
)
|
38 |
+
#demo.dependencies[0]["show_progress"] = "minimal"
|
39 |
+
demo.launch()
|
install.json
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"requires": [{
|
3 |
+
"type": "conda",
|
4 |
+
"name": "ffmpeg",
|
5 |
+
"args": "-c conda-forge"
|
6 |
+
}],
|
7 |
+
"run": [{
|
8 |
+
"method": "shell.run",
|
9 |
+
"params": {
|
10 |
+
"venv": "env",
|
11 |
+
"message": "pip install -r requirements.txt"
|
12 |
+
}
|
13 |
+
}, {
|
14 |
+
"method": "input",
|
15 |
+
"params": {
|
16 |
+
"title": "Install Success",
|
17 |
+
"description": "Go back to the dashboard and launch the app!"
|
18 |
+
}
|
19 |
+
}, {
|
20 |
+
"method": "browser.open",
|
21 |
+
"params": {
|
22 |
+
"uri": "/?selected=sdxl turbo"
|
23 |
+
}
|
24 |
+
}]
|
25 |
+
}
|
pinokio.js
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
module.exports = {
|
2 |
+
title: "sdxl turbo",
|
3 |
+
menu: async (kernel) => {
|
4 |
+
let installed = await kernel.exists(__dirname, "env")
|
5 |
+
if (installed) {
|
6 |
+
let session = await kernel.require(__dirname, "session.json")
|
7 |
+
console.log("session", session)
|
8 |
+
return [{
|
9 |
+
when: "start.json",
|
10 |
+
on: "<i class='fa-solid fa-spin fa-circle-notch'></i> Running",
|
11 |
+
type: "label"
|
12 |
+
}, {
|
13 |
+
when: "start.json",
|
14 |
+
off: "<i class='fa-solid fa-power-off'></i> Start",
|
15 |
+
href: "start.json?fullscreen=true&run=true",
|
16 |
+
}, {
|
17 |
+
when: "start.json",
|
18 |
+
on: "<i class='fa-solid fa-rocket'></i> Launch",
|
19 |
+
href: (session && session.url ? session.url : "http://127.0.0.1:7860"),
|
20 |
+
target: "_blank"
|
21 |
+
}]
|
22 |
+
} else {
|
23 |
+
return [{
|
24 |
+
html: '<i class="fa-solid fa-plug"></i> Install',
|
25 |
+
href: "install.json?run=true&fullscreen=true"
|
26 |
+
}]
|
27 |
+
}
|
28 |
+
}
|
29 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
diffusers
|
2 |
+
transformers
|
3 |
+
accelerate
|
4 |
+
gradio
|
start.json
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"daemon": true,
|
3 |
+
"run": [{
|
4 |
+
"method": "shell.run",
|
5 |
+
"params": {
|
6 |
+
"venv": "env",
|
7 |
+
"message": "python app.py",
|
8 |
+
"on": [{ "event": "/http:\/\/[0-9.:]+/", "done": true }]
|
9 |
+
}
|
10 |
+
}, {
|
11 |
+
"method": "self.set",
|
12 |
+
"params": {
|
13 |
+
"session.json": {
|
14 |
+
"url": "{{input.event[0]}}"
|
15 |
+
}
|
16 |
+
}
|
17 |
+
}, {
|
18 |
+
"method": "browser.open",
|
19 |
+
"params": {
|
20 |
+
"uri": "{{self.session.url}}"
|
21 |
+
}
|
22 |
+
}]
|
23 |
+
}
|