Sending messages between Google Colab and Anvil

I have setup a program in Google Colab for object detection and finding masks of objects

I have a program on Anvil that takes in an image from user and sends it to Google Colab through a server function

I have connected Anvil with Google Colab and it is working fine.

It takes about a minute for the whole program to run in Google Colab and send the output back to Anvil to show on the web app.

What I want to do is to show some intermediate messages on the web app, as the program in Google Colab is running. This is so that user doesn’t have to just see the spinner. How can I have some messages send from Google Colab when some part of the code is finished? For example, if one part of the code is finished, I can display on the web app
“Detecting object…”
“Object detected, segmentation in process”
“Segmentation done, mask creation in process”

and so on.
Right now, I have to wait till the end of the server function, before something can be returned. Is there a way to set some variables that can be accessed in the webapp during the program run in Google Colab?

In Colab you update a row in the database with the current status, so the Anvil server knows it.

In the server you create a get_status callable that returns the status.

In the form you put a timer that does self.status.text = call_s('get_status', session_id).

Here I used session_id, but you could use the current user or whatever Colab session identifier you may have.

1 Like

I have done the first part, which is to update a row in the database with the current status.

I didnt understand the later parts. I already have a function in Google Colab which returns a media file. Now, you are saying creating another function get_status? But, how can I put this function inside the existing function?

There are 3 python interpreters:

  1. Colab writes the status in a string column of a database row
  2. A server module with a callable function that reads that row and returns the status string
  3. A form with a Timer component that calls the server function to get the latest status and shows it on a label

The first one is in Colab.
The second is in a server module.
The third is in a form.

The second and the third are created inside the IDE.

3 Likes