Hello i’m trying to build a simple image classifier UI for my program but i get the following error when i press run RuntimeError: The Session graph is empty. Add operations to the graph before calling run(). I get this error when I try to upload a image.
import anvil.media
@anvil.server.callable
def classify_image(file):
with anvil.media.TempFile(file) as filename:
img=load_img(filename)
img=img.resize((224,224),resample=PIL.Image.BICUBIC)
arr=img_to_array(img)
arr=np.expand_dims(arr,axis=0)
arr /=255
score=model.predict(arr)
return("Positive" if pred == 0 else "Negative",score)
anvil.server.wait_forever()
Can you help me please?
1 Like
Welcome to Anvil.
Please can you edit your question and wrap the python code in triple back ticks like this so it formats it correctly :
```
<code>
```
Once it is easier to read, more people might help.
I’m no expert with the image stuff, but I might be able to help if it’s a general issue.
I’m assuming this is uplink server code? I’m further guessing the error is on the client side.
Please could you :
-
create a complete server script that I can run locally here (including importing the uplink module) but only including the functions I need to recreate the issue.
-
create a really simple anvil app that easily demonstrates just the issue, if possible.
If you can do that, and supply a clone link for the app, I will test it and see if I can see what the issue is.
You create a clone link by clicking the gear icon and selecting “share app” :


then post that link on here (or PM me privately)