diff --git a/.changeset/dirty-pugs-hunt.md b/.changeset/dirty-pugs-hunt.md new file mode 100644 index 0000000000000..19924d0c8516b --- /dev/null +++ b/.changeset/dirty-pugs-hunt.md @@ -0,0 +1,5 @@ +--- +"gradio": minor +--- + +feat:Adds TLS to FRP tunnel diff --git a/gradio/networking.py b/gradio/networking.py index aecbd43b2de79..85fa495f49f4d 100644 --- a/gradio/networking.py +++ b/gradio/networking.py @@ -5,17 +5,17 @@ from __future__ import annotations -import ipaddress import os import time import warnings +from pathlib import Path import httpx from gradio.routes import App # HACK: to avoid circular import # noqa: F401 -from gradio.tunneling import Tunnel +from gradio.tunneling import CERTIFICATE_PATH, Tunnel -GRADIO_API_SERVER = "https://api.gradio.app/v2/tunnel-request" +GRADIO_API_SERVER = "https://api.gradio.app/v3/tunnel-request" GRADIO_SHARE_SERVER_ADDRESS = os.getenv("GRADIO_SHARE_SERVER_ADDRESS") @@ -32,16 +32,14 @@ def setup_tunnel( response = httpx.get(GRADIO_API_SERVER, timeout=30) payload = response.json()[0] remote_host, remote_port = payload["host"], int(payload["port"]) + certificate = payload["root_ca"] + Path(CERTIFICATE_PATH).parent.mkdir(parents=True, exist_ok=True) + with open(CERTIFICATE_PATH, "w") as f: + f.write(certificate) except Exception as e: raise RuntimeError( "Could not get share link from Gradio API Server." ) from e - try: - ipaddress.ip_address(remote_host) - except ValueError as e: - raise ValueError( - f"Invalid IP address received from Gradio API Server: {remote_host}" - ) from e else: remote_host, remote_port = share_server_address.split(":") remote_port = int(remote_port) diff --git a/gradio/strings.py b/gradio/strings.py index 4e2dad2288dee..b038ee51ca172 100644 --- a/gradio/strings.py +++ b/gradio/strings.py @@ -8,9 +8,9 @@ MESSAGING_API_ENDPOINT = "https://api.gradio.app/gradio-messaging/en" en = { - "RUNNING_LOCALLY": "Running on local URL: {}", - "RUNNING_LOCALLY_SEPARATED": "Running on local URL: {}://{}:{}", - "SHARE_LINK_DISPLAY": "Running on public URL: {}", + "RUNNING_LOCALLY": "* Running on local URL: {}", + "RUNNING_LOCALLY_SEPARATED": "* Running on local URL: {}://{}:{}", + "SHARE_LINK_DISPLAY": "* Running on public URL: {}", "COULD_NOT_GET_SHARE_LINK": "\nCould not create share link. Please check your internet connection or our status page: https://status.gradio.app.", "COULD_NOT_GET_SHARE_LINK_MISSING_FILE": "\nCould not create share link. Missing file: {}. \n\nPlease check your internet connection. This can happen if your antivirus software blocks the download of this file. You can install manually by following these steps: \n\n1. Download this file: {}\n2. Rename the downloaded file to: {}\n3. Move the file to this location: {}", "COLAB_NO_LOCAL": "Cannot display local interface on google colab, public link created.", @@ -22,7 +22,7 @@ "To turn off, set debug=False in launch().", "COLAB_DEBUG_FALSE": "Colab notebook detected. To show errors in colab notebook, set debug=True in launch()", "COLAB_WARNING": "Note: opening Chrome Inspector may crash demo inside Colab notebooks.", - "SHARE_LINK_MESSAGE": "\nThis share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)", + "SHARE_LINK_MESSAGE": "\nThis share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)", "INLINE_DISPLAY_BELOW": "Interface loading below...", } diff --git a/gradio/tunneling.py b/gradio/tunneling.py index 43f75bca276ba..42fc647214ae7 100644 --- a/gradio/tunneling.py +++ b/gradio/tunneling.py @@ -12,24 +12,37 @@ import httpx -VERSION = "0.2" +VERSION = "0.3" CURRENT_TUNNELS: list["Tunnel"] = [] machine = platform.machine() if machine == "x86_64": machine = "amd64" +elif machine == "aarch64": + machine = "arm64" BINARY_REMOTE_NAME = f"frpc_{platform.system().lower()}_{machine.lower()}" EXTENSION = ".exe" if os.name == "nt" else "" BINARY_URL = f"https://cdn-media.huggingface.co/frpc-gradio-{VERSION}/{BINARY_REMOTE_NAME}{EXTENSION}" CHECKSUMS = { - "https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_windows_amd64.exe": "cdd756e16622e0e60b697022d8da827a11fefe689325861c58c1003f2f8aa519", - "https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_linux_amd64": "fb74b665633589410540c49dfcef5b6f0fd4a9bd7c9558bcdee2f0e43da0774d", - "https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_linux_arm64": "af13b93897512079ead398224bd58bbaa136fcc5679af023780ee6c0538b3d82", - "https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_darwin_amd64": "6d3bd9f7e92e82fe557ba1d223bdd25317fbc296173a829601926526263c6092", - "https://cdn-media.huggingface.co/frpc-gradio-0.2/frpc_darwin_arm64": "0227ae6dafbe59d4e2c4a827d983ecc463eaa61f152216a3ec809c429c08eb31", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_windows_amd64.exe": "14bc0ea470be5d67d79a07412bd21de8a0a179c6ac1116d7764f68e942dc9ceb", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_amd64": "c791d1f047b41ff5885772fc4bf20b797c6059bbd82abb9e31de15e55d6a57c4", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_arm64": "823ced25104de6dc3c9f4798dbb43f20e681207279e6ab89c40e2176ccbf70cd", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_darwin_amd64": "930f8face3365810ce16689da81b7d1941fda4466225a7bbcbced9a2916a6e15", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_darwin_arm64": "dfac50c690aca459ed5158fad8bfbe99f9282baf4166cf7c410a6673fbc1f327", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_arm": "4b563beb2e36c448cc688174e20b53af38dc1ff2b5e362d4ddd1401f2affbfb7", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_freebsd_386": "cb0a56c764ecf96dd54ed601d240c564f060ee4e58202d65ffca17c1a51ce19c", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_freebsd_amd64": "516d9e6903513869a011ddcd1ec206167ad1eb5dd6640d21057acc258edecbbb", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_386": "4c2f2a48cd71571498c0ac8a4d42a055f22cb7f14b4b5a2b0d584220fd60a283", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_mips": "b309ecd594d4f0f7f33e556a80d4b67aef9319c00a8334648a618e56b23cb9e0", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_mips64": "0372ef5505baa6f3b64c6295a86541b24b7b0dbe4ef28b344992e21f47624b7b", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_riscv64": "1658eed7e8c14ea76e1d95749d58441ce24147c3d559381832c725c29cfc3df3", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_mipsle": "a2aaba16961d3372b79bd7a28976fcd0f0bbaebc2b50d5a7a71af2240747960f", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_windows_386.exe": "721b90550195a83e15f2176d8f85a48d5a25822757cb872e9723d4bccc4e5bb6", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_mips64le": "796481edd609f31962b45cc0ab4c9798d040205ae3bf354ed1b72fb432d796b8", } + CHUNK_SIZE = 128 BINARY_FILENAME = f"{BINARY_REMOTE_NAME}_v{VERSION}" @@ -42,6 +55,8 @@ "Please check the appended log from frpc for more information:" ) +CERTIFICATE_PATH = ".gradio/certificate.pem" + class Tunnel: def __init__(self, remote_host, remote_port, local_host, local_port, share_token): @@ -113,6 +128,9 @@ def _start_tunnel(self, binary: str) -> str: "--server_addr", f"{self.remote_host}:{self.remote_port}", "--disable_log_color", + "--tls_enable", + "--tls_trusted_ca_file", + CERTIFICATE_PATH, ] self.proc = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE