mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-30 11:00:11 +08:00
Persistent FRP (#3149)
* start * adding share_token * added token * revert older changes * revert older changes * fixes * revert * print * changes * version * changelog, version * fix tests
This commit is contained in:
parent
752ec0ef6a
commit
d15590d49c
@ -58,6 +58,8 @@ No changes to highlight.
|
||||
* Caches temp files from base64 input data by giving them a deterministic path based on the contents of data by [@abidlabs](https://github.com/abidlabs) in [PR 3197](https://github.com/gradio-app/gradio/pull/3197)
|
||||
* Better warnings (when there is a mismatch between the number of output components and values returned by a function, or when the `File` component or `UploadButton` component includes a `file_types` parameter along with `file_count=="dir"`) by [@abidlabs](https://github.com/abidlabs) in [PR 3194](https://github.com/gradio-app/gradio/pull/3194)
|
||||
* Raises a `gr.Error` instead of a regular Python error when you use `gr.Interface.load()` to load a model and there's an error querying the HF API by [@abidlabs](https://github.com/abidlabs) in [PR 3194](https://github.com/gradio-app/gradio/pull/3194)
|
||||
* Fixed gradio share links so that they are persistent and do not reset if network
|
||||
connection is disrupted by by [XciD](https://github.com/XciD), [Wauplin](https://github.com/Wauplin), and [@abidlabs](https://github.com/abidlabs) in [PR 3149](https://github.com/gradio-app/gradio/pull/3149)
|
||||
|
||||
## Contributors Shoutout:
|
||||
No changes to highlight.
|
||||
|
@ -7,6 +7,7 @@ import json
|
||||
import os
|
||||
import pkgutil
|
||||
import random
|
||||
import secrets
|
||||
import sys
|
||||
import time
|
||||
import warnings
|
||||
@ -71,6 +72,7 @@ class Block:
|
||||
self.visible = visible
|
||||
self.elem_id = elem_id
|
||||
self.root_url = root_url
|
||||
self.share_token = secrets.token_urlsafe(32)
|
||||
self._skip_init_processing = _skip_init_processing
|
||||
self._style = {}
|
||||
self.parent: BlockContext | None = None
|
||||
@ -1475,7 +1477,7 @@ class Blocks(BlockContext):
|
||||
try:
|
||||
if self.share_url is None:
|
||||
self.share_url = networking.setup_tunnel(
|
||||
self.server_name, self.server_port
|
||||
self.server_name, self.server_port, self.share_token
|
||||
)
|
||||
print(strings.en["SHARE_LINK_DISPLAY"].format(self.share_url))
|
||||
if not (quiet):
|
||||
|
@ -156,13 +156,15 @@ def start_server(
|
||||
return server_name, port, path_to_local_server, app, server
|
||||
|
||||
|
||||
def setup_tunnel(local_host: str, local_port: int) -> str:
|
||||
def setup_tunnel(local_host: str, local_port: int, share_token: str) -> str:
|
||||
response = requests.get(GRADIO_API_SERVER)
|
||||
if response and response.status_code == 200:
|
||||
try:
|
||||
payload = response.json()[0]
|
||||
remote_host, remote_port = payload["host"], int(payload["port"])
|
||||
tunnel = Tunnel(remote_host, remote_port, local_host, local_port)
|
||||
tunnel = Tunnel(
|
||||
remote_host, remote_port, local_host, local_port, share_token
|
||||
)
|
||||
address = tunnel.start_tunnel()
|
||||
return address
|
||||
except Exception as e:
|
||||
|
@ -6,18 +6,19 @@ import subprocess
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
VERSION = "0.1"
|
||||
VERSION = "0.2"
|
||||
CURRENT_TUNNELS: List["Tunnel"] = []
|
||||
|
||||
|
||||
class Tunnel:
|
||||
def __init__(self, remote_host, remote_port, local_host, local_port):
|
||||
def __init__(self, remote_host, remote_port, local_host, local_port, share_token):
|
||||
self.proc = None
|
||||
self.url = None
|
||||
self.remote_host = remote_host
|
||||
self.remote_port = remote_port
|
||||
self.local_host = local_host
|
||||
self.local_port = local_port
|
||||
self.share_token = share_token
|
||||
|
||||
@staticmethod
|
||||
def download_binary():
|
||||
@ -72,7 +73,7 @@ class Tunnel:
|
||||
binary,
|
||||
"http",
|
||||
"-n",
|
||||
"random",
|
||||
self.share_token,
|
||||
"-l",
|
||||
str(self.local_port),
|
||||
"-i",
|
||||
@ -85,7 +86,6 @@ class Tunnel:
|
||||
f"{self.remote_host}:{self.remote_port}",
|
||||
"--disable_log_color",
|
||||
]
|
||||
|
||||
self.proc = subprocess.Popen(
|
||||
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
@ -1 +1 @@
|
||||
3.18.0
|
||||
3.18.1b2
|
||||
|
@ -7,5 +7,5 @@ from gradio import Interface, networking
|
||||
def test_setup_tunnel():
|
||||
io = Interface(lambda x: x, "number", "number")
|
||||
io.launch(show_error=True, prevent_thread_lock=True)
|
||||
share_url = networking.setup_tunnel(io.server_name, io.server_port)
|
||||
share_url = networking.setup_tunnel(io.server_name, io.server_port, io.share_token)
|
||||
assert isinstance(share_url, str)
|
||||
|
Loading…
Reference in New Issue
Block a user