Spaces:
Sleeping
Sleeping
Ray Chen
commited on
Commit
·
64d468d
1
Parent(s):
31ffb4a
new: get HF space information from config
Browse files- .github/tools/config.py +9 -0
- .github/tools/deploy_to_space.py +8 -5
- .github/tools/model.py +15 -0
.github/tools/config.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, Literal
|
2 |
+
|
3 |
+
from model import Config
|
4 |
+
|
5 |
+
UserName = Literal["default"]
|
6 |
+
|
7 |
+
SPACE_CONFIG: Dict[UserName, Config] = {
|
8 |
+
"default": {"space_name": "example", "space_owner": "jy-raychen"}
|
9 |
+
}
|
.github/tools/deploy_to_space.py
CHANGED
@@ -2,18 +2,19 @@ import argparse
|
|
2 |
import subprocess
|
3 |
import sys
|
4 |
|
|
|
|
|
|
|
5 |
DEFAULT_USER = "jy-raychen"
|
6 |
-
DEFAULT_SPACE_OWNER = "jy-raychen"
|
7 |
-
DEFAULT_SPACE_NAME = "example"
|
8 |
|
9 |
|
10 |
-
def force_push_to_remote(token, branch_name):
|
11 |
proc = subprocess.run(
|
12 |
[
|
13 |
"git",
|
14 |
"push",
|
15 |
"--force",
|
16 |
-
f"https://{DEFAULT_USER}:{token}@huggingface.co/spaces/{
|
17 |
f"{branch_name}:main",
|
18 |
],
|
19 |
capture_output=True,
|
@@ -34,7 +35,9 @@ if __name__ == "__main__":
|
|
34 |
parser.add_argument("--user_token", required=True)
|
35 |
args = parser.parse_args()
|
36 |
|
37 |
-
|
|
|
|
|
38 |
if not push_result:
|
39 |
sys.exit(1)
|
40 |
print(push_result)
|
|
|
2 |
import subprocess
|
3 |
import sys
|
4 |
|
5 |
+
from config import SPACE_CONFIG
|
6 |
+
from model import Space
|
7 |
+
|
8 |
DEFAULT_USER = "jy-raychen"
|
|
|
|
|
9 |
|
10 |
|
11 |
+
def force_push_to_remote(space: Space, token: str, branch_name: str):
|
12 |
proc = subprocess.run(
|
13 |
[
|
14 |
"git",
|
15 |
"push",
|
16 |
"--force",
|
17 |
+
f"https://{DEFAULT_USER}:{token}@huggingface.co/spaces/{space.owner}/{space.name}",
|
18 |
f"{branch_name}:main",
|
19 |
],
|
20 |
capture_output=True,
|
|
|
35 |
parser.add_argument("--user_token", required=True)
|
36 |
args = parser.parse_args()
|
37 |
|
38 |
+
space = Space(SPACE_CONFIG["default"])
|
39 |
+
|
40 |
+
push_result = force_push_to_remote(space, args.user_token, args.branch_name)
|
41 |
if not push_result:
|
42 |
sys.exit(1)
|
43 |
print(push_result)
|
.github/tools/model.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import TypedDict
|
2 |
+
|
3 |
+
|
4 |
+
class Config(TypedDict):
|
5 |
+
space_name: str
|
6 |
+
space_owner: str
|
7 |
+
|
8 |
+
|
9 |
+
class Space:
|
10 |
+
name: str
|
11 |
+
owner: str
|
12 |
+
|
13 |
+
def __init__(self, config: Config):
|
14 |
+
self.name = config["space_name"]
|
15 |
+
self.owner = config["space_owner"]
|