davda54 commited on
Commit
d15dca0
·
verified ·
1 Parent(s): 7e47a62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -40,6 +40,30 @@ LANGUAGE_IDS = {
40
  }
41
 
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  class BatchStreamer(TextIteratorStreamer):
44
  def put(self, value):
45
  print(value.shape)
@@ -127,6 +151,8 @@ def translate(source, source_language, target_language):
127
 
128
  for new_text in streamer:
129
  yield new_text.strip()
 
 
130
  return new_text.strip()
131
 
132
 
 
40
  }
41
 
42
 
43
+ STATS_REPO = "https://huggingface.co/datasets/ltg/usage_statistics"
44
+ HF_TOKEN = os.environ.get("HF_TOKEN")
45
+
46
+
47
+ # log the timestamp of the query
48
+ def add_anonymous_usage_log(path):
49
+ global dataset
50
+ try:
51
+ with open(path, "a") as f:
52
+ line = json.dumps(str(datetime.now()), ensure_ascii=False)
53
+ f.write(f"{line}\n")
54
+ dataset.push_to_hub()
55
+
56
+ except:
57
+ shutil.rmtree("data")
58
+ dataset = Repository(
59
+ local_dir="data", clone_from=LOGS_REPO, use_auth_token=HF_TOKEN
60
+ )
61
+ with open(path, "a") as f:
62
+ line = json.dumps(str(datetime.now()), ensure_ascii=False)
63
+ f.write(f"{line}\n")
64
+ dataset.push_to_hub()
65
+
66
+
67
  class BatchStreamer(TextIteratorStreamer):
68
  def put(self, value):
69
  print(value.shape)
 
151
 
152
  for new_text in streamer:
153
  yield new_text.strip()
154
+
155
+ add_anonymous_usage_log("data/no-en-translation.jsonl")
156
  return new_text.strip()
157
 
158