Session state in the new ChatInterface

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!

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

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.

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

That’s already baked into the gr.ChatInterface. Please see the examples here: Gradio ChatInterface Docs

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

Any solution?

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.

Any solutions?

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:

import gradio as gr
import requests
import logging
import uuid

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

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

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

1 Like

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!