Use of Panel package in JupyterLab

I was following the Chatbot lesson locally using JupyterLab.

However, it seems that the Panel package is not compatible with JupyterLab (version 3.5).
When I press the “Chat” button in the small GUI created by the panel package, the loading indicator works infinitely long. If I restart the same notebook using Jupyter Notebook version 6.5, it works.

Does anyone know how to make JupyterLab and panel compatible with each other?
Thanks!

Read down a bit. There is a cookbook describing how someone did it. Let us know?

@ai_curious thank you for the suggestion. That thread is about import problems. I do not have any such problems with the panel package.

The problem I have is that the panel UI is stuck in JupyterLab when I try to submit a message by pressing the “Chat” button. However, the UI works in Jupyter Notebook.

Ok. I thought it might be a package version issue and that approach would allow you to install a precise version to try working around. If that doesn’t help I got nothing since I don’t use Lab and it works for me (also) in a Notebook. Sorry

Thank anyway!

Yes, it seems to be strange. I’ve just tried to create a new conda environment and reinstall panel and JupyterLab (now version 4.0.0) in it. Still, even the basic example from panel · PyPI does not work (the number of stars does not change when I move the slider).

I was also running 3.5 via Docker.
Gave up on the panel library and shifted to a simpler approach:

import ipywidgets as widgets
from IPython.display import display, clear_output

# Create text box for user input
user_input = widgets.Textarea(value='',
                              placeholder='Enter text here...',
                              description='User:',
                              rows=2,
                              layout=widgets.Layout(width='auto'))

# Create text area for conversation display
conversation_history = widgets.Textarea(value='',
                                        description='Chat:',
                                        rows=15,
                                        layout=widgets.Layout(width='auto'))

# Create button for user to click to send their message
send_button = widgets.Button(description='Send')

def send_button_clicked(b):
    # Append user input to conversation history
    conversation_history.value += 'User: ' + user_input.value + '\n'
    
    # Generate assistant response and append to conversation history
    context.append({'role':'user', 'content':user_input.value})
    response = get_completion_from_messages(context) 
    context.append({'role':'assistant', 'content':response})
    conversation_history.value += 'Assistant: ' + response + '\n'
    
    # Clear user input box
    user_input.value = ''

send_button.on_click(send_button_clicked)

# Display everything
display(conversation_history, user_input, send_button)
1 Like

@claudiotx thank you for the code! I am not using Jupyter that much and was not aware that one can make GUIs so easily in it.
One note: it seems that the line

send_button.on_click(send_button_clicked)

should be

send_button.on_click(handle_submit)

although it is not clear how the text_input parameter is passed.

Have updated the snippet. Thanks