File size: 3,926 Bytes
2422035
f6bd4fa
2422035
 
c6196a6
2422035
 
af9852d
f6bd4fa
44698e5
6ca9756
dec8cc6
 
 
 
 
 
 
 
 
 
6ca9756
dec8cc6
 
6ca9756
3659749
 
 
 
 
 
 
b8cecf5
 
206ba2d
2ab105b
b8cecf5
 
 
 
 
 
 
 
 
 
ff3dacd
 
b8cecf5
206ba2d
 
 
0e6546e
2422035
92d53c1
2422035
 
0e7e92c
 
2422035
 
 
 
 
 
 
 
91ff2e6
7f39688
91ff2e6
c6196a6
2422035
 
66ffc69
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from PIL import Image
import gradio as gr
from huggingface_hub import hf_hub_download
from model import Model
from app_edge import create_demo as create_demo_edge
from app_depth import create_demo as create_demo_depth
import os
import torch

import subprocess

# def install_requirements():
#     try:
#         # subprocess.run(['pip', 'install', 'torch==2.1.2+cu118', '--extra-index-url', 'https://download.pytorch.org/whl/cu118'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#         subprocess.run(['pip', 'show', 'torch'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#         # result = subprocess.run(['pip', 'install', '-r', 'requirements.txt'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#         print("安装成功!")
#         # print("输出:", result.stdout.decode('utf-8'))
#     except subprocess.CalledProcessError as e:
#         print("安装失败!")
#         print("错误:", e.stderr.decode('utf-8'))

# install_requirements()
print("Torch version:", torch.__version__)

# hf_hub_download(repo_id='wondervictor/ControlAR',
#                 filename='canny_MR.safetensors',
#                 local_dir='./checkpoints/')
# hf_hub_download(repo_id='wondervictor/ControlAR',
#                 filename='depth_MR.safetensors',
#                 local_dir='./checkpoints/')
# # hf_hub_download('google/flan-t5-xl', cache_dir='./checkpoints/')
ckpt_folder = './checkpoints'
t5_folder = os.path.join(ckpt_folder, "flan-t5-xl/flan-t5-xl")
# dinov2_folder = os.path.join(ckpt_folder, "dinov2-small")
dinov2_folder = os.path.join(ckpt_folder, "dinov2-base")
hf_hub_download(repo_id="google/flan-t5-xl", filename="config.json", local_dir=t5_folder)
hf_hub_download(repo_id="google/flan-t5-xl", filename="pytorch_model-00001-of-00002.bin", local_dir=t5_folder)
hf_hub_download(repo_id="google/flan-t5-xl", filename="pytorch_model-00002-of-00002.bin", local_dir=t5_folder)
hf_hub_download(repo_id="google/flan-t5-xl", filename="pytorch_model.bin.index.json", local_dir=t5_folder)
hf_hub_download(repo_id="google/flan-t5-xl", filename="special_tokens_map.json", local_dir=t5_folder)
hf_hub_download(repo_id="google/flan-t5-xl", filename="spiece.model", local_dir=t5_folder)
hf_hub_download(repo_id="google/flan-t5-xl", filename="tokenizer_config.json", local_dir=t5_folder)

hf_hub_download(repo_id="lllyasviel/Annotators", filename="dpt_hybrid-midas-501f0c75.pt", local_dir=ckpt_folder)

hf_hub_download(repo_id="wondervictor/ControlAR", filename="edge_base.safetensors", local_dir=ckpt_folder)
hf_hub_download(repo_id="wondervictor/ControlAR", filename="depth_base.safetensors", local_dir=ckpt_folder)

hf_hub_download(repo_id="facebook/dinov2-base", filename="config.json", local_dir=dinov2_folder)
hf_hub_download(repo_id="facebook/dinov2-base", filename="preprocessor_config.json", local_dir=dinov2_folder)
hf_hub_download(repo_id="facebook/dinov2-base", filename="pytorch_model.bin", local_dir=dinov2_folder)


DESCRIPTION = "# [ControlAR: Controllable Image Generation with Autoregressive Models](https://arxiv.org/abs/2410.02705) \n ### The first image in outputs is the condition. The others are the images generated by ControlAR.  \n ### You can run locally by following the instruction on our [Github Repo](https://github.com/hustvl/ControlAR)."
SHOW_DUPLICATE_BUTTON = os.getenv("SHOW_DUPLICATE_BUTTON") == "1"
model = Model()
# device = "cuda"
# model.to(device)
with gr.Blocks(css="style.css") as demo:
    gr.Markdown(DESCRIPTION)
    gr.DuplicateButton(
        value="Duplicate Space for private use",
        elem_id="duplicate-button",
        visible=SHOW_DUPLICATE_BUTTON,
    )
    with gr.Tabs():
        with gr.TabItem("Depth to Image"):
            create_demo_depth(model.process_depth)
        with gr.TabItem("Edge to Image"):
            create_demo_edge(model.process_edge)

if __name__ == "__main__":
    demo.launch(share=False)