facebookresearch / sam2

The repository provides code for running inference with the Meta Segment Anything Model 2 (SAM 2), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.
Apache License 2.0
11.65k stars 1.02k forks source link

Unable to access the demo web UI on the LAN #366

Open rango886 opened 1 week ago

rango886 commented 1 week ago

After deploying an application with Docker, I can access it on the host machine using 127.0.0.1:7262. However, when I try to access it from other devices on the local network using 192.168.x.x IP address, I get a "Uh oh, this browser isn’t supported." error.

iCKqpQI35i

ronghanghu commented 1 week ago

Hi @rango886, to access it from another machine, you'll also need to set the backend API address, which is specified as the API_URL env in this line https://github.com/facebookresearch/sam2/blob/c98aa6bea377d5c000cdc80197ce402dbf5304dc/demo/backend/server/app_conf.py#L14 and set to a local address http://localhost:7263 in docker-compose.yaml in https://github.com/facebookresearch/sam2/blob/c98aa6bea377d5c000cdc80197ce402dbf5304dc/docker-compose.yaml#L26

You can change it to http://192.168.x.x:7263 (i.e. the server machine's IP address running the backend), so that it can be accessed from other hosts. Hope this resolves your issue

rango886 commented 1 week ago

Hi @rango886, to access it from another machine, you'll also need to set the backend API address, which is specified as the API_URL env in this line

https://github.com/facebookresearch/sam2/blob/c98aa6bea377d5c000cdc80197ce402dbf5304dc/demo/backend/server/app_conf.py#L14

and set to a local address http://localhost:7263 in docker-compose.yaml in https://github.com/facebookresearch/sam2/blob/c98aa6bea377d5c000cdc80197ce402dbf5304dc/docker-compose.yaml#L26

You can change it to http://192.168.x.x:7263 (i.e. the server machine's IP address running the backend), so that it can be accessed from other hosts. Hope this resolves your issue

It seems that it doesn't work. After modifying the environment variable. uvLJBeH7nB I found that it is displayed that the browser does not support video features. d0X69Tvny6 I am using the latest version of Chrome. I found on the Internet that the front end may use this browser API https://developer.mozilla.org/en-US/docs/Web/API/VideoEncoder . For this API, local access does not use https, while within the local area network, https is required for use.

MIKE-GUO233 commented 1 week ago

Please modify Chrome settings to enable the VideoEncoder feature when accessing over HTTP.

  1. Open chrome://flags/ in your chrome.
  2. Add your IP address to the Insecure origins treated as secure setting and relaunch the browser.
image
rango886 commented 1 week ago

Please modify Chrome settings to enable the VideoEncoder feature when accessing over HTTP.

  1. Open chrome://flags/ in your chrome.
  2. Add your IP address to the Insecure origins treated as secure setting and relaunch the browser.
image

NrH8EWivDk

Thank you. It can be used in the local area network now. However, it is also necessary to click this button and set the IP address of the local area network to be able to use it.

crashr commented 1 week ago

Hi @rango886, to access it from another machine, you'll also need to set the backend API address, which is specified as the API_URL env in this line

https://github.com/facebookresearch/sam2/blob/c98aa6bea377d5c000cdc80197ce402dbf5304dc/demo/backend/server/app_conf.py#L14

and set to a local address http://localhost:7263 in docker-compose.yaml in https://github.com/facebookresearch/sam2/blob/c98aa6bea377d5c000cdc80197ce402dbf5304dc/docker-compose.yaml#L26

You can change it to http://192.168.x.x:7263 (i.e. the server machine's IP address running the backend), so that it can be accessed from other hosts. Hope this resolves your issue

Didn't work for me. In the console I still see requests to http://localhost:7263 I worked around it with

socat TCP-LISTEN:7263,reuseaddr,fork TCP:192.168.178.56:7263

raedle commented 6 days ago

There are currently different places for changing the server endpoint:

Frontend

https://github.com/facebookresearch/sam2/blob/c98aa6bea377d5c000cdc80197ce402dbf5304dc/demo/frontend/src/demo/DemoConfig.tsx#L34-L35

The endpoint is also stored in local storage, which has precedence over the value in the DemoConfig.tsx. Just in case, make sure to delete the local storage key before opening the site (or use the browser's incognito mode) or change the endpoint via the settings modal shared above:

localStorage.removeItem('SAM2_SETTINGS_KEY')

Backend

https://github.com/facebookresearch/sam2/blob/c98aa6bea377d5c000cdc80197ce402dbf5304dc/docker-compose.yaml#L26

Note: there might be CORS restrictions if the page isn't loaded from localhost