CarlosMalaga commited on
Commit
b866469
1 Parent(s): b1a53b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -1
app.py CHANGED
@@ -246,11 +246,30 @@ def set_intro(css):
246
  # "[Riccardo Orlando](https://riccorl.github.io), [Simone Conia](https://c-simone.github.io/), "
247
  # "[Stefano Faralli](https://corsidilaurea.uniroma1.it/it/users/stefanofaralliuniroma1it), and [Roberto Navigli](https://www.diag.uniroma1.it/navigli/)."
248
  # )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
 
250
 
251
  def write_candidates_to_file(text, candidates, selected_candidates):
252
  logger.info(f"Text: {text}\tCandidates: {str(candidates)}\tSelected Candidates: {str(selected_candidates)}\n")
253
-
 
 
 
254
 
255
  def run_client():
256
  with open(Path(__file__).parent / "style.css") as f:
 
246
  # "[Riccardo Orlando](https://riccorl.github.io), [Simone Conia](https://c-simone.github.io/), "
247
  # "[Stefano Faralli](https://corsidilaurea.uniroma1.it/it/users/stefanofaralliuniroma1it), and [Roberto Navigli](https://www.diag.uniroma1.it/navigli/)."
248
  # )
249
+
250
+ from datetime import datetime
251
+ from pathlib import Path
252
+ from huggingface_hub import CommitScheduler
253
+ from uuid import uuid4
254
+
255
+ JSON_DATASET_DIR.mkdir(parents=True, exist_ok=True)
256
+ JSON_DATASET_DIR = Path("json_dataset")
257
+ JSON_DATASET_PATH = JSON_DATASET_DIR / f"train-{uuid4()}.json"
258
+
259
+ scheduler = CommitScheduler(
260
+ repo_id="example-space-to-dataset-json",
261
+ repo_type="dataset",
262
+ folder_path=JSON_DATASET_DIR,
263
+ path_in_repo="data",
264
+ )
265
 
266
 
267
  def write_candidates_to_file(text, candidates, selected_candidates):
268
  logger.info(f"Text: {text}\tCandidates: {str(candidates)}\tSelected Candidates: {str(selected_candidates)}\n")
269
+ with scheduler.lock:
270
+ with JSON_DATASET_PATH.open("a") as f:
271
+ json.dump({"text": text, "Candidates": [candidate for candidate in candidates], "Selected Candidates": [candidate for candidate in selected_candidates], "datetime": datetime.now().isoformat()}, f)
272
+ f.write("\n")
273
 
274
  def run_client():
275
  with open(Path(__file__).parent / "style.css") as f: