Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite reload loop when gradio mounted as a sub application #2477

Merged
merged 2 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ gr.Interface(iteration,
* Fixed videos being mirrored in the front-end if source is not webcam by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2475](https://github.com/gradio-app/gradio/pull/2475)
* Add clear button for timeseries component [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 2487](https://github.com/gradio-app/gradio/pull/2487)
* Removes special characters from temporary filenames so that the files can be served by components [@abidlabs](https://github.com/abidlabs) in [PR 2480](https://github.com/gradio-app/gradio/pull/2480)
* Fixed infinite reload loop when mounting gradio as a sub application by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2477](https://github.com/gradio-app/gradio/pull/2477)

## Documentation Changes:
* Adds a demo to show how a sound alert can be played upon completion of a prediction by [@abidlabs](https://github.com/abidlabs) in [PR 2478](https://github.com/gradio-app/gradio/pull/2478)
Expand Down
3 changes: 2 additions & 1 deletion gradio/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,8 @@ def read_main():
app = gr.mount_gradio_app(app, io, path="/gradio")
# Then run `uvicorn run:app` from the terminal and navigate to http://localhost:8000/gradio.
"""

blocks.dev_mode = False
blocks.config = blocks.get_config_file()
gradio_app = App.create_app(blocks)

@app.on_event("startup")
Expand Down
19 changes: 19 additions & 0 deletions test/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from unittest.mock import patch

import pytest
import starlette.routing
import websockets
from fastapi import FastAPI
from fastapi.testclient import TestClient

import gradio
from gradio import Blocks, Interface, Textbox, close_all, routes

os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
Expand Down Expand Up @@ -260,5 +262,22 @@ def test_get_server_url_from_ws_url(ws_url, answer):
assert routes.get_server_url_from_ws_url(ws_url) == answer


def test_mount_gradio_app_set_dev_mode_false():
app = FastAPI()

@app.get("/")
def read_main():
return {"message": "Hello!"}

with gradio.Blocks() as blocks:
gradio.Textbox("Hello from gradio!")

app = routes.mount_gradio_app(app, blocks, path="/gradio")
gradio_fast_api = next(
route for route in app.routes if isinstance(route, starlette.routing.Mount)
)
assert not gradio_fast_api.app.blocks.dev_mode


if __name__ == "__main__":
unittest.main()