I’ve created a Panel application that uses the ChatInterface widget to interact with an LLM.
A very simplified version of my app.py is:
def setup_ui(model):
template = pn.template.MaterialTemplate()
chat_interface = pn.chat.ChatInterface(
message_params=dict(
reaction_icons={},
),
callback=model.callback,
name="Chat",
)
template.main.append(chat_interface)
return template
model = setup_llm() # do llm model setup, ommited
template = setup_ui(model)
APP_ROUTES = {"app": template}
pn.serve(
{"app": template},
...other params, including OAuth
)
This works well for a single user, but when another user logs in using OAuth, all the state is shared between them, so they see each others conversation.
I see several Discourse entries, issues and documentation on this but they are somewhat dated and are more focused on scalability, and not on state.
I’ve tried one suggestion which was to increase num_procs to 2 or more, but this seems to break OAuth authentication. I’ve looked at other suggestions like implementing a callback, but it wasnt clear how this would prevent shared state or what a best practice is.
How can I prevent one users chat interface and template from being shared with another user?
Thanks!
Hi everyone! I am deploying an application using a panel and encountered the problem described here Unable to to serve datas . That is, multiple users cannot independently use the application.
But the proposed solution is for Boquet’s server. I would like to know how to implement the same thing only for the Panel.
My code is very simple and looks like this:
def callback():
return some_hv_object
dmap = hv.DynamicMap(callback)
rastered = rasterize(dmap)
pn.serve(rastered, port=5000, show=…
opened 08:09AM - 24 Aug 18 UTC
type: docs
I am using the [Deploying with `bokeh serve`](http://holoviews.org/user_guide/De… ploying_Bokeh_Apps.html#Deploying-with-bokeh-serve) example from the documentation to create a minimal holoviews/bokeh server.
However, instead of giving a `holoviews.DynamicMap` to `hv.renderer('bokeh').app()`; I am giving it a `holoviews.operation.datashader.datashade`.
This causes a Tornado lock to be opened and never closed making it impossible to serve multiple users.
Here is a minimal example that works fine for one user but fails for multiple users:
```python
import numpy as np
import holoviews as hv
import holoviews.plotting.bokeh
from holoviews.operation.datashader import datashade
renderer = hv.renderer('bokeh')
def sine(frequency, phase, amplitude):
xs = np.linspace(0, np.pi*4)
return hv.Curve((xs, np.sin(frequency*xs+phase)*amplitude)).options(width=800)
dmap = datashade(sine(1, 0, 1))
# Replacing by next line works fine for multiple users.
# dmap = hv.DynamicMap(sine, kdims=['frequency', 'phase', 'amplitude']).redim.range(**ranges)
app = renderer.app(dmap)
print(app)
from bokeh.server.server import Server
server = Server({'/': app}, port=0)
server.start()
server.show('/')
from tornado.ioloop import IOLoop
loop = IOLoop.current()
loop.start()
```
Is it possible to create a minimal datashader/holoviews/bokeh server that can serve multiple users?
Using template.servable()
and $ panel serve app.py
in the CLI would make it unique I think.
Thanks @ahuang11 , I was able to temporarily work around this by passing a callback that instantiated the template instead of the template itself.
Wrap the template in a function; otherwise, it is the same instance shared between users.
def routes():
model = setup_llm() # do llm model setup, committed
template = setup_ui(model)
APP_ROUTES = {"app": template()}
pn.serve(
{"app": template},
...other params, including OAuth
)