Ray Chen commited on
Commit
4112a5c
·
1 Parent(s): d809b84

change: update README.md by GitHub Actions

Browse files
.github/tools/config.py CHANGED
@@ -5,5 +5,18 @@ from model import Config
5
  UserName = Literal["default"]
6
 
7
  SPACE_CONFIG: Dict[UserName, Config] = {
8
- "default": {"space_name": "example", "space_owner": "jy-raychen"}
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  }
 
5
  UserName = Literal["default"]
6
 
7
  SPACE_CONFIG: Dict[UserName, Config] = {
8
+ "default": {
9
+ "space_name": "example",
10
+ "space_owner": "jy-raychen",
11
+ "space_readme": {
12
+ "title": "Hugging Face Maintain",
13
+ "emoji": "🏢",
14
+ "color_from": "blue",
15
+ "color_to": "indigo",
16
+ "sdk": "gradio",
17
+ "sdk_version": "4.36.0",
18
+ "app_file": "app.py",
19
+ "pinned": False,
20
+ },
21
+ }
22
  }
.github/tools/generate_readme.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+
3
+ from config import SPACE_CONFIG
4
+ from model import ReadMe, Space
5
+
6
+ DEFAULT_USER = "jy-raychen"
7
+
8
+
9
+ def readme_template(readme: ReadMe):
10
+ return f"""---
11
+ title: {readme.title}
12
+ emoji: {readme.emoji}
13
+ colorFrom: {readme.color_from}
14
+ colorTo: {readme.color_to}
15
+ sdk: {readme.sdk}
16
+ sdk_version: {readme.sdk_version}
17
+ app_file: {readme.app_file}
18
+ pinned: {readme.pinned}
19
+ ---
20
+
21
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference"""
22
+
23
+
24
+ if __name__ == "__main__":
25
+ space = Space(SPACE_CONFIG["default"])
26
+
27
+ readme = readme_template(space.readme)
28
+ print(readme)
29
+ sys.exit(0)
.github/tools/model.py CHANGED
@@ -1,15 +1,50 @@
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"]
 
 
1
  from typing import TypedDict
2
 
3
 
4
+ class ReadMeConfig(TypedDict):
5
+ title: str
6
+ emoji: str
7
+ color_from: str
8
+ color_to: str
9
+ sdk: str
10
+ sdk_version: str
11
+ app_file: str
12
+ pinned: bool
13
+
14
+
15
+ class ReadMe:
16
+ title: str
17
+ emoji: str
18
+ color_from: str
19
+ color_to: str
20
+ sdk: str
21
+ sdk_version: str
22
+ app_file: str
23
+ pinned: str
24
+
25
+ def __init__(self, readme_config: ReadMeConfig):
26
+ self.title = readme_config["title"]
27
+ self.emoji = readme_config["emoji"]
28
+ self.color_from = readme_config["color_from"]
29
+ self.color_to = readme_config["color_to"]
30
+ self.sdk = readme_config["sdk"]
31
+ self.sdk_version = readme_config["sdk_version"]
32
+ self.app_file = readme_config["app_file"]
33
+ self.pinned = str(readme_config["pinned"]).lower()
34
+
35
+
36
  class Config(TypedDict):
37
  space_name: str
38
  space_owner: str
39
+ space_readme: ReadMe
40
 
41
 
42
  class Space:
43
  name: str
44
  owner: str
45
+ readme: ReadMeConfig
46
 
47
  def __init__(self, config: Config):
48
  self.name = config["space_name"]
49
  self.owner = config["space_owner"]
50
+ self.readme = ReadMe(config["space_readme"])
.github/workflows/deploy-to-space.yaml CHANGED
@@ -20,5 +20,14 @@ jobs:
20
  uses: actions/checkout@v4
21
  with:
22
  fetch-depth: '0'
 
 
 
 
 
 
 
 
 
23
  - name: Run deploy tool
24
  run: python3 .github/tools/deploy_to_space.py --branch_name="${{ github.ref_name }}" --user_token="${{ secrets.HF_TOKEN }}"
 
20
  uses: actions/checkout@v4
21
  with:
22
  fetch-depth: '0'
23
+ - name: Update Repo README.md
24
+ run: |
25
+ python3 .github/tools/generate_readme.py > README.md
26
+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
27
+ git config --global user.name "GitHub Actions[bot]"
28
+ git add ./README.md
29
+ if [[ `git status --porcelain` ]]; then
30
+ git commit -m "[skip ci] update README.md"
31
+ fi
32
  - name: Run deploy tool
33
  run: python3 .github/tools/deploy_to_space.py --branch_name="${{ github.ref_name }}" --user_token="${{ secrets.HF_TOKEN }}"