sheonhan commited on
Commit
45abd0a
1 Parent(s): b992def

create files hourly

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -32,10 +32,13 @@ if HF_TOKEN:
32
  repo.git_pull()
33
 
34
 
35
- def save_inputs_and_outputs(inputs, outputs, generate_kwargs):
 
 
 
36
  if repo is not None:
37
  repo.git_pull(rebase=True)
38
- with open(os.path.join("data", "prompts.jsonl"), "a") as f:
39
  json.dump({"inputs": inputs, "outputs": outputs, "generate_kwargs": generate_kwargs}, f, ensure_ascii=False)
40
  f.write("\n")
41
  repo.push_to_hub()
@@ -146,8 +149,10 @@ def generate(
146
 
147
  if HF_TOKEN and do_save:
148
  try:
149
- print("Pushing prompt and completion to the Hub")
150
- save_inputs_and_outputs(prompt, output, generate_kwargs)
 
 
151
  except Exception as e:
152
  print(e)
153
 
 
32
  repo.git_pull()
33
 
34
 
35
+ def save_inputs_and_outputs(now, inputs, outputs, generate_kwargs):
36
+ current_hour = now.strftime("%Y-%m-%d_%H")
37
+ file_name = f"prompts_{current_hour}.jsonl"
38
+
39
  if repo is not None:
40
  repo.git_pull(rebase=True)
41
+ with open(os.path.join("data", file_name), "a") as f:
42
  json.dump({"inputs": inputs, "outputs": outputs, "generate_kwargs": generate_kwargs}, f, ensure_ascii=False)
43
  f.write("\n")
44
  repo.push_to_hub()
 
149
 
150
  if HF_TOKEN and do_save:
151
  try:
152
+ now = datetime.datetime.now()
153
+ current_time = now.strftime("%Y-%m-%d %H:%M:%S")
154
+ print(f"[{current_time}] Pushing prompt and completion to the Hub")
155
+ save_inputs_and_outputs(now, prompt, output, generate_kwargs)
156
  except Exception as e:
157
  print(e)
158