# Session state in the new ChatInterface

**URL:** <https://discuss.huggingface.co/t/session-state-in-the-new-chatinterface/51374>\
**Category:** 🔒 Gradio\
**Created:** [August 20, 2023, 12:22am UTC](https://discuss.huggingface.co/t/session-state-in-the-new-chatinterface/51374 "2023-08-20T00:22:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbaru](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@nbaru](https://discuss.huggingface.co/u/nbaru)\
**Post date:** [August 20, 2023, 12:22am UTC](https://discuss.huggingface.co/t/session-state-in-the-new-chatinterface/51374/1 "2023-08-20T00:22:26Z")

</div>

Hi there! I was checking at the new docs for the `gr.ChatInterface()` and I am unclear how can I apply session state to that.  
Any help would be appreciated.  
Thank you in advance!

---

<div class="post-metadata">

**Author:** ![abidlabs](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/abidlabs/32/21878_2.png) [@abidlabs](https://discuss.huggingface.co/u/abidlabs)\
**Post date:** [August 21, 2023, 1:26pm UTC](https://discuss.huggingface.co/t/session-state-in-the-new-chatinterface/51374/2 "2023-08-21T13:26:16Z")

</div>

Can you elaborate a bit more? What are you trying to accomplish?

---

<div class="post-metadata">

**Author:** ![nbaru](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@nbaru](https://discuss.huggingface.co/u/nbaru)\
**Post date:** [August 21, 2023, 2:27pm UTC](https://discuss.huggingface.co/t/session-state-in-the-new-chatinterface/51374/3 "2023-08-21T14:27:52Z")

</div>

Yes , definitely. I want to create a chatbot with the new gr.ChatInterface(),with chat history but the chat history to be different for every user and not to get jumbled between different users.,how can I implement that with session state,where the chat history is different for every user.

---

<div class="post-metadata">

**Author:** ![nbaru](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@nbaru](https://discuss.huggingface.co/u/nbaru)\
**Post date:** [August 21, 2023, 2:32pm UTC](https://discuss.huggingface.co/t/session-state-in-the-new-chatinterface/51374/4 "2023-08-21T14:32:52Z")

</div>

Basically, data _not_ being shared between different users of the chatbot.

---

<div class="post-metadata">

**Author:** ![abidlabs](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/abidlabs/32/21878_2.png) [@abidlabs](https://discuss.huggingface.co/u/abidlabs)\
**Post date:** [August 21, 2023, 2:40pm UTC](https://discuss.huggingface.co/t/session-state-in-the-new-chatinterface/51374/5 "2023-08-21T14:40:39Z")

</div>

That’s already baked into the `gr.ChatInterface`. Please see the examples here: [Gradio ChatInterface Docs](https://www.gradio.app/docs/chatinterface)

(and you can try running them from different browser tabs to ensure that conversation history is not shared)

---

<div class="post-metadata">

**Author:** ![nbaru](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@nbaru](https://discuss.huggingface.co/u/nbaru)\
**Post date:** [August 22, 2023, 5:35pm UTC](https://discuss.huggingface.co/t/session-state-in-the-new-chatinterface/51374/7 "2023-08-22T17:35:06Z")

</div>

Any solution?

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [August 22, 2023, 6:15pm UTC](https://discuss.huggingface.co/t/session-state-in-the-new-chatinterface/51374/8 "2023-08-22T18:15:56Z")

</div>

hi @nbaru , the session is ephemeral, so if you refresh the connection you will get a new session and all the previous chat is gone.  
However, you can implement a form of login using an experimental OAuth with Gradio and HF hub.  
Essentially, you will have to implement some local storage and when the user returns you can load the previous chat data.

> **[Sharing Your App](https://www.gradio.app/guides/sharing-your-app#o-auth-login-via-hugging-face)**
>
> A Step-by-Step Gradio Tutorial

---

<div class="post-metadata">

**Author:** ![nbaru](https://avatars.discourse-cdn.com/v4/letter/n/0ea827/32.png) [@nbaru](https://discuss.huggingface.co/u/nbaru)\
**Post date:** [August 24, 2023, 12:02am UTC](https://discuss.huggingface.co/t/session-state-in-the-new-chatinterface/51374/10 "2023-08-24T00:02:59Z")

</div>

Any solutions?

---

<div class="post-metadata">

**Author:** ![juanluisrto](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/juanluisrto/32/20625_2.png) [@juanluisrto](https://discuss.huggingface.co/u/juanluisrto)\
**Post date:** [October 25, 2023, 8:50am UTC](https://discuss.huggingface.co/t/session-state-in-the-new-chatinterface/51374/11 "2023-10-25T08:50:49Z")

</div>

Hi @radames @abidlabs  
I am also interested on this, could we reopen the issue?  
My gradio app is connecting to a backend for the conversation logic and I need to create and save some sort of session\_id, to pass it over to the backend and handle multiple users. I have tried adding a State object via additional\_inputs but without success

What I have tried is to pass extra arguments to the gr.ChatInterface fn, which can be returned with the new message and represent states, but it is not working.

This is my current status, which is not working:

```plaintext

import gradio as gr
import requests
import logging
import uuid

def predict_interface(message, history=None, id = None):
    response = requests.post('http://localhost:8000/api/ask_llm', json={'message': message})
    logging.error(response.json())
    if id is None:
        id = str(uuid.uuid4())
    logging.error(id)
    return response.json()['response'], id

       
#this is my session_id
id_component = gr.State(value = None, label = "id")

iface = gr.ChatInterface(
    predict_interface,
    additional_inputs= [id_component],
)
iface.output_components = [id_component]

iface.queue().launch()

```

---

<div class="post-metadata">

**Author:** ![codingurl](https://avatars.discourse-cdn.com/v4/letter/c/34f0e0/32.png) [@codingurl](https://discuss.huggingface.co/u/codingurl)\
**Post date:** [November 6, 2023, 3:37pm UTC](https://discuss.huggingface.co/t/session-state-in-the-new-chatinterface/51374/12 "2023-11-06T15:37:18Z")

</div>

I am also dealing with this problem and have been trying a similar solution to @juanluisrto. Feels like it should be intuitive to see users’ chat history but I too have noticed they always come back jumbled like @nbaru initially said. Thanks for the questions!
