How to persist Gradio state externally

Is there a way to persist Gradio’s gr.State() externally in a way that makes it work:

  1. across deploys
  2. across replicas
  3. across sessions

Our use case is launching a prototype chatbot for internal use, but the limitation on state being stored per-session in memory causes the following problems:

  • the app cannot have more than one replica running at a time, as if traffic goes to “the other instance”, it has no state and the chat is reset
  • whenever the app is deployed, state is reset for all users
  • whenever a user refreshes, state is reset

Ideally, there would be a way to persist gr.State in some external datastore (e.g. Redis, DB, even a just a cookie could work), or swap it out for another object with an appropriate interface.

1 Like