Sygil-Dev / sygil-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
7.87k stars 881 forks source link

Streamlit not working with access from other machines on the local network anymore #1645

Open DasWookie opened 2 years ago

DasWookie commented 2 years ago

Discussed in https://github.com/Sygil-Dev/sygil-webui/discussions/1640

Originally posted by **DasWookie** November 2, 2022 Not sure what or why the change was made. Maybe because of all the Horde integration, but I can no longer connect to my linux server running SD on my local network anymore. Looked for some sort of "--listen" switch, but there doesn't appear to be anything (like automatic1111 needs) to listen on the local network. This was working previously with no issues. I had relaunched and the environment did a git pull to sync with latest, and stopped working. It's working fine with Gradio.

This is something specific to Sygil! I can run "streamlit hello" on the server in the same conda environment with the same config.toml config file, and I'm able to connect no problem from any of the other machines on the same network. I even changed the port number even to 7860 (instead of 8501) just to make sure that isn't the issue, it wasn't, but I'm doing the test just to prove that it's not a firewall issue on the server or client machines on the same network. Screenshot 2022-11-04 175302

So, I can connect to other streamlit apps on the linux server, on either port 7860 and 8501, but I still am unable connect to streamlit sygil server. This WORKED! I have been using it since the streamlit server was initially released. I haven't been able to track it down to which change broke it, but it's not working anymore.

DasWookie commented 2 years ago

I've made changes to the config TRYING to get sygil working on my local network. This is the config I used to test that the "hello" streamlit demo worked, and it connects with no problem at all. config.toml.txt

So, it doesn't APPEAR to be the config.toml settings that's stopping sygil from connecting from another machine on the local network. I've seared and troubleshot this as far as I can go, but it seems to me to be a issue with the sygil code and the connection only being allowed from localhost.

DasWookie commented 2 years ago

I've used the bone stock config as well as making just about every permutation of changes to headless, address, port, enableCORS, enableXsrfProtection, serverAddress, and serverPort. I can't get it to work, Here is my current config file for the streamlit config.toml. This works for streamlit hello, but NOT for sygil!


Below are all the sections and options you can have in ~/.streamlit/config.toml.

[global]

By default, Streamlit checks if the Python watchdog module is available and, if not, prints a warning asking for you to install it. The watchdog module is not required, but highly recommended. It improves Streamlit's ability to detect changes to files in your filesystem.

If you'd like to turn off this warning, set this to True.

Default: false

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

disableWatchdogWarning = false

If True, will show a warning when you run a Streamlit-enabled script via "python my_script.py".

Default: true

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

showWarningOnDirectExecution = true

DataFrame serialization.

Acceptable values: - 'legacy': Serialize DataFrames using Streamlit's custom format. Slow but battle-tested. - 'arrow': Serialize DataFrames using Apache Arrow. Much faster and versatile.

Default: "arrow"

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

dataFrameSerialization = "arrow"

[logger]

Level of logging: 'error', 'warning', 'info', or 'debug'.

Default: 'info'

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

level = "info"

String format for logging messages. If logger.datetimeFormat is set, logger messages will default to %(asctime)s.%(msecs)03d %(message)s. See Python's documentation for available attributes.

Default: "%(asctime)s %(message)s"

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

messageFormat = "%(asctime)s %(message)s"

[client]

Whether to enable st.cache.

Default: true

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

caching = true

If false, makes your Streamlit script not draw to a Streamlit app.

Default: true

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

displayEnabled = true

Controls whether uncaught app exceptions are displayed in the browser. By default, this is set to True and Streamlit displays app exceptions and associated tracebacks in the browser.

If set to False, an exception will result in a generic message being shown in the browser, and exceptions and tracebacks will be printed to the console only.

Default: true

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

showErrorDetails = true

[runner]

Allows you to type a variable or string by itself in a single line of Python code to write it to the app.

Default: true

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

magicEnabled = true

Install a Python tracer to allow you to stop or pause your script at any point and introspect it. As a side-effect, this slows down your script's execution.

Default: false

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

