Hi. I’m uploading few files in Anvil and want to know how can I send them to Colab. Whatever I do it only sends the first one and it doesnt let me to iterate through the files also get_bytes gives a value only for the first one. Could you help me please?
Welcome! Here’s how to help us help you:
here I want to have all the files, then I want to select some of them, but it says that the files arent iterable and getting bytes for files gives only the answer for just first file and ignores the rest
Edit: I only want to be sure that I have all the files in colab and after that do pca.
@anvil.server.callable
def func(files):
try:
# Convert the file to an image
image_bytes = files.get_bytes()
img = Image.open(io.BytesIO(image_bytes))
img = img.convert(‘L’) # Convert to grayscale
# Convert the processed image back to bytes
with io.BytesIO() as output:
img.save(output, format='PNG')
processed_image_bytes = output.getvalue()
except Exception as e:
# If there's an error processing the image, print the error
print(f"Error processing file: {e}")
return BlobMedia(content=processed_image_bytes, content_type='image/png')
# Return None if no valid image is found or processed
return None
If you also share the client code that calls this ‘func’, we could help diagnose what’s going on with files
.
1 Like