Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,057 Bytes
036cfd1 656540b 036cfd1 656540b 036cfd1 656540b |
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 |
import os
import gradio as gr
import datetime
import tempfile
from huggingface_hub import hf_hub_download
def download_slow(repo_id):
os.environ.pop("HF_TRANSFER", None)
with tempfile.NamedDirectory() as workdir:
hf_hub_download(
repo_id,
filename="pytorch_model.bin",
force_download=True,
cache_dir=workdir,
)
def download_fast(repo_id):
os.environ["HF_TRANSFER"] = "1"
with tempfile.NamedDirectory() as workdir:
hf_hub_download(
repo_id,
filename="pytorch_model.bin",
force_download=True,
cache_dir=workdir,
)
def download(repo_id):
start = datetime.datetime.now()
download_slow(repo_id)
taken_slow = datetime.datetime.now() - start
start = datetime.datetime.now()
download_fast(repo_id)
taken_fast = datetime.datetime.now() - start
return f"""
Slow : {taken_slow}
Fast : {taken_fast}
"""
iface = gr.Interface(fn=download, inputs="text", outputs="text")
iface.launch()
|