installTracer = false

Sets the MPLBACKEND environment variable to Agg inside Streamlit to prevent Python crashing.

Default: true

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

fixMatplotlib = true

Run the Python Garbage Collector after each script execution. This can help avoid excess memory use in Streamlit apps, but could introduce delay in rerunning the app script for high-memory-use applications.

Default: true

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

postScriptGC = true

Handle script rerun requests immediately, rather than waiting for script execution to reach a yield point. Enabling this will make Streamlit much more responsive to user interaction, but it can lead to race conditions in apps that mutate session_state data outside of explicit session_state assignment statements.

Default: false

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

fastReruns = false

[server]

List of folders that should not be watched for changes. This impacts both "Run on Save" and @st.cache.

Relative paths will be taken as relative to the current working directory.

Example: ['/home/user1/env', 'relative/path/to/folder']

Default: []

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

folderWatchBlacklist = []

Change the type of file watcher used by Streamlit, or turn it off completely.

Allowed values: "auto" : Streamlit will attempt to use the watchdog module, and falls back to polling if watchdog is not available. "watchdog" : Force Streamlit to use the watchdog module. "poll" : Force Streamlit to always use polling. "none" : Streamlit will not watch files.

Default: "auto"

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

fileWatcherType = "auto"

Symmetric key used to produce signed cookies. If deploying on multiple replicas, this should be set to the same value across all replicas to ensure they all share the same secret.

Default: randomly generated secret key.

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

cookieSecret = ""

If false, will attempt to open a browser window on start.

Default: false unless (1) we are on a Linux box where DISPLAY is unset, or (2) we are running in the Streamlit Atom plugin.

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

headless = true

Automatically rerun script when the file is modified on disk.

Default: false

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

runOnSave = false

The address where the server will listen for client and browser connections. Use this if you want to bind the server to a specific address. If set, the server will only be accessible from this address, and not from any aliases (like localhost).

Default: (unset)

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

address = "192.168.1.7"

The port where the server will listen for browser connections.

Default: 8501

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

port = 7860

The base path for the URL where Streamlit should be served from.

Default: ""

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

baseUrlPath = ""

Enables support for Cross-Origin Request Sharing (CORS) protection, for added security.

Due to conflicts between CORS and XSRF, if server.enableXsrfProtection is on and server.enableCORS is off at the same time, we will prioritize server.enableXsrfProtection.

Default: true

enableCORS = true

Enables support for Cross-Site Request Forgery (XSRF) protection, for added security.

Due to conflicts between CORS and XSRF, if server.enableXsrfProtection is on and server.enableCORS is off at the same time, we will prioritize server.enableXsrfProtection.

Default: true

enableXsrfProtection = true

Max size, in megabytes, for files uploaded with the file_uploader.

Default: 200

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

maxUploadSize = 200

Max size, in megabytes, of messages that can be sent via the WebSocket connection.

Default: 200

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

maxMessageSize = 200

Enables support for websocket compression.

Default: false

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

enableWebsocketCompression = false

[browser]

Internet address where users should point their browsers in order to connect to the app. Can be IP address or DNS name and path.

This is used to: - Set the correct URL for CORS and XSRF protection purposes. - Show the URL on the terminal - Open the browser

Default: "localhost"

serverAddress = "localhost"

Whether to send usage statistics to Streamlit.

Default: true

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

gatherUsageStats = false

Port where users should point their browsers in order to connect to the app.

This is used to: - Set the correct URL for CORS and XSRF protection purposes. - Show the URL on the terminal - Open the browser

Default: whatever value is set in server.port.

serverPort = 7860

[mapbox]

Configure Streamlit to use a custom Mapbox token for elements like st.pydeck_chart and st.map. To get a token for yourself, create an account at https://mapbox.com. It's free (for moderate usage levels)!

Default: ""

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

token = ""

[deprecation]

Set to false to disable the deprecation warning for the file uploader encoding.

Default: true

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

showfileUploaderEncoding = true

Set to false to disable the deprecation warning for using the global pyplot instance.

Default: true

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

