Spaces:
Runtime error
Runtime error
wondervictor
commited on
Commit
·
1925277
1
Parent(s):
2a1f69d
add requirements
Browse files- app.py +6 -4
- app_canny.py +58 -20
- app_depth.py +59 -29
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -6,12 +6,14 @@ from app_canny import create_demo as create_demo_canny
|
|
| 6 |
from app_depth import create_demo as create_demo_depth
|
| 7 |
import os
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
# hf_hub_download('google/flan-t5-xl', cache_dir='./checkpoints/')
|
| 13 |
|
| 14 |
-
|
| 15 |
DESCRIPTION = "# [ControlAR: Controllable Image Generation with Autoregressive Models](https://arxiv.org/abs/2410.02705) \n ### The first row in outputs is the input image and condition. The second row is the images generated by ControlAR. \n ### You can run locally by following the instruction on our [Github Repo](https://github.com/hustvl/ControlAR)."
|
| 16 |
SHOW_DUPLICATE_BUTTON = os.getenv("SHOW_DUPLICATE_BUTTON") == "1"
|
| 17 |
model = Model()
|
|
|
|
| 6 |
from app_depth import create_demo as create_demo_depth
|
| 7 |
import os
|
| 8 |
|
| 9 |
+
hf_hub_download('wondervictor/ControlAR',
|
| 10 |
+
filename='canny_MR.safetensors',
|
| 11 |
+
cache_dir='./checkpoints/')
|
| 12 |
+
hf_hub_download('wondervictor/ControlAR',
|
| 13 |
+
filename='depth_MR.safetensors',
|
| 14 |
+
cache_dir='./checkpoints/')
|
| 15 |
# hf_hub_download('google/flan-t5-xl', cache_dir='./checkpoints/')
|
| 16 |
|
|
|
|
| 17 |
DESCRIPTION = "# [ControlAR: Controllable Image Generation with Autoregressive Models](https://arxiv.org/abs/2410.02705) \n ### The first row in outputs is the input image and condition. The second row is the images generated by ControlAR. \n ### You can run locally by following the instruction on our [Github Repo](https://github.com/hustvl/ControlAR)."
|
| 18 |
SHOW_DUPLICATE_BUTTON = os.getenv("SHOW_DUPLICATE_BUTTON") == "1"
|
| 19 |
model = Model()
|
app_canny.py
CHANGED
|
@@ -1,9 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
|
|
|
|
|
|
| 3 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
| 4 |
if randomize_seed:
|
| 5 |
seed = random.randint(0, 100000000)
|
| 6 |
return seed
|
|
|
|
|
|
|
| 7 |
examples = [
|
| 8 |
[
|
| 9 |
"condition/example/t2i/multigen/doll.png",
|
|
@@ -12,15 +16,15 @@ examples = [
|
|
| 12 |
],
|
| 13 |
[
|
| 14 |
"condition/example/t2i/multigen/girl.png",
|
| 15 |
-
"An anime style girl with blue hair",
|
| 16 |
-
"(512, 512)"
|
| 17 |
],
|
| 18 |
[
|
| 19 |
-
"condition/example/t2i/multi_resolution/bird.jpg",
|
| 20 |
-
"colorful bird",
|
| 21 |
"(921, 564)"
|
| 22 |
],
|
| 23 |
]
|
|
|
|
|
|
|
| 24 |
def create_demo(process):
|
| 25 |
with gr.Blocks() as demo:
|
| 26 |
with gr.Row():
|
|
@@ -30,20 +34,55 @@ def create_demo(process):
|
|
| 30 |
run_button = gr.Button("Run")
|
| 31 |
with gr.Accordion("Advanced options", open=False):
|
| 32 |
canny_low_threshold = gr.Slider(
|
| 33 |
-
label="Canny low threshold",
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 35 |
canny_high_threshold = gr.Slider(
|
| 36 |
-
label="Canny high threshold",
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
with gr.Column():
|
| 46 |
-
result = gr.Gallery(label="Output",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
gr.Examples(
|
| 48 |
examples=examples,
|
| 49 |
inputs=[
|
|
@@ -90,11 +129,10 @@ def create_demo(process):
|
|
| 90 |
api_name="canny",
|
| 91 |
)
|
| 92 |
return demo
|
|
|
|
|
|
|
| 93 |
if __name__ == "__main__":
|
| 94 |
from model import Model
|
| 95 |
model = Model()
|
| 96 |
demo = create_demo(model.process_canny)
|
| 97 |
-
demo.queue().launch(
|
| 98 |
-
share=False,
|
| 99 |
-
server_name="0.0.0.0"
|
| 100 |
-
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
+
|
| 4 |
+
|
| 5 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
| 6 |
if randomize_seed:
|
| 7 |
seed = random.randint(0, 100000000)
|
| 8 |
return seed
|
| 9 |
+
|
| 10 |
+
|
| 11 |
examples = [
|
| 12 |
[
|
| 13 |
"condition/example/t2i/multigen/doll.png",
|
|
|
|
| 16 |
],
|
| 17 |
[
|
| 18 |
"condition/example/t2i/multigen/girl.png",
|
| 19 |
+
"An anime style girl with blue hair", "(512, 512)"
|
|
|
|
| 20 |
],
|
| 21 |
[
|
| 22 |
+
"condition/example/t2i/multi_resolution/bird.jpg", "colorful bird",
|
|
|
|
| 23 |
"(921, 564)"
|
| 24 |
],
|
| 25 |
]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
def create_demo(process):
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
with gr.Row():
|
|
|
|
| 34 |
run_button = gr.Button("Run")
|
| 35 |
with gr.Accordion("Advanced options", open=False):
|
| 36 |
canny_low_threshold = gr.Slider(
|
| 37 |
+
label="Canny low threshold",
|
| 38 |
+
minimum=0,
|
| 39 |
+
maximum=1000,
|
| 40 |
+
value=100,
|
| 41 |
+
step=50)
|
| 42 |
canny_high_threshold = gr.Slider(
|
| 43 |
+
label="Canny high threshold",
|
| 44 |
+
minimum=0,
|
| 45 |
+
maximum=1000,
|
| 46 |
+
value=200,
|
| 47 |
+
step=50)
|
| 48 |
+
cfg_scale = gr.Slider(label="Guidance scale",
|
| 49 |
+
minimum=0.1,
|
| 50 |
+
maximum=30.0,
|
| 51 |
+
value=4,
|
| 52 |
+
step=0.1)
|
| 53 |
+
relolution = gr.Slider(label="(H, W)",
|
| 54 |
+
minimum=384,
|
| 55 |
+
maximum=768,
|
| 56 |
+
value=512,
|
| 57 |
+
step=16)
|
| 58 |
+
top_k = gr.Slider(minimum=1,
|
| 59 |
+
maximum=16384,
|
| 60 |
+
step=1,
|
| 61 |
+
value=2000,
|
| 62 |
+
label='Top-K')
|
| 63 |
+
top_p = gr.Slider(minimum=0.,
|
| 64 |
+
maximum=1.0,
|
| 65 |
+
step=0.1,
|
| 66 |
+
value=1.0,
|
| 67 |
+
label="Top-P")
|
| 68 |
+
temperature = gr.Slider(minimum=0.,
|
| 69 |
+
maximum=1.0,
|
| 70 |
+
step=0.1,
|
| 71 |
+
value=1.0,
|
| 72 |
+
label='Temperature')
|
| 73 |
+
seed = gr.Slider(label="Seed",
|
| 74 |
+
minimum=0,
|
| 75 |
+
maximum=100000000,
|
| 76 |
+
step=1,
|
| 77 |
+
value=0)
|
| 78 |
+
randomize_seed = gr.Checkbox(label="Randomize seed",
|
| 79 |
+
value=True)
|
| 80 |
with gr.Column():
|
| 81 |
+
result = gr.Gallery(label="Output",
|
| 82 |
+
show_label=False,
|
| 83 |
+
height='800px',
|
| 84 |
+
columns=2,
|
| 85 |
+
object_fit="scale-down")
|
| 86 |
gr.Examples(
|
| 87 |
examples=examples,
|
| 88 |
inputs=[
|
|
|
|
| 129 |
api_name="canny",
|
| 130 |
)
|
| 131 |
return demo
|
| 132 |
+
|
| 133 |
+
|
| 134 |
if __name__ == "__main__":
|
| 135 |
from model import Model
|
| 136 |
model = Model()
|
| 137 |
demo = create_demo(model.process_canny)
|
| 138 |
+
demo.queue().launch(share=False, server_name="0.0.0.0")
|
|
|
|
|
|
|
|
|
app_depth.py
CHANGED
|
@@ -1,26 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
|
|
|
|
|
|
| 3 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
| 4 |
if randomize_seed:
|
| 5 |
seed = random.randint(0, 100000000)
|
| 6 |
return seed
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
def create_demo(process):
|
| 25 |
with gr.Blocks() as demo:
|
| 26 |
with gr.Row():
|
|
@@ -29,15 +31,44 @@ def create_demo(process):
|
|
| 29 |
prompt = gr.Textbox(label="Prompt")
|
| 30 |
run_button = gr.Button("Run")
|
| 31 |
with gr.Accordion("Advanced options", open=False):
|
| 32 |
-
cfg_scale = gr.Slider(label="Guidance scale",
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
with gr.Column():
|
| 40 |
-
result = gr.Gallery(label="Output",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
gr.Examples(
|
| 42 |
examples=examples,
|
| 43 |
inputs=[
|
|
@@ -82,11 +113,10 @@ def create_demo(process):
|
|
| 82 |
api_name="canny",
|
| 83 |
)
|
| 84 |
return demo
|
|
|
|
|
|
|
| 85 |
if __name__ == "__main__":
|
| 86 |
from model import Model
|
| 87 |
model = Model()
|
| 88 |
demo = create_demo(model.process_depth)
|
| 89 |
-
demo.queue().launch(
|
| 90 |
-
share=False,
|
| 91 |
-
server_name="0.0.0.0"
|
| 92 |
-
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
+
|
| 4 |
+
|
| 5 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
| 6 |
if randomize_seed:
|
| 7 |
seed = random.randint(0, 100000000)
|
| 8 |
return seed
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
examples = [[
|
| 12 |
+
"condition/example/t2i/multigen/sofa.png",
|
| 13 |
+
"The red sofa in the living room has several pillows on it", "(512, 512)"
|
| 14 |
+
],
|
| 15 |
+
[
|
| 16 |
+
"condition/example/t2i/multigen/house.png",
|
| 17 |
+
"A brick house with a chimney under a starry sky.",
|
| 18 |
+
"(512, 512)"
|
| 19 |
+
],
|
| 20 |
+
[
|
| 21 |
+
"condition/example/t2i/multi_resolution/car.jpg",
|
| 22 |
+
"a sport car", "(448, 768)"
|
| 23 |
+
]]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
def create_demo(process):
|
| 27 |
with gr.Blocks() as demo:
|
| 28 |
with gr.Row():
|
|
|
|
| 31 |
prompt = gr.Textbox(label="Prompt")
|
| 32 |
run_button = gr.Button("Run")
|
| 33 |
with gr.Accordion("Advanced options", open=False):
|
| 34 |
+
cfg_scale = gr.Slider(label="Guidance scale",
|
| 35 |
+
minimum=0.1,
|
| 36 |
+
maximum=30.0,
|
| 37 |
+
value=4,
|
| 38 |
+
step=0.1)
|
| 39 |
+
resolution = gr.Slider(label="(H, W)",
|
| 40 |
+
minimum=384,
|
| 41 |
+
maximum=768,
|
| 42 |
+
value=512,
|
| 43 |
+
step=16)
|
| 44 |
+
top_k = gr.Slider(minimum=1,
|
| 45 |
+
maximum=16384,
|
| 46 |
+
step=1,
|
| 47 |
+
value=2000,
|
| 48 |
+
label='Top-K')
|
| 49 |
+
top_p = gr.Slider(minimum=0.,
|
| 50 |
+
maximum=1.0,
|
| 51 |
+
step=0.1,
|
| 52 |
+
value=1.0,
|
| 53 |
+
label="Top-P")
|
| 54 |
+
temperature = gr.Slider(minimum=0.,
|
| 55 |
+
maximum=1.0,
|
| 56 |
+
step=0.1,
|
| 57 |
+
value=1.0,
|
| 58 |
+
label='Temperature')
|
| 59 |
+
seed = gr.Slider(label="Seed",
|
| 60 |
+
minimum=0,
|
| 61 |
+
maximum=100000000,
|
| 62 |
+
step=1,
|
| 63 |
+
value=0)
|
| 64 |
+
randomize_seed = gr.Checkbox(label="Randomize seed",
|
| 65 |
+
value=True)
|
| 66 |
with gr.Column():
|
| 67 |
+
result = gr.Gallery(label="Output",
|
| 68 |
+
show_label=False,
|
| 69 |
+
height='800px',
|
| 70 |
+
columns=2,
|
| 71 |
+
object_fit="scale-down")
|
| 72 |
gr.Examples(
|
| 73 |
examples=examples,
|
| 74 |
inputs=[
|
|
|
|
| 113 |
api_name="canny",
|
| 114 |
)
|
| 115 |
return demo
|
| 116 |
+
|
| 117 |
+
|
| 118 |
if __name__ == "__main__":
|
| 119 |
from model import Model
|
| 120 |
model = Model()
|
| 121 |
demo = create_demo(model.process_depth)
|
| 122 |
+
demo.queue().launch(share=False, server_name="0.0.0.0")
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -17,4 +17,5 @@ ftfy
|
|
| 17 |
clean-fid
|
| 18 |
safetensors
|
| 19 |
transformers
|
| 20 |
-
tiktoken
|
|
|
|
|
|
| 17 |
clean-fid
|
| 18 |
safetensors
|
| 19 |
transformers
|
| 20 |
+
tiktoken
|
| 21 |
+
sentencepiece
|