Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
abidlabs committed Aug 29, 2024
1 parent ab4580b commit 9f4c3ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
10 changes: 7 additions & 3 deletions gradio/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
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")


def setup_tunnel(
local_host: str, local_port: int, share_token: str, share_server_address: str | None
) -> str:
Expand All @@ -32,6 +32,10 @@ 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."
Expand Down
17 changes: 11 additions & 6 deletions gradio/tunneling.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import httpx

VERSION = "0.2"
VERSION = "0.3"
CURRENT_TUNNELS: list["Tunnel"] = []

machine = platform.machine()
Expand All @@ -24,11 +24,11 @@
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": "cdd756e16622e0e60b697022d8da827a11fefe689325861c58c1003f2f8aa519",
"https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_amd64": "fb74b665633589410540c49dfcef5b6f0fd4a9bd7c9558bcdee2f0e43da0774d",
"https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_arm64": "af13b93897512079ead398224bd58bbaa136fcc5679af023780ee6c0538b3d82",
"https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_darwin_amd64": "6d3bd9f7e92e82fe557ba1d223bdd25317fbc296173a829601926526263c6092",
"https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_darwin_arm64": "0227ae6dafbe59d4e2c4a827d983ecc463eaa61f152216a3ec809c429c08eb31",
}
CHUNK_SIZE = 128

Expand All @@ -42,6 +42,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):
Expand Down Expand Up @@ -113,6 +115,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
Expand Down

0 comments on commit 9f4c3ee

Please sign in to comment.