Sharing fix for assets (#1208)

* changes

* format

* typo

* updated PyPi version to 2.9b33

* Update PKG-INFO

* removed

* formatting

* fixes

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
aliabid94 2022-05-11 16:27:58 -07:00 committed by GitHub
parent a88c017f87
commit c50a2b021a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 19 deletions

View File

@ -10,7 +10,7 @@ Keywords: machine learning,visualization,reproducibility
Platform: UNKNOWN
Description-Content-Type: text/markdown
License-File: LICENSE
[![CircleCI](https://circleci.com/gh/gradio-app/gradio.svg?style=svg)](https://circleci.com/gh/gradio-app/gradio) [![PyPI version](https://badge.fury.io/py/gradio.svg)](https://badge.fury.io/py/gradio) [![codecov](https://codecov.io/gh/gradio-app/gradio/branch/master/graph/badge.svg?token=NNVPX9KEGS)](https://codecov.io/gh/gradio-app/gradio) [![PyPI - Downloads](https://img.shields.io/pypi/dm/gradio)](https://pypi.org/project/gradio/) [![Twitter Follow](https://img.shields.io/twitter/follow/gradio.svg?style=social&label=Follow)](https://twitter.com/gradio)
# Welcome to Gradio

View File

@ -33,12 +33,6 @@ BUILD_PATH_LIB = pkg_resources.resource_filename("gradio", "templates/frontend/a
VERSION_FILE = pkg_resources.resource_filename("gradio", "version.txt")
with open(VERSION_FILE) as version_file:
VERSION = version_file.read()
GRADIO_STATIC_ROOT = "https://gradio.s3-us-west-2.amazonaws.com/{}/static/".format(
VERSION
)
GRADIO_BUILD_ROOT = "https://gradio.s3-us-west-2.amazonaws.com/{}/assets/".format(
VERSION
)
class ORJSONResponse(JSONResponse):
@ -98,6 +92,7 @@ class App(FastAPI):
self.auth = auth
else:
self.auth = None
self.blocks = blocks
self.cwd = os.getcwd()
self.favicon_path = blocks.favicon_path
@ -151,7 +146,6 @@ class App(FastAPI):
response = RedirectResponse(url="/", status_code=status.HTTP_302_FOUND)
response.set_cookie(key="access-token", value=token, httponly=True)
return response
else:
raise HTTPException(status_code=400, detail="Incorrect credentials.")
@ -171,8 +165,11 @@ class App(FastAPI):
}
try:
template = (
"frontend/share.html" if app.blocks.share else "frontend/index.html"
)
return templates.TemplateResponse(
"frontend/index.html", {"request": request, "config": config}
template, {"request": request, "config": config}
)
except TemplateNotFound:
raise ValueError(
@ -187,20 +184,14 @@ class App(FastAPI):
@app.get("/static/{path:path}")
def static_resource(path: str):
if app.blocks.share:
return RedirectResponse(GRADIO_STATIC_ROOT + path)
else:
static_file = safe_join(STATIC_PATH_LIB, path)
static_file = safe_join(STATIC_PATH_LIB, path)
if static_file is not None:
return FileResponse(static_file)
raise HTTPException(status_code=404, detail="Static file not found")
@app.get("/assets/{path:path}")
def build_resource(path: str):
if app.blocks.share:
return RedirectResponse(GRADIO_BUILD_ROOT + path)
else:
build_file = safe_join(BUILD_PATH_LIB, path)
build_file = safe_join(BUILD_PATH_LIB, path)
if build_file is not None:
return FileResponse(build_file)
raise HTTPException(status_code=404, detail="Build file not found")

View File

@ -1 +1 @@
2.9b26
2.9b33

View File

@ -20,6 +20,9 @@ else
pnpm build
cd ..
aws s3 cp gradio/templates/frontend s3://gradio/$new_version/ --recursive # requires aws cli (contact maintainers for credentials)
cp gradio/templates/frontend/index.html gradio/templates/frontend/share.html
assets_link="https://gradio.s3-us-west-2.amazonaws.com/$new_version/assets"
sed -i -e "s#\./assets#${assets_link}#g" gradio/templates/frontend/share.html
fi
rm -r dist/*
rm -r build/*

View File

@ -127,7 +127,7 @@ class TestInterface(unittest.TestCase):
interface = Interface(lambda x: x, "textbox", "label")
interface.launch(inline=True, prevent_thread_lock=True)
mock_display.assert_called_once()
interface.launch(inline=True, share=True, prevent_thread_lock=True)
interface.launch(inline=True, prevent_thread_lock=True)
self.assertEqual(mock_display.call_count, 2)
interface.close()