mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
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:
parent
a88c017f87
commit
c50a2b021a
@ -10,7 +10,7 @@ Keywords: machine learning,visualization,reproducibility
|
||||
Platform: UNKNOWN
|
||||
Description-Content-Type: text/markdown
|
||||
License-File: LICENSE
|
||||
|
||||
|
||||
[](https://circleci.com/gh/gradio-app/gradio) [](https://badge.fury.io/py/gradio) [](https://codecov.io/gh/gradio-app/gradio) [](https://pypi.org/project/gradio/) [](https://twitter.com/gradio)
|
||||
|
||||
# Welcome to Gradio
|
||||
|
@ -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")
|
||||
|
@ -1 +1 @@
|
||||
2.9b26
|
||||
2.9b33
|
||||
|
@ -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/*
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user