vpcom commited on
Commit
183a544
·
1 Parent(s): a5e860d

feat: record everything in data.json

Browse files
Files changed (1) hide show
  1. app.py +29 -6
app.py CHANGED
@@ -3,6 +3,7 @@ import os
3
  import shutil
4
  import requests
5
  import threading
 
6
 
7
  import gradio as gr
8
  from huggingface_hub import Repository, InferenceClient
@@ -51,12 +52,6 @@ def asynchronous_push(f_stop):
51
  f_stop = threading.Event()
52
  asynchronous_push(f_stop)
53
 
54
- def vote(data: gr.LikeData):
55
- if data.liked:
56
- print("You upvoted this response: " + data.value)
57
- else:
58
- print("You downvoted this response: " + data.value)
59
-
60
  def format_prompt(message, history, system_prompt):
61
  prompt = ""
62
  if system_prompt:
@@ -186,6 +181,34 @@ def evolve_text(x):
186
 
187
  return possible_generation
188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  with gr.Blocks(css=CSS) as demo:
190
  with gr.Row():
191
  with gr.Column():
 
3
  import shutil
4
  import requests
5
  import threading
6
+ import time
7
 
8
  import gradio as gr
9
  from huggingface_hub import Repository, InferenceClient
 
52
  f_stop = threading.Event()
53
  asynchronous_push(f_stop)
54
 
 
 
 
 
 
 
55
  def format_prompt(message, history, system_prompt):
56
  prompt = ""
57
  if system_prompt:
 
181
 
182
  return possible_generation
183
 
184
+ def vote(data: gr.LikeData):
185
+ if data.liked:
186
+ print("You upvoted this response: " + data.value)
187
+ else:
188
+ print("You downvoted this response: " + data.value)
189
+
190
+ print(data)
191
+
192
+ with open(DATA_FILE, "a") as jsonlfile:
193
+ json_data = [
194
+ json.dumps(
195
+ {
196
+ "index": data.index,
197
+ "time_stamp": time.time(),
198
+ "prompt": "",
199
+ "history": "",
200
+ "system prompt": additional_inputs[0].value,
201
+ "temperature": additional_inputs[1].value,
202
+ "max_new_tokens": additional_inputs[2].value,
203
+ "top_p": additional_inputs[3].value,
204
+ "repetition_penalty": additional_inputs[4].value,
205
+ "response": data.value,
206
+ "label": data.liked,
207
+ }
208
+ )
209
+ ]
210
+ jsonlfile.write("\n".join(json_data) + "\n")
211
+
212
  with gr.Blocks(css=CSS) as demo:
213
  with gr.Row():
214
  with gr.Column():