showPyplotGlobalUse = true

[theme]

The preset Streamlit theme that your custom theme inherits from. One of "light" or "dark".

The value below was set in /home/cyber/stable-diffusion-webui-sygil/.streamlit/config.toml

base = "dark"

Primary accent color for interactive elements.

primaryColor =

Background color for the main content area.

backgroundColor =

Background color used for the sidebar and most interactive widgets.

secondaryBackgroundColor =

Color used for almost all text.

textColor =

Font family for all text in the app, except code blocks. One of "sans serif", "serif", or "monospace".

font =


So, it is NOT a firewall setting, or my streamlit config.toml that's the issue. That I know for certain now. I just don't know what the problem is for why I'm not able to connect from any other machines on the same network. Again, this worked previously!

ZeroCool940711 commented 2 years ago

@DasWookie I think it's an issue with the address, the port is probably fine, you need to set the address in the config file to 0.0.0.0 or your server IP under the [server] section, another option is to launch streamlit with the --server.address 0.0.0.0 argument, also, make sure the serverAddress under the browser section is also set as well as the port for that, those are used for CORS and XSRF, for some reason it also sometimes conflicts with the server address and it's taken from there instead of the server section, another thing to keep in mind is that command line arguments take priority over the streamlit config file, so, try launching streamlit with streamlit run scripts\webui_streamlit.py --logger.level info --server.headless True --server.address 0.0.0.0 --browser.serverAddress 0.0.0.0, note the --server.headless True if you are on a server this might be needed as streamlit will try to open a browser on launch which sometimes can have issues and stop the whole app on a server without a desktop.

DasWookie commented 2 years ago

OK, I tried that, and was able to connect successfully with using either: streamlit run scripts\webui_streamlit.py --logger.level info --server.headless True --server.address 0.0.0.0 --browser.serverAddress 0.0.0.0 and streamlit run scripts\webui_streamlit.py --logger.level info --server.headless True --server.address 192.168.1.7 --browser.serverAddress 192.168.1.7

So, I then changed my config.toml file for both the server section "address" and browser section "serverAddress" to have either 0.0.0.0 or 192.168.1.7 and both settings allowed a connection from machines on the local network. The headless setting seems to have gotten changed at least twice in the history, and the serverAddress = "localhost" value in the file bone stock certainly isn't helping.

ZeroCool940711 commented 2 years ago

The settings are probably getting changed because of the Settings page on the UI, I made it so you can customize the address and port from there and I had to add a default value for when those things were not set, probably having conflicts with it, also, in case you wonder, you can disable those options from the user config file so they are not shown there on the UI in case you plan to expose the UI on a remote server or just so you can connect from outside your home network, find the admin section on the config file and change the two options there.

DasWookie commented 2 years ago

yeah, the problem is, to access the config page, you have to have a working version. If one runs their linux server is headless (as I do) then the settings page isn't accessible with the default settings for the config.toml. I get there are MANY use cases, and there is no perfect solution. I beat my head against this rock for almost a week before posted the question on Discussions, and after getting nothing there and doing my own troubleshooting, I finally escalated this to an issue.

So a change of the following in your .streamlit/config.toml file: [server] headless = true address = "0.0.0.0"

[browser] serverAddress = "0.0.0.0"

seems to get it working. I don't know if that would be acceptable to modify in the .streamlit/config.toml or not. The 0.0.0.0 might end up confusing a lot of people who want to copy the string emitted by the launcher where localhost works for them.

ZeroCool940711 commented 2 years ago

@DasWookie yup, that should fix it but as you say it might or more like it already has people confused when they see the http://0.0.0.0:8501 address on their console and try to open it on the browser, so, I have no other option but to aim to please the guys with little tech knowledge and make it easy for them to understand things and then for the guys that want to run things on a server or other way just point them to where to edit stuff so they can make things work. Btw, you should join our discord, I'm always there and a lot of other people as well so helping with this kind of issue or any other is a lot easier, you can also just join to chat with the community or to share the results you've gotten with our UI on our Showcase channels :)