julien-c HF staff commited on
Commit
88775d1
1 Parent(s): 8a44566
Files changed (1) hide show
  1. app.py +31 -1
app.py CHANGED
@@ -1,7 +1,22 @@
 
 
 
 
1
  import gradio as gr
2
 
3
  from convert import convert
4
- from huggingface_hub import HfApi
 
 
 
 
 
 
 
 
 
 
 
5
 
6
 
7
  def run(token: str, model_id: str) -> str:
@@ -14,6 +29,21 @@ def run(token: str, model_id: str) -> str:
14
  try:
15
  api = HfApi(token=token)
16
  commit_info = convert(api=api, model_id=model_id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  return f"""
18
  ### Success 🔥
19
 
 
1
+ import csv
2
+ import datetime
3
+ import os
4
+ from typing import Optional
5
  import gradio as gr
6
 
7
  from convert import convert
8
+ from huggingface_hub import HfApi, Repository
9
+
10
+
11
+ DATASET_REPO_URL = "https://huggingface.co/datasets/safetensors/conversions"
12
+ DATA_FILENAME = "data.csv"
13
+ DATA_FILE = os.path.join("data", DATA_FILENAME)
14
+
15
+ HF_TOKEN = os.environ.get("HF_TOKEN")
16
+
17
+ repo: Optional[Repository] = None
18
+ if HF_TOKEN:
19
+ repo = Repository(local_dir="data", clone_from=DATASET_REPO_URL, token=HF_TOKEN)
20
 
21
 
22
  def run(token: str, model_id: str) -> str:
 
29
  try:
30
  api = HfApi(token=token)
31
  commit_info = convert(api=api, model_id=model_id)
32
+
33
+ # save in a private dataset:
34
+ repo.git_pull(rebase=True)
35
+ with open(DATA_FILE, "a") as csvfile:
36
+ writer = csv.DictWriter(csvfile, fieldnames=["model_id", "pr_url", "time"])
37
+ writer.writerow(
38
+ {
39
+ "model_id": model_id,
40
+ "pr_url": commit_info.pr_url,
41
+ "time": str(datetime.now()),
42
+ }
43
+ )
44
+ commit_url = repo.push_to_hub()
45
+ print("[dataset]", commit_url)
46
+
47
  return f"""
48
  ### Success 🔥
49