badaoui commited on
Commit
4ab1173
·
1 Parent(s): 538326f
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -88,30 +88,31 @@ def neuron_export(model_id: str, task: str, oauth_token: gr.OAuthToken) -> str:
88
  try:
89
  api = HfApi(token=oauth_token.token)
90
 
91
- error, result_info = convert(api=api, model_id=model_id, task=task, token=oauth_token.token)
92
  if error != "0":
93
  return error
94
 
95
- print("[result_info]", result_info)
96
 
97
- # Save in a private dataset if repo initialized
98
  if repo is not None:
99
  repo.git_pull(rebase=True)
100
  with open(os.path.join(DATADIR, DATA_FILE), "a") as csvfile:
101
  writer = csv.DictWriter(
102
- csvfile, fieldnames=["model_id", "cache_info", "time"]
103
  )
104
  writer.writerow(
105
  {
106
  "model_id": model_id,
107
- "cache_info": str(result_info),
108
  "time": str(datetime.now()),
109
  }
110
  )
111
  commit_url = repo.push_to_hub()
112
  print("[dataset]", commit_url)
113
 
114
- return f"#### Success 🔥 Yay! This model was successfully compiled and cached! The compilation artifacts have been synchronized to the optimum-neuron cache repository. You can now use this model with optimum-neuron and benefit from faster loading times. Model: {model_id}, Task: {task}"
 
115
 
116
  except Exception as e:
117
  return f"#### Error: {e}"
 
88
  try:
89
  api = HfApi(token=oauth_token.token)
90
 
91
+ error, commit_info = convert(api=api, model_id=model_id, task=task, token=oauth_token.token)
92
  if error != "0":
93
  return error
94
 
95
+ print("[commit_info]", commit_info)
96
 
97
+ # Save in a private dataset if repo initialized
98
  if repo is not None:
99
  repo.git_pull(rebase=True)
100
  with open(os.path.join(DATADIR, DATA_FILE), "a") as csvfile:
101
  writer = csv.DictWriter(
102
+ csvfile, fieldnames=["model_id", "pr_url", "time"]
103
  )
104
  writer.writerow(
105
  {
106
  "model_id": model_id,
107
+ "pr_url": commit_info.pr_url,
108
  "time": str(datetime.now()),
109
  }
110
  )
111
  commit_url = repo.push_to_hub()
112
  print("[dataset]", commit_url)
113
 
114
+ pr_revision = commit_info.pr_revision.replace("/", "%2F")
115
+ return f"#### Success 🔥 Yay! This model was successfully exported and a PR was opened using your token: [{commit_info.pr_url}]({commit_info.pr_url}). If you would like to use the exported model without waiting for the PR to be approved, head to https://huggingface.co/{model_id}/tree/{pr_revision}"
116
 
117
  except Exception as e:
118
  return f"#### Error: {e}"