diff --git a/gradio/blocks.py b/gradio/blocks.py index 33ca88b31b6cb..991c7324d3179 100644 --- a/gradio/blocks.py +++ b/gradio/blocks.py @@ -99,8 +99,6 @@ if TYPE_CHECKING: # Only import for type checking (is False at runtime). - from fastapi.applications import FastAPI - from gradio.components.base import Component from gradio.renderable import Renderable @@ -2227,7 +2225,7 @@ def launch( _frontend: bool = True, enable_monitoring: bool | None = None, strict_cors: bool = True, - ) -> tuple[FastAPI, str, str]: + ) -> tuple[routes.App, str, str]: """ Launches a simple web server that serves the demo. Can also be used to create a public link used by anyone to access the demo from their browser by setting share=True. diff --git a/test/test_routes.py b/test/test_routes.py index 19162a4a40bcc..ff51880f76e12 100644 --- a/test/test_routes.py +++ b/test/test_routes.py @@ -273,10 +273,18 @@ def test_response_attachment_format(self): app, _, _ = io.launch( prevent_thread_lock=True, allowed_paths=[ - os.path.dirname(image_file.name), - os.path.dirname(html_file.name), + image_file.name, + html_file.name, ], ) + + html_file2 = tempfile.NamedTemporaryFile( + mode="w", delete=False, suffix=".html", dir=app.uploaded_file_dir + ) + html_file2.write("Hello, world!") + html_file2.flush() + html_file2_name = str(Path(app.uploaded_file_dir) / html_file2.name) + client = TestClient(app) file_response = client.get(f"{API_PREFIX}/file={image_file.name}") @@ -284,6 +292,10 @@ def test_response_attachment_format(self): assert "inline" in file_response.headers["Content-Disposition"] file_response = client.get(f"{API_PREFIX}/file={html_file.name}") + assert file_response.headers["Content-Type"] == "text/html; charset=utf-8" + assert "inline" in file_response.headers["Content-Disposition"] + + file_response = client.get(f"{API_PREFIX}/file={html_file2_name}") assert file_response.headers["Content-Type"] == "application/octet-stream" assert "attachment" in file_response.headers["Content-Disposition"]