Not able to pass image files from anvil to google colab

What I’m trying to do:
I have a program in Google Colab which takes in two files, one is an indoor scene, and another is a furniture image. The output inserts the furniture image into the indoor scene file.
What I’ve tried and what’s not working:
I have added the components for file upload for both the files, and also added a button to run the program in Google Colab. But, I am not able to pass the files into Google Colab. It shows error as below.
Code Sample:
from ._anvil_designer import Form1Template
from anvil import *
import anvil.google.auth, anvil.google.drive
from anvil.google.drive import app_files
import anvil.server
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables
from anvil.google.drive import app_files
import anvil.media

class Form1(Form1Template):

def init(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)

# Any code you write here will run when the form opens.

def button_1_click(self, **event_args):
“”“This method is called when the button is clicked”""

result = anvil.server.call('test_code',self.file1,self.file2)
self.image_3.source = app_files.image0_output_png

pass

def file_loader_1_change(self, file, **event_args):
“”“This method is called when a new file is loaded into this FileLoader”""
self.file1=file
pass

def file_loader_2_change(self, file, **event_args):
“”“This method is called when a new file is loaded into this FileLoader”""
self.file2=file
pass

Clone link:
share a copy of your app

The error I get is:
NameError: name 'load_img' is not defined

  • at <ipython-input-1-858c0baec19f>:26
  • called from Form1, line 26

Line 26 is
result = anvil.server.call(‘test_code’,self.file1,self.file2)

Welcome to Anvil!

Are you sure there’s not more to the error message than that?

load_img doesn’t appear to be referenced in the code you pasted. I’m guessing the error is in your server function. Can you please post that?

(edit - I’ve not used anvil with colab, so if the issue is specific to that then I won’t be much help!)

Hi David,
Thanks for the reply. Yes, load_img was happening within the server function on Google Colab. I was able to fix it.

Thanks

2 Likes

how did you manage to do it ? im also stuck