Spaces:
Sleeping
Sleeping
File size: 1,454 Bytes
ee52aeb f72f753 ee52aeb 1b49c62 a961aec 1b49c62 ee52aeb 22a101f a961aec f72f753 3e16a9f a961aec f72f753 1b49c62 8bed913 22a101f 8bed913 2392655 8bed913 f72f753 40b1a45 ee52aeb |
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 gradio as gr
from huggingface_hub import HfApi
import os
hf_api = HfApi()
CURRENT_MODEL_PATH = "./current_model"
HF_TOKEN = os.environ.get("HF_TOKEN", None)
REPO = os.getenv("REPO")
REVISION = os.getenv("REVISION")
TARGET = os.getenv("TARGET")
def func(hf_token, repo, revision, target_repo):
hf_token = hf_token if hf_token else HF_TOKEN
repo = repo if repo else REPO
revision = revision if revision else REVISION
target_repo = target_repo if target_repo else TARGET
print('download the desired model locally ...')
hf_api.snapshot_download(
repo_id=repo,
revision=revision,
token=hf_token,
local_dir=CURRENT_MODEL_PATH,
)
print(os.listdir(CURRENT_MODEL_PATH))
print(f"The content of {repo}/{revision} has been copied to {target_repo}!" )
for file in os.listdir(CURRENT_MODEL_PATH):
print(f'uploading {file}')
with open(f"{CURRENT_MODEL_PATH}/{file}", "rb") as fobj:
hf_api.upload_file(
path_or_fileobj=fobj,
path_in_repo=f"{file}",
repo_id=target_repo,
repo_type="model",
token=hf_token,
commit_message=f"updating model files: {file}-{revision}",
)
return f"The content of {repo}/{revision} has been copied to {target_repo}!"
iface = gr.Interface(fn=func, inputs=["text","text","text"], outputs="text")
iface.launch() |