print(f'Run this in (non-interactive) terminal. Stop server with Ctrl+C. Then you can reuse the same port.\nAccess WebGUI server on https://jupyter.hs-bochum.de/user/{user}/proxy/{port}/')
# s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# s.connect(("8.8.8.8", 80))
# my_ip = s.getsockname()[0]
# s.close()
# port = 7860
# print(f'Run this in (non-interactive) terminal. Stop server with Ctrl+C. Then you can reuse the same port.\nAccess WebGUI server on https://{my_ip}:7860')
Now, what is missing is the `demo.launch()` part. And this is, what this small tutorial is about. For different situations you need different arguments. The order of the situations is from low access to shared access. So prefer the first method that fits for you.
Find the full code for download [here](gradio-example.py).
## Localhost
If you are working on a local python installation (not JupyterHub) and want to restrict access to this very machine, just call
``` python
demo.launch()
```
Gradio can also show in VS Code's interactive window. So you can call this in interactive mode or maybe even from Jupyter Notebooks. Or just open http://localhost:7860.
## Network link
If you are working on a local python installation (not JupyterHub) and want to allow access to the gradio server from other computers in the local network, use `server_name='0.0.0.0'. For a friendly output, we also look for the IP address of the default route.
``` python
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
my_ip = s.getsockname()[0]
s.close()
port = 7860
print('Run this in (non-interactive) terminal. Stop server with Ctrl+C. Then you can reuse the same port.')
print(f'Access WebGUI server on http://{my_ip}:7860')
If you run the app on a JupyterHub with the Jupyter Server Proxy is enabled, like on [our JupyterHub](https://jupyter.hs-bochum.de), you can use the following code and execute your script in a terminal.
``` python
import socket
user = socket.gethostname().removeprefix('jupyter-')
port = 7860
print('Run this in (non-interactive) terminal. Stop server with Ctrl+C. Then you can reuse the same port.')
print(f'Access WebGUI server on https://jupyter.hs-bochum.de/user/{user}/proxy/{port}/')
If you run the app anywhere, like on Kaggle, Google Colab or any other JupyterHub, you can always make a public shared link. It will last for max. 72 h.
``` python
demo.launch(share=True, height=800)
```
This will use gradio's service to make a public link tunneling to the gradio server.