ChrisDelClea / streamlit-agraph

A Streamlit Graph Vis
MIT License
390 stars 53 forks source link

Can't refer node image to local address. #35

Closed SandroChen closed 1 year ago

SandroChen commented 1 year ago

nodes.append(Node(id="Spiderman", label="Peter Parker", size=25, shape="circularImage", image="./data/images/经典片段-021-让子弹飞-1.png") )

Beyond is my code. It seems that I can't set a local address as the image path, otherwise the error would occur:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/streamlit/web/server/component_request_handler.py", line 55, in get with open(abspath, "rb") as file: FileNotFoundError: [Errno 2] No such file or directory: '/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/streamlit_agraph/frontend/build/data/images/经典片段-021-让子弹飞-1.png'

ChrisDelClea commented 1 year ago

hey @SandroChen ,

this is a known issu within streamlit. You can try to upload the files to a sever (e.g. GitHub) and get them from there or otherwise try to convert them to base64 and store them in a json file or something. Btw. this is only happening if you deploy the app, right?

cygkichi commented 8 months ago

Thank you, @ChrisDelClea !

I also encountered the same issue but was able to resolve it. Incidentally, it only occurred upon deployment.

I'll share the code for reference.

import base64
from pathlib import Path

image_path=Path('../image.png')
image_bytes = image_path.read_bytes()
image_encoded = base64.b64encode(image_bytes).decode()

nodes.append(Node(
    label='abc',
    size=25,
    shape="circularImage",
    image=f"data:image/png;base64,{image_encoded}"
))