Skip to content

Commit

Permalink
合并拉取请求 #22
Browse files Browse the repository at this point in the history
Remove auth for output endpoint, add API_PORT to specify the API port
  • Loading branch information
mrhan1993 authored Jul 15, 2024
2 parents 3a5dc00 + 019f50b commit 2c19778
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
12 changes: 9 additions & 3 deletions apis/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from apis.routes.generate import secure_router as generate
from apis.routes.query import secure_router as query
from apis.routes.query import router
from apis.utils import file_utils
from apis.utils import api_utils

Expand All @@ -25,6 +26,7 @@

app.include_router(query)
app.include_router(generate)
app.include_router(router)


@app.get("/", tags=["Query"])
Expand All @@ -46,8 +48,12 @@ def run_server(arguments):

os.environ["WEBHOOK_URL"] = arguments.webhook_url
try:
api_port = int(arguments.port) + 1
except TypeError:
api_port = int(os.environ["GRADIO_SERVER_PORT"]) + 1
api_port = int(os.environ['API_PORT'])
except KeyError:
try:
api_port = int(arguments.port) + 1
except TypeError:
api_port = int(os.environ["GRADIO_SERVER_PORT"]) + 1

file_utils.STATIC_SERVER_BASE = f"http://{arguments.base_url}:{api_port}"
uvicorn.run(app, host=arguments.listen, port=api_port)
6 changes: 4 additions & 2 deletions apis/routes/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ async def tasks_info(task_id: str = None):
dependencies=[Depends(api_key_auth)]
)

router = APIRouter()


@secure_router.get("/tasks", tags=["Query"])
async def get_tasks(
Expand Down Expand Up @@ -147,7 +149,7 @@ async def get_task(task_id: str):
return JSONResponse(await tasks_info(task_id))


@secure_router.get("/outputs/{date}/{file_name}", tags=["Query"])
@router.get("/outputs/{date}/{file_name}", tags=["Query"])
async def get_output(date: str, file_name: str, accept: str = Header(None)):
"""
Get a specific output by its ID.
Expand All @@ -172,7 +174,7 @@ async def get_output(date: str, file_name: str, accept: str = Header(None)):
return Response(content=img, media_type=f"image/{ext}")


@secure_router.get("/inputs/{file_name}", tags=["Query"])
@router.get("/inputs/{file_name}", tags=["Query"])
async def get_input(file_name: str, accept: str = Header(None)):
"""
Get a specific input by its ID.
Expand Down
4 changes: 3 additions & 1 deletion docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ FastAPI 是一个现代、快速(高性能)的Web框架,用于构建APIs

和 Fooocus 相同的启动方式,使用 `--nowebui` 参数可以启动 API 而不启动 WebUI。

默认的 API 端口是 WebUI 端口加 1,即 7866,使用 `--port` 修改 WebUI 端口将同时修改 API 端口。
默认的 API 端口是 WebUI 端口加 1,即 7866

环境变量 API_PORT 用于指定 API 端口,优先级高于默认设置。

同时启动 WebUI 和 API 示例:

Expand Down
10 changes: 6 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ advantage:
- Use X-API-KEY for authentication
- all-in-one interface
- use URL provide INPUT image
- streaming output, binary image, asynchronous task and syncronous task support
- streaming output, binary image, asynchronous task and synchronous task support
- persistent task history
- enhanced task history management
- task query function
Expand All @@ -48,7 +48,9 @@ Based on Fooocus, there are several dependencies, so you can install it in the s

Same as Fooocus, use `--apikey` to specify the API authentication key.

Default API port is WebUI port plus 1, that is 7866, use `--port` to modify WebUI port to modify API port at the same time.
Default API port is WebUI port plus 1, that is 7866, use `--port` to modify WebUI port

Environment variable API_PORT is used to specify the API port. It takes precedence over the default setting.

example for WebUI and API:

Expand Down Expand Up @@ -103,10 +105,10 @@ In addition, some API-specific parameters are also included:
- `preset`, You can use this parameter to specify a preset that takes precedence over the global default and below the passed parameter, but if the passed parameter is equal to the default value, the preset parameter is used
- `stream_output`, true for streaming output, default false
- `require_base64`, not used
- `async_process`, async task, default false, a syncronous task will be returned when `stream_output` is false at the same time
- `async_process`, async task, default false, a synchronous task will be returned when `stream_output` is false at the same time
- `webhook_url`, Webhook addr, if set, the task will be sent to the address after the task is completed.

> `stream_output` has a higher priority than `async_process`, that is, when both are `true`, return streaming output. When all are false, task will be syncronously returned. when you set Accepet: image/xxx in the request header, the response will be a binary image
> `stream_output` has a higher priority than `async_process`, that is, when both are `true`, return streaming output. When all are false, task will be synchronously returned. when you set `Accept: image/xxx` in the request header, the response will be a binary image
### Stop or Skip

Expand Down

0 comments on commit 2c19778

Please sign in to comment.