Session state in the new ChatInterface
Hi there! I was checking at the new docs for thegr.ChatInterface()and I am unclear how can I apply session state to that.Any help would be appreciated.Thank you in advance!
2023-08-21T13:26:16Z
Can you elaborate a bit more? What are you trying to accomplish?
2023-08-21T14:27:52Z
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.
2023-08-21T14:32:52Z
Basically, datanotbeing shared between different users of the chatbot.
2023-08-21T14:40:39Z
That’s already baked into thegr.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)
2023-08-22T17:35:06Z
Any solution?
2023-08-22T18:15:56Z
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.gradio.appSharing Your AppA Step-by-Step Gradio Tutorial
2023-08-24T00:02:59Z
Any solutions?
2023-10-25T08:50:49Z
Hi@radames@abidlabsI 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 successWhat 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 = 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()
2023-11-06T15:37:18Z
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@nbaruinitially said. Thanks for the questions!