Narsil HF staff commited on
Commit
036cfd1
1 Parent(s): 656540b

Downloader.

Browse files
Files changed (2) hide show
  1. app.py +42 -3
  2. requirements.txt +2 -0
app.py CHANGED
@@ -1,7 +1,46 @@
 
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  iface.launch()
 
1
+ import os
2
  import gradio as gr
3
+ import datetime
4
+ import tempfile
5
+ from huggingface_hub import hf_hub_download
6
 
 
 
7
 
8
+ def download_slow(repo_id):
9
+ os.environ.pop("HF_TRANSFER", None)
10
+ with tempfile.NamedDirectory() as workdir:
11
+ hf_hub_download(
12
+ repo_id,
13
+ filename="pytorch_model.bin",
14
+ force_download=True,
15
+ cache_dir=workdir,
16
+ )
17
+
18
+
19
+ def download_fast(repo_id):
20
+ os.environ["HF_TRANSFER"] = "1"
21
+ with tempfile.NamedDirectory() as workdir:
22
+ hf_hub_download(
23
+ repo_id,
24
+ filename="pytorch_model.bin",
25
+ force_download=True,
26
+ cache_dir=workdir,
27
+ )
28
+
29
+
30
+ def download(repo_id):
31
+ start = datetime.datetime.now()
32
+ download_slow(repo_id)
33
+ taken_slow = datetime.datetime.now() - start
34
+
35
+ start = datetime.datetime.now()
36
+ download_fast(repo_id)
37
+ taken_fast = datetime.datetime.now() - start
38
+
39
+ return f"""
40
+ Slow : {taken_slow}
41
+ Fast : {taken_fast}
42
+ """
43
+
44
+
45
+ iface = gr.Interface(fn=download, inputs="text", outputs="text")
46
  iface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ hf_transfer
2
+ -e git+https://github.com/huggingface/huggingface_hub@hf_transfer#egg=huggingface_hub