Spaces:
Runtime error
Runtime error
wfjsw
commited on
Commit
•
9de9174
1
Parent(s):
b1acc10
update
Browse files- .gitignore +1 -0
- app.py +59 -3
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
venv/
|
app.py
CHANGED
@@ -1,7 +1,63 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
return repo_name
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import json
|
3 |
+
from huggingface_hub import HfApi, hf_hub_download
|
4 |
+
import requests
|
5 |
+
import hashlib
|
6 |
|
7 |
+
api = HfApi()
|
|
|
8 |
|
9 |
+
def hash_file(path: str) -> str:
|
10 |
+
sha256_hash = hashlib.sha256()
|
11 |
+
with open(path, "rb") as f:
|
12 |
+
for byte_block in iter(lambda: f.read(4096), b""):
|
13 |
+
sha256_hash.update(byte_block)
|
14 |
+
return sha256_hash.hexdigest()
|
15 |
+
|
16 |
+
|
17 |
+
def hash_repo(repo_name: str):
|
18 |
+
converted = []
|
19 |
+
blobs = {}
|
20 |
+
sub_repo_id = repo_name.replace("/", "-").lower()
|
21 |
+
files = api.list_files_info(repo_name)
|
22 |
+
for file in files:
|
23 |
+
if file.lfs is not None:
|
24 |
+
converted.append(
|
25 |
+
{
|
26 |
+
"filename": file.rfilename,
|
27 |
+
"revision": "main",
|
28 |
+
"size": file.lfs["size"],
|
29 |
+
"sha256": file.lfs["sha256"],
|
30 |
+
}
|
31 |
+
)
|
32 |
+
blobs[file.lfs["sha256"]] = [
|
33 |
+
f"https://modelscope.cn/api/v1/models/hanamizukiai/{sub_repo_id}/repo?Revision=main&FilePath={file.rfilename}",
|
34 |
+
f"https://wisemodel.cn/file-proxy/hanamizuki-ai/{sub_repo_id}/-/raw/main/{file.rfilename}",
|
35 |
+
f"https://gitcode.net/spectator2639/{sub_repo_id}/-/raw/main/{file.rfilename}",
|
36 |
+
]
|
37 |
+
else:
|
38 |
+
filepath = hf_hub_download(repo_name, file.rfilename, revision="main")
|
39 |
+
hash = hash_file(filepath)
|
40 |
+
size = os.path.getsize(filepath)
|
41 |
+
converted.append(
|
42 |
+
{
|
43 |
+
"filename": file.rfilename,
|
44 |
+
"revision": "main",
|
45 |
+
"size": size,
|
46 |
+
"sha256": hash,
|
47 |
+
}
|
48 |
+
)
|
49 |
+
blobs[file.lfs["sha256"]] = [
|
50 |
+
f"https://modelscope.cn/api/v1/models/hanamizukiai/{sub_repo_id}/repo?Revision=main&FilePath={file.rfilename}",
|
51 |
+
f"https://wisemodel.cn/file-proxy/hanamizuki-ai/{sub_repo_id}/-/raw/main/{file.rfilename}",
|
52 |
+
f"https://gitcode.net/spectator2639/{sub_repo_id}/-/raw/main/{file.rfilename}",
|
53 |
+
]
|
54 |
+
return converted, blobs
|
55 |
+
|
56 |
+
|
57 |
+
iface = gr.Interface(
|
58 |
+
fn=hash_repo,
|
59 |
+
inputs="text",
|
60 |
+
outputs=["json", "json"],
|
61 |
+
title="Repo Hasher",
|
62 |
+
)
|
63 |
iface.launch()
|