vpcom commited on
Commit
2ba7b49
1 Parent(s): 9caa5c6

feat: use git push; fix: use environment variables

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -7,8 +7,13 @@ import gradio as gr
7
  from huggingface_hub import Repository, InferenceClient
8
 
9
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
10
- API_URL = "https://api-inference.huggingface.co/models/DataAnalyticsLab/PersianGPT-FT-Grover"
 
 
11
  BOT_NAME = "PersianGPT-FT"
 
 
 
12
 
13
  stop_sequences = [] #["<|endoftext|>",">"]
14
 
@@ -25,6 +30,21 @@ client = InferenceClient(
25
  headers={"Authorization": f"Bearer {HF_TOKEN}"},
26
  )
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  def vote(data: gr.LikeData):
29
  if data.liked:
30
  print("You upvoted this response: " + data.value)
 
7
  from huggingface_hub import Repository, InferenceClient
8
 
9
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
10
+ API_URL = os.environ.get("API_URL", None)
11
+ DATASET_REPO_URL = os.getenv("DATASET_REPO_URL")
12
+ FORCE_PUSH = os.getenv("FORCE_PUSH")
13
  BOT_NAME = "PersianGPT-FT"
14
+ PUSH_FREQUENCY = 60 # every minute
15
+
16
+ repo = Repository(local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=HF_TOKEN)
17
 
18
  stop_sequences = [] #["<|endoftext|>",">"]
19
 
 
30
  headers={"Authorization": f"Bearer {HF_TOKEN}"},
31
  )
32
 
33
+ def asynchronous_push(f_stop):
34
+ if repo.is_repo_clean():
35
+ print("Repo currently clean. Ignoring push_to_hub")
36
+ print(repo.huggingface_token)
37
+ else:
38
+ repo.git_add(auto_lfs_track=True)
39
+ repo.git_commit("Auto commit by space")
40
+ if FORCE_PUSH == "yes":
41
+ force_git_push(repo)
42
+ else:
43
+ repo.git_push()
44
+ if not f_stop.is_set():
45
+ # call again in 60 seconds
46
+ threading.Timer(PUSH_FREQUENCY, asynchronous_push, [f_stop]).start()
47
+
48
  def vote(data: gr.LikeData):
49
  if data.liked:
50
  print("You upvoted this response: " + data.value)