Spaces:
Sleeping
Sleeping
Daniel Nichols
commited on
Commit
·
d672eb0
1
Parent(s):
4f8f6fb
add download button
Browse files- src/perfguru.py +12 -19
src/perfguru.py
CHANGED
@@ -78,8 +78,8 @@ def chat_with_llms(prompt, code_files, profile_file, profile_type):
|
|
78 |
vote_buttons = gr.Button(interactive=True), gr.Button(interactive=True), gr.Button(interactive=True), gr.Button(interactive=True)
|
79 |
yield c1 or gr.Textbox(), source1, formatted1, c2 or gr.Textbox(), source2, formatted2, *vote_buttons
|
80 |
|
81 |
-
def
|
82 |
-
|
83 |
"prompt": prompt,
|
84 |
"full_prompt1": full_prompt1,
|
85 |
"full_prompt2": full_prompt2,
|
@@ -92,21 +92,10 @@ def log_interaction(prompt, vote, response1, model1, formatter1, full_prompt1, r
|
|
92 |
"formatter2": formatter2,
|
93 |
"timestamp": datetime.datetime.now().isoformat()
|
94 |
}
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
if os.path.exists(log_file_path):
|
100 |
-
with open(log_file_path, "r") as log_file:
|
101 |
-
logs = json.load(log_file)
|
102 |
-
else:
|
103 |
-
logs = []
|
104 |
-
|
105 |
-
logs.append(interaction)
|
106 |
-
|
107 |
-
# Write updated logs to file
|
108 |
-
with open(log_file_path, "w") as log_file:
|
109 |
-
json.dump(logs, log_file, indent=4)
|
110 |
|
111 |
|
112 |
def handle_vote(prompt, vote, response1, source1, full_prompt1, response2, source2, full_prompt2):
|
@@ -115,9 +104,11 @@ def handle_vote(prompt, vote, response1, source1, full_prompt1, response2, sourc
|
|
115 |
|
116 |
label1_class = ["voted"] if vote == "Vote for Response 1" else []
|
117 |
label2_class = ["voted"] if vote == "Vote for Response 2" else []
|
|
|
118 |
|
119 |
-
|
120 |
return gr.Markdown(visible=True, elem_classes=label1_class), gr.Markdown(visible=True, elem_classes=label2_class), \
|
|
|
121 |
gr.Button(interactive=False), gr.Button(interactive=False), gr.Button(interactive=False), gr.Button(interactive=False)
|
122 |
|
123 |
# Define the Gradio interface
|
@@ -175,9 +166,11 @@ with gr.Blocks(css=".not-voted p { color: black; } .voted p { color: green; } .r
|
|
175 |
tie_button = gr.Button("Vote for Tie", interactive=False)
|
176 |
skip_button = gr.Button("Skip", interactive=False)
|
177 |
|
|
|
|
|
178 |
vote_btns = [vote1_button, vote2_button, tie_button, skip_button]
|
179 |
for btn in vote_btns:
|
180 |
-
btn.click(handle_vote, inputs=[prompt, btn, response1, source1, full_prompt1, response2, source2, full_prompt2], outputs=[source1, source2, *vote_btns])
|
181 |
|
182 |
# final chat button
|
183 |
chat_button.click(
|
|
|
78 |
vote_buttons = gr.Button(interactive=True), gr.Button(interactive=True), gr.Button(interactive=True), gr.Button(interactive=True)
|
79 |
yield c1 or gr.Textbox(), source1, formatted1, c2 or gr.Textbox(), source2, formatted2, *vote_buttons
|
80 |
|
81 |
+
def get_interaction_log(prompt, vote, response1, model1, formatter1, full_prompt1, response2, model2, formatter2, full_prompt2):
|
82 |
+
log = {
|
83 |
"prompt": prompt,
|
84 |
"full_prompt1": full_prompt1,
|
85 |
"full_prompt2": full_prompt2,
|
|
|
92 |
"formatter2": formatter2,
|
93 |
"timestamp": datetime.datetime.now().isoformat()
|
94 |
}
|
95 |
+
fpath = f"interaction_log_{datetime.datetime.now().isoformat()}.json"
|
96 |
+
with open(fpath, "w") as f:
|
97 |
+
json.dump(log, f, indent=2)
|
98 |
+
return fpath
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
|
101 |
def handle_vote(prompt, vote, response1, source1, full_prompt1, response2, source2, full_prompt2):
|
|
|
104 |
|
105 |
label1_class = ["voted"] if vote == "Vote for Response 1" else []
|
106 |
label2_class = ["voted"] if vote == "Vote for Response 2" else []
|
107 |
+
did_vote = vote != "Skip"
|
108 |
|
109 |
+
log_fpath = get_interaction_log(prompt, vote, response1, model1, formatter1, full_prompt1, response2, model2, formatter2, full_prompt2)
|
110 |
return gr.Markdown(visible=True, elem_classes=label1_class), gr.Markdown(visible=True, elem_classes=label2_class), \
|
111 |
+
gr.Button(interactive=did_vote, value=log_fpath), \
|
112 |
gr.Button(interactive=False), gr.Button(interactive=False), gr.Button(interactive=False), gr.Button(interactive=False)
|
113 |
|
114 |
# Define the Gradio interface
|
|
|
166 |
tie_button = gr.Button("Vote for Tie", interactive=False)
|
167 |
skip_button = gr.Button("Skip", interactive=False)
|
168 |
|
169 |
+
download_btn = gr.DownloadButton("Download Log", interactive=False)
|
170 |
+
|
171 |
vote_btns = [vote1_button, vote2_button, tie_button, skip_button]
|
172 |
for btn in vote_btns:
|
173 |
+
btn.click(handle_vote, inputs=[prompt, btn, response1, source1, full_prompt1, response2, source2, full_prompt2], outputs=[source1, source2, download_btn, *vote_btns])
|
174 |
|
175 |
# final chat button
|
176 |
chat_button.click(
|