Spaces:
Build error
Build error
Nils Durner commited on
Commit ·
4ec2d84
1
Parent(s): 43b6937
add System Prompt to history export
Browse files
app.py
CHANGED
|
@@ -206,10 +206,18 @@ def import_history(history, file):
|
|
| 206 |
else:
|
| 207 |
content = str(content)
|
| 208 |
|
| 209 |
-
# Deserialize the JSON content
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
with gr.Blocks() as demo:
|
| 215 |
gr.Markdown("# OAI Chat (Nils' Version™️)")
|
|
@@ -310,13 +318,14 @@ with gr.Blocks() as demo:
|
|
| 310 |
with gr.Accordion("Import/Export", open = False):
|
| 311 |
import_button = gr.UploadButton("History Import")
|
| 312 |
export_button = gr.Button("History Export")
|
| 313 |
-
export_button.click(lambda: None, [chatbot], js="""
|
| 314 |
-
(chat_history) => {
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
|
|
|
|
|
|
| 318 |
const blob = new Blob([history_json], {type: 'application/json'});
|
| 319 |
-
// Create a download link
|
| 320 |
const url = URL.createObjectURL(blob);
|
| 321 |
const a = document.createElement('a');
|
| 322 |
a.href = url;
|
|
@@ -356,6 +365,6 @@ with gr.Blocks() as demo:
|
|
| 356 |
}
|
| 357 |
}
|
| 358 |
""")
|
| 359 |
-
import_button.upload(import_history, inputs=[chatbot, import_button], outputs=[chatbot])
|
| 360 |
|
| 361 |
demo.queue().launch()
|
|
|
|
| 206 |
else:
|
| 207 |
content = str(content)
|
| 208 |
|
| 209 |
+
# Deserialize the JSON content
|
| 210 |
+
import_data = json.loads(content)
|
| 211 |
+
|
| 212 |
+
# Check if 'history' key exists for backward compatibility
|
| 213 |
+
if 'history' in import_data:
|
| 214 |
+
history = import_data['history']
|
| 215 |
+
system_prompt.value = import_data.get('system_prompt', '') # Set default if not present
|
| 216 |
+
else:
|
| 217 |
+
# Assume it's an old format with only history data
|
| 218 |
+
history = import_data
|
| 219 |
+
|
| 220 |
+
return history, system_prompt.value # Return system prompt value to be set in the UI
|
| 221 |
|
| 222 |
with gr.Blocks() as demo:
|
| 223 |
gr.Markdown("# OAI Chat (Nils' Version™️)")
|
|
|
|
| 318 |
with gr.Accordion("Import/Export", open = False):
|
| 319 |
import_button = gr.UploadButton("History Import")
|
| 320 |
export_button = gr.Button("History Export")
|
| 321 |
+
export_button.click(lambda: None, [chatbot, system_prompt], js="""
|
| 322 |
+
(chat_history, system_prompt) => {
|
| 323 |
+
const export_data = {
|
| 324 |
+
history: chat_history,
|
| 325 |
+
system_prompt: system_prompt
|
| 326 |
+
};
|
| 327 |
+
const history_json = JSON.stringify(export_data);
|
| 328 |
const blob = new Blob([history_json], {type: 'application/json'});
|
|
|
|
| 329 |
const url = URL.createObjectURL(blob);
|
| 330 |
const a = document.createElement('a');
|
| 331 |
a.href = url;
|
|
|
|
| 365 |
}
|
| 366 |
}
|
| 367 |
""")
|
| 368 |
+
import_button.upload(import_history, inputs=[chatbot, import_button], outputs=[chatbot, system_prompt])
|
| 369 |
|
| 370 |
demo.queue().launch()
|