elibrowne commited on
Commit
895a686
1 Parent(s): e7c52d7

Code for saving data?

Browse files
Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -1,5 +1,32 @@
1
  import gradio as gr
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  # VARIABLES: will eventually be loaded with JSON from a dataset
4
 
5
  question_text = """
@@ -44,7 +71,7 @@ with gr.Blocks() as user_eval:
44
  def next(eval_1, eval_2 = 0):
45
  print(eval_1 + eval_2)
46
 
47
- btn.click(fn = next, inputs = [eval_1, eval_2])
48
 
49
  # Question and answering dynamics
50
  with gr.Row() as question:
 
1
  import gradio as gr
2
 
3
+ # These libraries are used in loading and storing persistent data
4
+ import json
5
+ from datetime import datetime
6
+ from pathlib import Path
7
+ from uuid import uuid4
8
+ from huggingface_hub import CommitScheduler
9
+
10
+ # PERSISTENT DATA STORAGE: these are used to upload user responses to a dataset
11
+
12
+ JSON_DATASET_DIR = Path("json_dataset")
13
+ JSON_DATASET_DIR.mkdir(parents=True, exist_ok=True)
14
+
15
+ JSON_DATASET_PATH = JSON_DATASET_DIR / f"train-{uuid4()}.json"
16
+
17
+ scheduler = CommitScheduler(
18
+ repo_id="ebrowne/test-data",
19
+ repo_type="dataset",
20
+ folder_path=JSON_DATASET_DIR,
21
+ path_in_repo="data",
22
+ )
23
+
24
+ def save_json(score1, score2):
25
+ with scheduler.lock:
26
+ with JSON_DATASET_PATH.open("a") as f:
27
+ json.dump({"relevance": score1, "novelty": score2, "datetime": datetime.now().isoformat()}, f)
28
+ f.write("\n")
29
+
30
  # VARIABLES: will eventually be loaded with JSON from a dataset
31
 
32
  question_text = """
 
71
  def next(eval_1, eval_2 = 0):
72
  print(eval_1 + eval_2)
73
 
74
+ btn.click(fn = save_json, inputs = [eval_1, eval_2])
75
 
76
  # Question and answering dynamics
77
  with gr.Row() as question: