Spaces:
Running
on
Zero
Running
on
Zero
Use Zero Spaces
#2
by
radames
- opened
- README.md +1 -1
- app.py +16 -11
- requirements.txt +3 -2
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: ⚡
|
|
4 |
colorFrom: purple
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: cc-by-nc-4.0
|
|
|
4 |
colorFrom: purple
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.36.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: cc-by-nc-4.0
|
app.py
CHANGED
@@ -1,12 +1,15 @@
|
|
1 |
import random
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
import torch
|
6 |
from diffusers import LCMScheduler, PixArtAlphaPipeline, Transformer2DModel
|
7 |
from peft import PeftModel
|
|
|
8 |
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
10 |
|
11 |
transformer = Transformer2DModel.from_pretrained(
|
12 |
"PixArt-alpha/PixArt-XL-2-1024-MS",
|
@@ -23,7 +26,8 @@ if torch.cuda.is_available():
|
|
23 |
transformer=transformer,
|
24 |
torch_dtype=torch.float16,
|
25 |
)
|
26 |
-
|
|
|
27 |
pipe = pipe.to(device)
|
28 |
else:
|
29 |
pipe = PixArtAlphaPipeline.from_pretrained(
|
@@ -46,8 +50,8 @@ MAX_IMAGE_SIZE = 1024
|
|
46 |
NUM_INFERENCE_STEPS = 4
|
47 |
|
48 |
|
|
|
49 |
def infer(prompt, seed, randomize_seed):
|
50 |
-
|
51 |
if randomize_seed:
|
52 |
seed = random.randint(0, MAX_SEED)
|
53 |
|
@@ -88,7 +92,6 @@ else:
|
|
88 |
power_device = "CPU"
|
89 |
|
90 |
with gr.Blocks(css=css) as demo:
|
91 |
-
|
92 |
with gr.Column(elem_id="col-container"):
|
93 |
gr.Markdown(
|
94 |
f"""
|
@@ -104,7 +107,6 @@ with gr.Blocks(css=css) as demo:
|
|
104 |
)
|
105 |
|
106 |
with gr.Row():
|
107 |
-
|
108 |
prompt = gr.Text(
|
109 |
label="Prompt",
|
110 |
show_label=False,
|
@@ -118,7 +120,6 @@ with gr.Blocks(css=css) as demo:
|
|
118 |
result = gr.Image(label="Result", show_label=False)
|
119 |
|
120 |
with gr.Accordion("Advanced Settings", open=False):
|
121 |
-
|
122 |
seed = gr.Slider(
|
123 |
label="Seed",
|
124 |
minimum=0,
|
@@ -131,14 +132,18 @@ with gr.Blocks(css=css) as demo:
|
|
131 |
|
132 |
examples = gr.Examples(examples=examples, inputs=[prompt])
|
133 |
|
134 |
-
gr.Markdown(
|
135 |
-
"**Disclaimer:**"
|
136 |
-
)
|
137 |
gr.Markdown(
|
138 |
"This demo is only for research purpose. Jasper cannot be held responsible for the generation of NSFW (Not Safe For Work) content through the use of this demo. Users are solely responsible for any content they create, and it is their obligation to ensure that it adheres to appropriate and ethical standards. Jasper provides the tools, but the responsibility for their use lies with the individual user."
|
139 |
)
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
demo.queue().launch(show_api=False)
|
|
|
1 |
import random
|
2 |
+
import spaces
|
3 |
|
4 |
import gradio as gr
|
5 |
import numpy as np
|
6 |
import torch
|
7 |
from diffusers import LCMScheduler, PixArtAlphaPipeline, Transformer2DModel
|
8 |
from peft import PeftModel
|
9 |
+
import os
|
10 |
|
11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
+
IS_SPACE = os.environ.get("SPACE_ID", None) is not None
|
13 |
|
14 |
transformer = Transformer2DModel.from_pretrained(
|
15 |
"PixArt-alpha/PixArt-XL-2-1024-MS",
|
|
|
26 |
transformer=transformer,
|
27 |
torch_dtype=torch.float16,
|
28 |
)
|
29 |
+
if not IS_SPACE:
|
30 |
+
pipe.enable_xformers_memory_efficient_attention()
|
31 |
pipe = pipe.to(device)
|
32 |
else:
|
33 |
pipe = PixArtAlphaPipeline.from_pretrained(
|
|
|
50 |
NUM_INFERENCE_STEPS = 4
|
51 |
|
52 |
|
53 |
+
@spaces.GPU
|
54 |
def infer(prompt, seed, randomize_seed):
|
|
|
55 |
if randomize_seed:
|
56 |
seed = random.randint(0, MAX_SEED)
|
57 |
|
|
|
92 |
power_device = "CPU"
|
93 |
|
94 |
with gr.Blocks(css=css) as demo:
|
|
|
95 |
with gr.Column(elem_id="col-container"):
|
96 |
gr.Markdown(
|
97 |
f"""
|
|
|
107 |
)
|
108 |
|
109 |
with gr.Row():
|
|
|
110 |
prompt = gr.Text(
|
111 |
label="Prompt",
|
112 |
show_label=False,
|
|
|
120 |
result = gr.Image(label="Result", show_label=False)
|
121 |
|
122 |
with gr.Accordion("Advanced Settings", open=False):
|
|
|
123 |
seed = gr.Slider(
|
124 |
label="Seed",
|
125 |
minimum=0,
|
|
|
132 |
|
133 |
examples = gr.Examples(examples=examples, inputs=[prompt])
|
134 |
|
135 |
+
gr.Markdown("**Disclaimer:**")
|
|
|
|
|
136 |
gr.Markdown(
|
137 |
"This demo is only for research purpose. Jasper cannot be held responsible for the generation of NSFW (Not Safe For Work) content through the use of this demo. Users are solely responsible for any content they create, and it is their obligation to ensure that it adheres to appropriate and ethical standards. Jasper provides the tools, but the responsibility for their use lies with the individual user."
|
138 |
)
|
139 |
+
gr.on(
|
140 |
+
[run_button.click, seed.change, prompt.change, randomize_seed.change],
|
141 |
+
fn=infer,
|
142 |
+
inputs=[prompt, seed, randomize_seed],
|
143 |
+
outputs=[result],
|
144 |
+
show_progress="minimal",
|
145 |
+
show_api=False,
|
146 |
+
trigger_mode="always_last",
|
147 |
+
)
|
148 |
|
149 |
demo.queue().launch(show_api=False)
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
accelerate
|
2 |
-
diffusers
|
3 |
invisible_watermark
|
4 |
--extra-index-url https://download.pytorch.org/whl/cu118
|
5 |
torch==2.0.1
|
@@ -9,4 +9,5 @@ optimum
|
|
9 |
beautifulsoup4
|
10 |
transformers >= 4.34.0
|
11 |
xformers
|
12 |
-
ftfy
|
|
|
|
1 |
accelerate
|
2 |
+
git+https://github.com/huggingface/diffusers/
|
3 |
invisible_watermark
|
4 |
--extra-index-url https://download.pytorch.org/whl/cu118
|
5 |
torch==2.0.1
|
|
|
9 |
beautifulsoup4
|
10 |
transformers >= 4.34.0
|
11 |
xformers
|
12 |
+
ftfy
|
13 |
+
spaces
|