sayakpaul HF staff commited on
Commit
434a537
1 Parent(s): 6b34e0a

fix: hub push.

Browse files
Files changed (1) hide show
  1. main.py +9 -6
main.py CHANGED
@@ -2,7 +2,7 @@ from typing import List
2
 
3
  import gradio as gr
4
  import tensorflow as tf
5
- from huggingface_hub import Repository
6
 
7
  from utils import benchmark, convert_to_trt
8
 
@@ -36,11 +36,14 @@ def push_to_hub(hf_token: str, push_dir: str) -> str:
36
  if hf_token == "":
37
  return "### No HF token provided. Model won't be pushed."
38
  else:
39
- repo = Repository(local_dir=push_dir, token=hf_token)
40
- commit_url = repo.push_to_hub()
41
- return f"### Model successfully pushed: [{commit_url}]({commit_url})"
42
- except:
43
- return f"### {hf_token == ''}."
 
 
 
44
 
45
 
46
  def post_optimization(list_of_strs: List[str]) -> str:
 
2
 
3
  import gradio as gr
4
  import tensorflow as tf
5
+ from huggingface_hub import HfApi, Repository, create_repo
6
 
7
  from utils import benchmark, convert_to_trt
8
 
 
36
  if hf_token == "":
37
  return "### No HF token provided. Model won't be pushed."
38
  else:
39
+ hf_api = HfApi(token=hf_token)
40
+ user = hf_api.whoami()["name"]
41
+ repo_id = f"{user}/{push_dir}"
42
+ _ = create_repo(repo_id=repo_id, token=hf_token)
43
+ url = hf_api.upload_folder(folder_path=push_dir, repo_id=repo_id)
44
+ return f"### Model successfully pushed: [{url}]({url})"
45
+ except Exception as e:
46
+ return f"### {e}"
47
 
48
 
49
  def post_optimization(list_of_strs: List[str]) -> str: