|
import json |
|
session_state, |
|
consent_storage, |
|
], |
|
outputs=[chatbot_display], |
|
) |
|
.then(fn=set_interactive, inputs=[], outputs=[sandbox_html]) |
|
.then(fn=reactivate_stop_btn, outputs=[stop_btn]) |
|
) |
|
|
|
def interrupt_agent(session_state): |
|
if not session_state["agent"].interrupt_switch: |
|
session_state["agent"].interrupt() |
|
print("Stopping agent...") |
|
return gr.Button("Stopping agent... (could take time)", variant="secondary") |
|
else: |
|
return gr.Button("Stop the agent!", variant="huggingface") |
|
|
|
stop_btn.click(fn=interrupt_agent, inputs=[session_state], outputs=[stop_btn]) |
|
|
|
def upload_interaction_logs(session: gr.Request): |
|
data_dirs = [] |
|
for interaction_id in list( |
|
INTERACTION_IDS_PER_SESSION_HASH[session.session_hash].keys() |
|
): |
|
data_dir = os.path.join(TMP_DIR, interaction_id) |
|
if os.path.exists(data_dir): |
|
data_dirs.append(data_dir) |
|
del INTERACTION_IDS_PER_SESSION_HASH[session.session_hash][ |
|
interaction_id |
|
] |
|
|
|
upload_to_hf_and_remove(data_dirs) |
|
|
|
demo.load( |
|
fn=lambda: True, |
|
outputs=[is_interactive], |
|
).then( |
|
fn=initialize_session, |
|
inputs=[is_interactive], |
|
outputs=[sandbox_html], |
|
) |
|
|
|
demo.unload(fn=upload_interaction_logs) |
|
|
|
|
|
if __name__ == "__main__": |
|
Timer(60, cleanup_sandboxes).start() |
|
demo.launch() |
|
|