Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	Upload 7 files
Browse files- README.md +1 -1
 - civitai_to_hf.py +1 -1
 - utils.py +39 -0
 
    	
        README.md
    CHANGED
    
    | 
         @@ -4,7 +4,7 @@ emoji: 🤗 
     | 
|
| 4 | 
         
             
            colorFrom: yellow
         
     | 
| 5 | 
         
             
            colorTo: blue
         
     | 
| 6 | 
         
             
            sdk: gradio
         
     | 
| 7 | 
         
            -
            sdk_version: 5. 
     | 
| 8 | 
         
             
            app_file: app.py
         
     | 
| 9 | 
         
             
            pinned: false
         
     | 
| 10 | 
         
             
            license: mit
         
     | 
| 
         | 
|
| 4 | 
         
             
            colorFrom: yellow
         
     | 
| 5 | 
         
             
            colorTo: blue
         
     | 
| 6 | 
         
             
            sdk: gradio
         
     | 
| 7 | 
         
            +
            sdk_version: 5.4.0
         
     | 
| 8 | 
         
             
            app_file: app.py
         
     | 
| 9 | 
         
             
            pinned: false
         
     | 
| 10 | 
         
             
            license: mit
         
     | 
    	
        civitai_to_hf.py
    CHANGED
    
    | 
         @@ -140,7 +140,7 @@ def download_civitai(dl_url, civitai_key, hf_token, urls, 
     | 
|
| 140 | 
         | 
| 141 | 
         | 
| 142 | 
         
             
            CIVITAI_TYPE = ["Checkpoint", "TextualInversion", "Hypernetwork", "AestheticGradient", "LORA", "Controlnet", "Poses"]
         
     | 
| 143 | 
         
            -
            CIVITAI_BASEMODEL = ["Pony", " 
     | 
| 144 | 
         
             
            CIVITAI_SORT = ["Highest Rated", "Most Downloaded", "Newest"]
         
     | 
| 145 | 
         
             
            CIVITAI_PERIOD = ["AllTime", "Year", "Month", "Week", "Day"]
         
     | 
| 146 | 
         | 
| 
         | 
|
| 140 | 
         | 
| 141 | 
         | 
| 142 | 
         
             
            CIVITAI_TYPE = ["Checkpoint", "TextualInversion", "Hypernetwork", "AestheticGradient", "LORA", "Controlnet", "Poses"]
         
     | 
| 143 | 
         
            +
            CIVITAI_BASEMODEL = ["Pony", "Illustrious", "SDXL 1.0", "SD 1.5", "Flux.1 D", "Flux.1 S"]
         
     | 
| 144 | 
         
             
            CIVITAI_SORT = ["Highest Rated", "Most Downloaded", "Newest"]
         
     | 
| 145 | 
         
             
            CIVITAI_PERIOD = ["AllTime", "Year", "Month", "Week", "Day"]
         
     | 
| 146 | 
         | 
    	
        utils.py
    CHANGED
    
    | 
         @@ -6,6 +6,7 @@ import shutil 
     | 
|
| 6 | 
         
             
            import gc
         
     | 
| 7 | 
         
             
            import re
         
     | 
| 8 | 
         
             
            import urllib.parse
         
     | 
| 
         | 
|
| 9 | 
         | 
| 10 | 
         | 
| 11 | 
         
             
            def get_token():
         
     | 
| 
         @@ -227,3 +228,41 @@ def duplicate_hf_repo(src_repo: str, dst_repo: str, src_repo_type: str, dst_repo 
     | 
|
| 227 | 
         
             
                    print(f"Error: Failed to duplicate repo {src_repo} to {dst_repo}. {e}")
         
     | 
| 228 | 
         
             
                    return ""
         
     | 
| 229 | 
         | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
| 
         | 
|
| 6 | 
         
             
            import gc
         
     | 
| 7 | 
         
             
            import re
         
     | 
| 8 | 
         
             
            import urllib.parse
         
     | 
| 9 | 
         
            +
            import subprocess
         
     | 
| 10 | 
         | 
| 11 | 
         | 
| 12 | 
         
             
            def get_token():
         
     | 
| 
         | 
|
| 228 | 
         
             
                    print(f"Error: Failed to duplicate repo {src_repo} to {dst_repo}. {e}")
         
     | 
| 229 | 
         
             
                    return ""
         
     | 
| 230 | 
         | 
| 231 | 
         
            +
             
     | 
| 232 | 
         
            +
            BASE_DIR = str(Path(__file__).resolve().parent.resolve())
         
     | 
| 233 | 
         
            +
            CIVITAI_API_KEY = os.environ.get("CIVITAI_API_KEY")
         
     | 
| 234 | 
         
            +
             
     | 
| 235 | 
         
            +
             
     | 
| 236 | 
         
            +
            def get_file(url: str, path: str): # requires aria2, gdown
         
     | 
| 237 | 
         
            +
                print(f"Downloading {url} to {path}...")
         
     | 
| 238 | 
         
            +
                get_download_file(path, url, CIVITAI_API_KEY)
         
     | 
| 239 | 
         
            +
             
     | 
| 240 | 
         
            +
             
     | 
| 241 | 
         
            +
            def git_clone(url: str, path: str, pip: bool=False, addcmd: str=""): # requires git
         
     | 
| 242 | 
         
            +
                os.makedirs(str(Path(BASE_DIR, path)), exist_ok=True)
         
     | 
| 243 | 
         
            +
                os.chdir(Path(BASE_DIR, path))
         
     | 
| 244 | 
         
            +
                print(f"Cloning {url} to {path}...")
         
     | 
| 245 | 
         
            +
                cmd = f'git clone {url}'
         
     | 
| 246 | 
         
            +
                print(f'Running {cmd} at {Path.cwd()}')
         
     | 
| 247 | 
         
            +
                i = subprocess.run(cmd, shell=True).returncode
         
     | 
| 248 | 
         
            +
                if i != 0: print(f'Error occured at running {cmd}')
         
     | 
| 249 | 
         
            +
                p = url.split("/")[-1]
         
     | 
| 250 | 
         
            +
                if not Path(p).exists: return
         
     | 
| 251 | 
         
            +
                if pip:
         
     | 
| 252 | 
         
            +
                    os.chdir(Path(BASE_DIR, path, p))
         
     | 
| 253 | 
         
            +
                    cmd = f'pip install -r requirements.txt'
         
     | 
| 254 | 
         
            +
                    print(f'Running {cmd} at {Path.cwd()}')
         
     | 
| 255 | 
         
            +
                    i = subprocess.run(cmd, shell=True).returncode
         
     | 
| 256 | 
         
            +
                    if i != 0: print(f'Error occured at running {cmd}')
         
     | 
| 257 | 
         
            +
                if addcmd:
         
     | 
| 258 | 
         
            +
                    os.chdir(Path(BASE_DIR, path, p))
         
     | 
| 259 | 
         
            +
                    cmd = addcmd
         
     | 
| 260 | 
         
            +
                    print(f'Running {cmd} at {Path.cwd()}')
         
     | 
| 261 | 
         
            +
                    i = subprocess.run(cmd, shell=True).returncode
         
     | 
| 262 | 
         
            +
                    if i != 0: print(f'Error occured at running {cmd}')
         
     | 
| 263 | 
         
            +
             
     | 
| 264 | 
         
            +
             
     | 
| 265 | 
         
            +
            def run(cmd: str):
         
     | 
| 266 | 
         
            +
                print(f'Running {cmd} at {Path.cwd()}')
         
     | 
| 267 | 
         
            +
                i = subprocess.run(cmd, shell=True).returncode
         
     | 
| 268 | 
         
            +
                if i != 0: print(f'Error occured at running {cmd}')
         
     |