Alexander Bagus commited on
Commit
656efd6
·
1 Parent(s): 386c360
Files changed (2) hide show
  1. app.py +5 -0
  2. utils/repo_utils.py +33 -0
app.py CHANGED
@@ -8,10 +8,15 @@ from transformers import AutoTokenizer, Qwen3ForCausalLM
8
  from diffusers import AutoencoderKL
9
  from utils.image_utils import get_image_latent, rescale_image
10
  from utils.prompt_utils import polish_prompt
 
11
  # from controlnet_aux import HEDdetector, MLSDdetector, OpenposeDetector, CannyDetector, MidasDetector
12
  from controlnet_aux.processor import Processor
13
 
14
 
 
 
 
 
15
  # MODEL_REPO = "Tongyi-MAI/Z-Image-Turbo"
16
  MAX_SEED = np.iinfo(np.int32).max
17
  MAX_IMAGE_SIZE = 1280
 
8
  from diffusers import AutoencoderKL
9
  from utils.image_utils import get_image_latent, rescale_image
10
  from utils.prompt_utils import polish_prompt
11
+ from utils import repo_utils
12
  # from controlnet_aux import HEDdetector, MLSDdetector, OpenposeDetector, CannyDetector, MidasDetector
13
  from controlnet_aux.processor import Processor
14
 
15
 
16
+ repo_utils.clone_repo_if_not_exists("https://huggingface.co/Tongyi-MAI/Z-Image-Turbo", "app/models")
17
+ repo_utils.clone_repo_if_not_exists("https://huggingface.co/alibaba-pai/Z-Image-Turbo-Fun-Controlnet-Union", "app/models")
18
+
19
+
20
  # MODEL_REPO = "Tongyi-MAI/Z-Image-Turbo"
21
  MAX_SEED = np.iinfo(np.int32).max
22
  MAX_IMAGE_SIZE = 1280
utils/repo_utils.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, subprocess
2
+
3
+ def clone_repo_if_not_exists(git_url, git_dir):
4
+ """
5
+ Clones a Git repository if it doesn't already exist in the git_dir folder.
6
+ """
7
+ home_dir = os.path.expanduser("~")
8
+ models_dir = os.path.join(home_dir, git_dir)
9
+
10
+ # Extract repository name from the Git URL
11
+ if git_url.endswith(".git"):
12
+ git_name = git_url.split('/')[-1][:-4]
13
+ else:
14
+ git_name = git_url.split('/')[-1]
15
+
16
+ repo_path = os.path.join(models_dir, git_name)
17
+
18
+ if not os.path.exists(models_dir):
19
+ os.makedirs(models_dir)
20
+ print(f"Created directory: {models_dir}")
21
+
22
+ if not os.path.exists(repo_path):
23
+ print(f"Repository '{git_name}' not found in '{models_dir}'. Cloning from {git_url}...")
24
+ try:
25
+ subprocess.run(["git", "clone", git_url, repo_path], check=True)
26
+ print(f"Successfully cloned '{git_name}' to '{repo_path}'.")
27
+ except subprocess.CalledProcessError as e:
28
+ print(f"Error cloning repository: {e}")
29
+ except FileNotFoundError:
30
+ print("Error: 'git' command not found. Please ensure Git is installed and in your PATH.")
31
+ else:
32
+ print(f"Repository '{git_name}' already exists at '{repo_path}'. Skipping clone.")
33
+