Skip to content

Commit

Permalink
networking tweak (gradio-app#1143)
Browse files Browse the repository at this point in the history
* networking tweak

* updated PyPi version to 2.9b20

* tweaks

* updated PyPi version to 2.9b21

Co-authored-by: pngwn <[email protected]>
  • Loading branch information
abidlabs and pngwn authored May 3, 2022
1 parent 8464481 commit 12f2374
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gradio.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: gradio
Version: 2.9b12
Version: 2.9b21
Summary: Python library for easily interacting with trained machine learning models
Home-page: https://github.com/gradio-app/gradio-UI
Author: Abubakar Abid, Ali Abid, Ali Abdalla, Dawood Khan, Ahsen Khaliq, Pete Allen, Ömer Faruk Özdemir
Expand Down
6 changes: 2 additions & 4 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,12 @@ def __init__(
self.ip_address = utils.get_local_ip_address()
self.is_space = True if os.getenv("SYSTEM") == "spaces" else False
self.favicon_path = None
self.auth = None
if self.is_space and enable_queue is None:
self.enable_queue = True
else:
self.enable_queue = enable_queue or False
self.config = self.get_config_file()

def render(self):
if Context.root_block is not None:
Expand Down Expand Up @@ -457,7 +459,6 @@ def launch(
local_url (str): Locally accessible link to the demo
share_url (str): Publicly accessible link to the demo (if share=True, otherwise None)
"""
self.config = self.get_config_file()
if (
auth
and not callable(auth)
Expand All @@ -479,9 +480,6 @@ def launch(
getpass.getpass("Enter key for encryption: ")
)

config = self.get_config_file()
self.config = config

if self.is_running:
self.server_app.launchable = self
print(
Expand Down
2 changes: 2 additions & 0 deletions gradio/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ def load_example(example_id):
if self.article:
Markdown(self.article)

self.config = self.get_config_file()

def __call__(self, *params):
if (
self.api_mode
Expand Down
32 changes: 18 additions & 14 deletions gradio/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ def get_first_available_port(initial: int, final: int) -> int:
)


def configure_app(app: fastapi.FastAPI, blocks: Blocks) -> fastapi.FastAPI:
auth = blocks.auth
if auth is not None:
if not callable(auth):
app.auth = {account[0]: account[1] for account in auth}
else:
app.auth = auth
else:
app.auth = None
app.blocks = blocks
app.cwd = os.getcwd()
app.favicon_path = blocks.favicon_path
app.tokens = {}
return app


def start_server(
blocks: Blocks,
server_name: Optional[str] = None,
Expand Down Expand Up @@ -123,23 +139,11 @@ def start_server(
else:
path_to_local_server = "http://{}:{}/".format(url_host_name, port)

auth = blocks.auth
app = create_app()

if auth is not None:
if not callable(auth):
app.auth = {account[0]: account[1] for account in auth}
else:
app.auth = auth
else:
app.auth = None
app.blocks = blocks
app.cwd = os.getcwd()
app.favicon_path = blocks.favicon_path
app.tokens = {}
app = configure_app(app, blocks)

if app.blocks.enable_queue:
if auth is not None or app.blocks.encrypt:
if blocks.auth is not None or app.blocks.encrypt:
raise ValueError("Cannot queue with encryption or authentication enabled.")
queueing.init()
app.queue_thread = threading.Thread(
Expand Down
2 changes: 1 addition & 1 deletion gradio/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.9b12
2.9b21
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="gradio",
version="2.9b12",
version="2.9b21",
include_package_data=True,
description="Python library for easily interacting with trained machine learning models",
long_description=long_description,
Expand Down

0 comments on commit 12f2374

Please sign in to comment.