From 691895b3860b1f3aa323d430cd52aab27bef1836 Mon Sep 17 00:00:00 2001 From: zhzluke96 Date: Tue, 11 Jun 2024 22:46:48 +0800 Subject: [PATCH 1/4] Fix request serialization for fastapi `/docs` --- gradio/data_classes.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gradio/data_classes.py b/gradio/data_classes.py index f43e15073068d..0e20289fd0ec3 100644 --- a/gradio/data_classes.py +++ b/gradio/data_classes.py @@ -110,6 +110,24 @@ class PredictBody(BaseModel): None # dictionary of request headers, query parameters, url, etc. (used to to pass in request for queuing) ) + def __get_pydantic_json_schema__(self, source_type: Any, handler): + return { + "title": "PredictBody", + "type": "object", + "properties": { + "session_hash": {"type": "string"}, + "event_id": {"type": "string"}, + "data": {"type": "array", "items": {"type": "object"}}, + "event_data": {"type": "object"}, + "fn_index": {"type": "integer"}, + "trigger_id": {"type": "integer"}, + "simple_format": {"type": "boolean"}, + "batched": {"type": "boolean"}, + "request": {"type": "object"}, + }, + "required": ["data"], + } + class ResetBody(BaseModel): event_id: str From 28a8e5368840dfe7520b1a6ebe2fc3d8baf68ed8 Mon Sep 17 00:00:00 2001 From: zhzluke96 Date: Wed, 12 Jun 2024 02:18:50 +0800 Subject: [PATCH 2/4] fix issues identified in code review --- gradio/data_classes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gradio/data_classes.py b/gradio/data_classes.py index 0e20289fd0ec3..2ec18bb800e46 100644 --- a/gradio/data_classes.py +++ b/gradio/data_classes.py @@ -110,7 +110,8 @@ class PredictBody(BaseModel): None # dictionary of request headers, query parameters, url, etc. (used to to pass in request for queuing) ) - def __get_pydantic_json_schema__(self, source_type: Any, handler): + @classmethod + def __get_pydantic_json_schema__(cls, core_schema, handler): return { "title": "PredictBody", "type": "object", From 690374f6958508380e0f5da8c7dfde50bce030d4 Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Tue, 11 Jun 2024 15:10:30 -0400 Subject: [PATCH 3/4] unit test --- test/test_routes.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test_routes.py b/test/test_routes.py index e6219dcf981b8..282f71068fd39 100644 --- a/test/test_routes.py +++ b/test/test_routes.py @@ -1320,3 +1320,19 @@ def test_max_file_size_used_in_upload_route(connect): with open("test/test_files/alphabet.txt", "rb") as f: r = test_client.post("/upload", files={"files": f}) assert r.status_code == 200 + + +def test_docs_url(): + with gr.Blocks() as demo: + num = gr.Number(value=0) + button = gr.Button() + button.click(lambda n: n + 1, [num], [num]) + + app, _, _ = demo.launch(app_kwargs={"docs_url": "/docs"}, prevent_thread_lock=True) + try: + test_client = TestClient(app) + with test_client: + r = test_client.get("/docs") + assert r.status_code == 200 + finally: + demo.close() From c841ac8484eb4d18ef185ee583c75f4a6ff73b1e Mon Sep 17 00:00:00 2001 From: gradio-pr-bot Date: Tue, 11 Jun 2024 19:11:24 +0000 Subject: [PATCH 4/4] add changeset --- .changeset/dull-lizards-suffer.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dull-lizards-suffer.md diff --git a/.changeset/dull-lizards-suffer.md b/.changeset/dull-lizards-suffer.md new file mode 100644 index 0000000000000..da6c114179d08 --- /dev/null +++ b/.changeset/dull-lizards-suffer.md @@ -0,0 +1,5 @@ +--- +"gradio": patch +--- + +fix:Fix request serialization for fastapi `/docs`