Skip to content

Commit

Permalink
sync env
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Sep 8, 2023
1 parent 6022559 commit 3bc84a1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore cache
id: file-restore
uses: actions/cache/restore@v3
with:
path: |
sync/endpoint.txt
key: endpoint
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
- name: run
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: python sync.py
HF_TOKEN: ${{ secrets.HF_TOKEN }}
ENDPOINTS: ${{ vars.ENDPOINTS }}
run: cd sync && cat endpoint.txt && pip install huggingface_hub && python sync.py
- name: Save cache
id: file-save
uses: actions/cache/save@v3
with:
path: |
sync/endpoint.txt
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
11 changes: 0 additions & 11 deletions sync.py

This file was deleted.

2 changes: 2 additions & 0 deletions sync/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/endpoint.txt
/.env
File renamed without changes.
25 changes: 25 additions & 0 deletions sync/sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from huggingface_hub import HfApi, list_models
import os

hf_api = HfApi(
endpoint="https://huggingface.co", # Can be a Private Hub endpoint.
token=os.environ.get('HF_TOKEN'), # Token is not persisted on the machine.
)
ENDPOINTS = os.environ.get('ENDPOINTS')
file = 'endpoint.txt'
endpoints = ENDPOINTS.split('\n')
endpoint = endpoints[0].strip()
try:
with open(file,"r") as f:
content=f.read().strip()
endpoint = endpoints[1] if content == endpoints[0] else endpoints[0]
f.close()
except IOError:
print("File not accessible")
with open(file, "w") as wf:
wf.write(endpoint)
wf.close()

print('new endpoint', endpoint)
hf_api.add_space_secret('hf4all/bingo2', 'ENDPOINT', endpoint.strip())

0 comments on commit 3bc84a1

Please sign in to comment.