Spaces:
Running
Running
File size: 1,361 Bytes
2718c61 1a990e7 2718c61 1a990e7 2718c61 |
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 |
import os
import sys
import git
import subprocess
from huggingface_hub import hf_hub_download
REPO_URL = "https://github.com/facebookresearch/watermark-anything.git"
REPO_BRANCH = '45d56c2b61f2bc73caeafc90e14df33ad50b238c'
LOCAL_PATH = "./watermark-anything"
MODEL_ID = "facebook/watermark-anything"
def install_src():
if not os.path.exists(LOCAL_PATH):
print(f"Cloning repository from {REPO_URL}...")
repo = git.Repo.clone_from(REPO_URL, LOCAL_PATH)
repo.git.checkout(REPO_BRANCH)
else:
print(f"Repository already exists at {LOCAL_PATH}")
requirements_path = os.path.join(LOCAL_PATH, "requirements.txt")
if os.path.exists(requirements_path):
print("Installing requirements...")
subprocess.check_call(["pip", "install", "-r", requirements_path])
else:
print("No requirements.txt found.")
def install_model():
checkpoint_path = os.path.join(LOCAL_PATH, "checkpoints")
hf_hub_download(repo_id=MODEL_ID, filename='checkpoint.pth', local_dir=checkpoint_path)
# clone repo and download model
install_src()
install_model()
# change directory
print(f"Current Directory: {os.getcwd()}")
os.chdir(LOCAL_PATH)
print(f"New Directory: {os.getcwd()}")
# fix sys.path for import
sys.path.append(os.getcwd())
# run gradio
import gradio_app
|