Spaces:
Runtime error
Runtime error
add revision textbox
Browse files- .gitignore +1 -0
- app.py +12 -10
- revise_feedback_jsons.py +28 -0
.gitignore
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
app_ref.py
|
|
|
|
|
|
| 1 |
app_ref.py
|
| 2 |
+
DemoFeedback/
|
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
-
from datasets import load_dataset
|
| 4 |
import json
|
| 5 |
import os
|
| 6 |
import uuid
|
|
@@ -23,10 +23,10 @@ import time
|
|
| 23 |
|
| 24 |
truth_data = load_dataset("commonsense-index-dev/commonsense-candidates", "iter7-0520", split="train")
|
| 25 |
|
| 26 |
-
logs = load_dataset("commonsense-index-dev/DemoFeedback", split="train")
|
| 27 |
-
|
| 28 |
LAST_LOG_UPDATE = time.time()
|
| 29 |
|
|
|
|
|
|
|
| 30 |
qa_dataset = {}
|
| 31 |
for item in truth_data:
|
| 32 |
qa_dataset[item["id"]] = {
|
|
@@ -40,8 +40,8 @@ for item in truth_data:
|
|
| 40 |
def update_logs():
|
| 41 |
global LAST_LOG_UPDATE
|
| 42 |
global logs
|
| 43 |
-
if time.time() - LAST_LOG_UPDATE >
|
| 44 |
-
# update logs for every
|
| 45 |
logs = load_dataset("commonsense-index-dev/DemoFeedback", split="train")
|
| 46 |
LAST_LOG_UPDATE = time.time()
|
| 47 |
|
|
@@ -105,7 +105,7 @@ def show_buttons(choices_markdown):
|
|
| 105 |
return visibility
|
| 106 |
|
| 107 |
|
| 108 |
-
def submit_feedback(question_id, user_reason, example_quality, user_name_text):
|
| 109 |
if "N/A" in question_id or "N/A" in example_quality:
|
| 110 |
# send a message to the user to sample an example and select a choice first
|
| 111 |
return {
|
|
@@ -118,6 +118,7 @@ def submit_feedback(question_id, user_reason, example_quality, user_name_text):
|
|
| 118 |
"question_id": question_id,
|
| 119 |
"user_name": user_name_text,
|
| 120 |
"user_reason": user_reason,
|
|
|
|
| 121 |
"example_quality": example_quality,
|
| 122 |
}
|
| 123 |
jsonl_str = json.dumps(feedback_item)
|
|
@@ -146,7 +147,7 @@ def submit_feedback(question_id, user_reason, example_quality, user_name_text):
|
|
| 146 |
}
|
| 147 |
|
| 148 |
def refresh_feedback(question_id):
|
| 149 |
-
return gr.update(value="", visible=True), gr.update(value="", visible=True), gr.update(value="", visible=True)
|
| 150 |
|
| 151 |
with gr.Blocks() as app:
|
| 152 |
gr.Markdown("# Commonsense Index Data Viewer")
|
|
@@ -166,7 +167,8 @@ with gr.Blocks() as app:
|
|
| 166 |
|
| 167 |
with gr.Row():
|
| 168 |
with gr.Column(scale=2):
|
| 169 |
-
reason_textbox = gr.Textbox(label="Reason", placeholder="Please talk why the correct answer is correct and why the others are wrong. If you think this is a bad example, please explain too.", type="text", elem_classes="", max_lines=5, lines=
|
|
|
|
| 170 |
with gr.Column():
|
| 171 |
example_quality = gr.Radio(label="Quality", choices=["Good", "Bad"], interactive=True, visible=True)
|
| 172 |
user_name = gr.Textbox(label="Your username", placeholder="Your username", type="text", elem_classes="", max_lines=1, show_copy_button=False, visible=True, interactive=True, show_label=False)
|
|
@@ -175,8 +177,8 @@ with gr.Blocks() as app:
|
|
| 175 |
|
| 176 |
random_button.click(fn=load_question, inputs=[user_name], outputs=[question_id, question_display, choices_markdown, result_display, reasoning_display, example_quality, submit_button])
|
| 177 |
choices_markdown.change(fn=show_buttons, inputs=choices_markdown, outputs=choice_buttons)
|
| 178 |
-
question_id.change(fn=refresh_feedback, inputs=[question_id], outputs=[reason_textbox, example_quality])
|
| 179 |
-
submit_button.click(fn=submit_feedback, inputs=[question_id, reason_textbox, example_quality, user_name], outputs=[submit_button])
|
| 180 |
for i, button in enumerate(choice_buttons):
|
| 181 |
button.click(fn=check_answer, inputs=[question_id, button, reasoning_display], outputs=result_display)
|
| 182 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
+
from datasets import load_dataset, Features, Value
|
| 4 |
import json
|
| 5 |
import os
|
| 6 |
import uuid
|
|
|
|
| 23 |
|
| 24 |
truth_data = load_dataset("commonsense-index-dev/commonsense-candidates", "iter7-0520", split="train")
|
| 25 |
|
|
|
|
|
|
|
| 26 |
LAST_LOG_UPDATE = time.time()
|
| 27 |
|
| 28 |
+
logs = None
|
| 29 |
+
|
| 30 |
qa_dataset = {}
|
| 31 |
for item in truth_data:
|
| 32 |
qa_dataset[item["id"]] = {
|
|
|
|
| 40 |
def update_logs():
|
| 41 |
global LAST_LOG_UPDATE
|
| 42 |
global logs
|
| 43 |
+
if logs is None or time.time() - LAST_LOG_UPDATE > 3600:
|
| 44 |
+
# update logs for every 60 minutes
|
| 45 |
logs = load_dataset("commonsense-index-dev/DemoFeedback", split="train")
|
| 46 |
LAST_LOG_UPDATE = time.time()
|
| 47 |
|
|
|
|
| 105 |
return visibility
|
| 106 |
|
| 107 |
|
| 108 |
+
def submit_feedback(question_id, user_reason, user_revision, example_quality, user_name_text):
|
| 109 |
if "N/A" in question_id or "N/A" in example_quality:
|
| 110 |
# send a message to the user to sample an example and select a choice first
|
| 111 |
return {
|
|
|
|
| 118 |
"question_id": question_id,
|
| 119 |
"user_name": user_name_text,
|
| 120 |
"user_reason": user_reason,
|
| 121 |
+
"revision": user_revision,
|
| 122 |
"example_quality": example_quality,
|
| 123 |
}
|
| 124 |
jsonl_str = json.dumps(feedback_item)
|
|
|
|
| 147 |
}
|
| 148 |
|
| 149 |
def refresh_feedback(question_id):
|
| 150 |
+
return gr.update(value="", visible=True), gr.update(value="", visible=True), gr.update(value="", visible=True), gr.update(value="", visible=True)
|
| 151 |
|
| 152 |
with gr.Blocks() as app:
|
| 153 |
gr.Markdown("# Commonsense Index Data Viewer")
|
|
|
|
| 167 |
|
| 168 |
with gr.Row():
|
| 169 |
with gr.Column(scale=2):
|
| 170 |
+
reason_textbox = gr.Textbox(label="Reason", placeholder="Please talk why the correct answer is correct and why the others are wrong. If you think this is a bad example, please explain too.", type="text", elem_classes="", max_lines=5, lines=3, show_copy_button=False, visible=True, scale=4, interactive=True)
|
| 171 |
+
revision_textbox = gr.Textbox(label="Revision", placeholder="Please suggest a revision to the question.", type="text", elem_classes="", max_lines=5, lines=3, show_copy_button=False, visible=True, scale=4, interactive=True)
|
| 172 |
with gr.Column():
|
| 173 |
example_quality = gr.Radio(label="Quality", choices=["Good", "Bad"], interactive=True, visible=True)
|
| 174 |
user_name = gr.Textbox(label="Your username", placeholder="Your username", type="text", elem_classes="", max_lines=1, show_copy_button=False, visible=True, interactive=True, show_label=False)
|
|
|
|
| 177 |
|
| 178 |
random_button.click(fn=load_question, inputs=[user_name], outputs=[question_id, question_display, choices_markdown, result_display, reasoning_display, example_quality, submit_button])
|
| 179 |
choices_markdown.change(fn=show_buttons, inputs=choices_markdown, outputs=choice_buttons)
|
| 180 |
+
question_id.change(fn=refresh_feedback, inputs=[question_id], outputs=[reason_textbox, revision_textbox, example_quality])
|
| 181 |
+
submit_button.click(fn=submit_feedback, inputs=[question_id, reason_textbox, revision_textbox, example_quality, user_name], outputs=[submit_button])
|
| 182 |
for i, button in enumerate(choice_buttons):
|
| 183 |
button.click(fn=check_answer, inputs=[question_id, button, reasoning_display], outputs=result_display)
|
| 184 |
|
revise_feedback_jsons.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Directory containing the JSON files
|
| 5 |
+
directory = 'DemoFeedback'
|
| 6 |
+
|
| 7 |
+
# Check each file in the directory
|
| 8 |
+
for filename in os.listdir(directory):
|
| 9 |
+
if filename.endswith('.json'):
|
| 10 |
+
file_path = os.path.join(directory, filename)
|
| 11 |
+
|
| 12 |
+
# Open and load the JSON file
|
| 13 |
+
with open(file_path, 'r+') as file:
|
| 14 |
+
data = json.load(file)
|
| 15 |
+
|
| 16 |
+
# Check if 'revision' field is missing
|
| 17 |
+
if 'revision' not in data:
|
| 18 |
+
data['revision'] = 'N/A'
|
| 19 |
+
|
| 20 |
+
# Move the file pointer to the beginning of the file
|
| 21 |
+
file.seek(0)
|
| 22 |
+
# Write the updated data
|
| 23 |
+
json.dump(data, file, indent=4)
|
| 24 |
+
# Truncate the file to the new data length
|
| 25 |
+
file.truncate()
|
| 26 |
+
print(f"Updated file: {filename}")
|
| 27 |
+
|
| 28 |
+
print("Files have been checked and updated as needed.")
|