What I’m trying to do: To connect my chatbot from colab notebook to anvil interface
What I’ve tried and what’s not working:
I’ve already created the chatbot, added the !pip install anvil_uplink, import server with server key, defined a function you can call from anvil to get bot response. Lastly, defined a function when button is clicked.
I seem to encounter issues with my button defined function.
Code Sample:
# ON MY COLAB NOTEBOOK I DID THE FOLLOWING.
!pip install anvil-uplink
import anvil.server
anvil.server.connect("SERVER_KEY INCLUDED")
#@anvil.server.callable
def get_chatbot_response(input_text):
response = match_response(input_text)
return response
#entire chatbot code here!!!!
anvil.server.wait_forever()
# ON ANVIL I DID THE FOLLOWING
#defined a function when the button is clicked a response is retrieved from colab notebook and displayed on rich text area.
def button_1_click(self, **event_args):
"""This method is called when the button is clicked"""
# Establish the connection with the Anvil server
anvil.server.connect("SERVER_KEY INCLUDED")
# Get the user input from the text box component
input_text = self.input_text.text
# Call the Colab chatbot function using Anvil server
response = anvil.server.call('my_colab_chatbot_function', input_text)
# Set the response in the label component
self.response.text = response
# Set the event handler for the button click
self.send_message.set_event_handler('click', button_click)
#Inside the event handler for the send button click
self.text_area_1.text = ''
#rich_text_1 renamed to "response"
#text_area_1 renamed to "input_text"
#button_1 renamed to "send_message"
Clone link:Anvil | Login