Spaces:
Running
Running
Nils Durner
commited on
Commit
·
c81fd70
1
Parent(s):
5a15b7d
add system prompt to history export
Browse files
app.py
CHANGED
@@ -112,10 +112,13 @@ def import_history(history, file):
|
|
112 |
else:
|
113 |
content = str(content)
|
114 |
|
115 |
-
# Deserialize the JSON content
|
116 |
-
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
119 |
|
120 |
with gr.Blocks() as demo:
|
121 |
gr.Markdown("# Amazon™️ Bedrock™️ Chat™️ (Nils' Version™️) feat. Mistral™️ AI & Anthropic™️ Claude™️")
|
@@ -218,13 +221,14 @@ with gr.Blocks() as demo:
|
|
218 |
with gr.Accordion("Import/Export", open = False):
|
219 |
import_button = gr.UploadButton("History Import")
|
220 |
export_button = gr.Button("History Export")
|
221 |
-
export_button.click(lambda: None, [chatbot], js="""
|
222 |
-
(chat_history) => {
|
223 |
-
|
224 |
-
|
225 |
-
|
|
|
|
|
226 |
const blob = new Blob([history_json], {type: 'application/json'});
|
227 |
-
// Create a download link
|
228 |
const url = URL.createObjectURL(blob);
|
229 |
const a = document.createElement('a');
|
230 |
a.href = url;
|
@@ -264,7 +268,7 @@ with gr.Blocks() as demo:
|
|
264 |
}
|
265 |
}
|
266 |
""")
|
267 |
-
import_button.upload(import_history, inputs=[chatbot, import_button], outputs=[chatbot])
|
268 |
|
269 |
txt_msg = txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
|
270 |
bot, [txt, chatbot, aws_access, aws_secret, aws_token, system_prompt, temp, max_tokens, model, region], [txt, chatbot],
|
|
|
112 |
else:
|
113 |
content = str(content)
|
114 |
|
115 |
+
# Deserialize the JSON content
|
116 |
+
import_data = json.loads(content)
|
117 |
+
|
118 |
+
new_history = import_data.get('history', history) # Use existing history if not provided
|
119 |
+
new_system_prompt = import_data.get('system_prompt', '') # Default to empty if not provided
|
120 |
+
|
121 |
+
return new_history, new_system_prompt
|
122 |
|
123 |
with gr.Blocks() as demo:
|
124 |
gr.Markdown("# Amazon™️ Bedrock™️ Chat™️ (Nils' Version™️) feat. Mistral™️ AI & Anthropic™️ Claude™️")
|
|
|
221 |
with gr.Accordion("Import/Export", open = False):
|
222 |
import_button = gr.UploadButton("History Import")
|
223 |
export_button = gr.Button("History Export")
|
224 |
+
export_button.click(lambda: None, [chatbot, system_prompt], js="""
|
225 |
+
(chat_history, system_prompt) => {
|
226 |
+
const export_data = {
|
227 |
+
history: chat_history,
|
228 |
+
system_prompt: system_prompt
|
229 |
+
};
|
230 |
+
const history_json = JSON.stringify(export_data);
|
231 |
const blob = new Blob([history_json], {type: 'application/json'});
|
|
|
232 |
const url = URL.createObjectURL(blob);
|
233 |
const a = document.createElement('a');
|
234 |
a.href = url;
|
|
|
268 |
}
|
269 |
}
|
270 |
""")
|
271 |
+
import_button.upload(import_history, inputs=[chatbot, import_button], outputs=[chatbot, system_prompt])
|
272 |
|
273 |
txt_msg = txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
|
274 |
bot, [txt, chatbot, aws_access, aws_secret, aws_token, system_prompt, temp, max_tokens, model, region], [txt, chatbot],
|