From 65edfd27dc245a13278fbe61077ca2aa9a9d95d2 Mon Sep 17 00:00:00 2001 From: Konie Date: Wed, 25 Oct 2023 12:13:55 +0800 Subject: [PATCH 1/2] Add get and refresh model names apis --- README.md | 12 +++++++- docs/openapi.json | 62 ++++++++++++++++++++++++++++++++++++++++++ fooocus_api_version.py | 2 +- fooocusapi/api.py | 14 +++++++++- fooocusapi/models.py | 7 ++++- 5 files changed, 93 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 468ced8..bdfdd23 100644 --- a/README.md +++ b/README.md @@ -99,4 +99,14 @@ Query async generation request results, return job progress and generation resul #### Query Job Queue Info > GET /v1/generation/job-queue -Query job queue info, include running job count, finished job count and last job id. \ No newline at end of file +Query job queue info, include running job count, finished job count and last job id. + +#### Get All Model Names +> GET /v1/engines/all-models + +Get all filenames of base model and lora. + +#### Refresh Models +> POST /v1/engines/refresh-models + +Refresh local files and get all filenames of base model and lora. \ No newline at end of file diff --git a/docs/openapi.json b/docs/openapi.json index a523ba3..321e03f 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -459,10 +459,72 @@ } } } + }, + "/v1/engines/all-models": { + "get": { + "summary": "All Models", + "description": "Get all filenames of base model and lora", + "operationId": "all_models_v1_engines_all_models_get", + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AllModelNamesResponse" + } + } + } + } + } + } + }, + "/v1/engines/refresh-models": { + "post": { + "summary": "Refresh Models", + "description": "Refresh local files and get all filenames of base model and lora", + "operationId": "refresh_models_v1_engines_refresh_models_post", + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AllModelNamesResponse" + } + } + } + } + } + } } }, "components": { "schemas": { + "AllModelNamesResponse": { + "properties": { + "model_filenames": { + "items": { + "type": "string" + }, + "type": "array", + "title": "Model Filenames" + }, + "lora_filenames": { + "items": { + "type": "string" + }, + "type": "array", + "title": "Lora Filenames" + } + }, + "type": "object", + "required": [ + "model_filenames", + "lora_filenames" + ], + "title": "AllModelNamesResponse" + }, "AspectRatio": { "type": "string", "enum": [ diff --git a/fooocus_api_version.py b/fooocus_api_version.py index 9bc95e8..c3e4772 100644 --- a/fooocus_api_version.py +++ b/fooocus_api_version.py @@ -1 +1 @@ -version = '0.2.2' \ No newline at end of file +version = '0.2.3' \ No newline at end of file diff --git a/fooocusapi/api.py b/fooocusapi/api.py index 851634d..9b4f2ec 100644 --- a/fooocusapi/api.py +++ b/fooocusapi/api.py @@ -3,7 +3,7 @@ from fastapi.params import File import uvicorn from fooocusapi.api_utils import generation_output, req_to_params -from fooocusapi.models import AsyncJobResponse, GeneratedImageBase64, ImgInpaintOrOutpaintRequest, ImgPromptRequest, ImgUpscaleOrVaryRequest, JobQueueInfo, Text2ImgRequest +from fooocusapi.models import AllModelNamesResponse, AsyncJobResponse, GeneratedImageBase64, ImgInpaintOrOutpaintRequest, ImgPromptRequest, ImgUpscaleOrVaryRequest, JobQueueInfo, Text2ImgRequest from fooocusapi.parameters import GenerationFinishReason, ImageGenerationResult from fooocusapi.task_queue import TaskType from fooocusapi.worker import process_generate, task_queue @@ -152,6 +152,18 @@ def job_queue(): return JobQueueInfo(running_size=len(task_queue.queue), finished_size=len(task_queue.history), last_job_id=task_queue.last_seq) +@app.get("/v1/engines/all-models", response_model=AllModelNamesResponse, description="Get all filenames of base model and lora") +def all_models(): + import modules.path as path + return AllModelNamesResponse(model_filenames=path.model_filenames, lora_filenames=path.lora_filenames) + + +@app.post("/v1/engines/refresh-models", response_model=AllModelNamesResponse, description="Refresh local files and get all filenames of base model and lora") +def refresh_models(): + import modules.path as path + path.update_all_model_names() + return AllModelNamesResponse(model_filenames=path.model_filenames, lora_filenames=path.lora_filenames) + def start_app(args): uvicorn.run("fooocusapi.api:app", host=args.host, port=args.port, log_level=args.log_level) diff --git a/fooocusapi/models.py b/fooocusapi/models.py index d432e68..bab55a3 100644 --- a/fooocusapi/models.py +++ b/fooocusapi/models.py @@ -367,4 +367,9 @@ class AsyncJobResponse(BaseModel): class JobQueueInfo(BaseModel): running_size: int = Field(description="The current running and waiting job count") finished_size: int = Field(description="Finished job cound (after auto clean)") - last_job_id: int = Field(description="Last submit generation job id") \ No newline at end of file + last_job_id: int = Field(description="Last submit generation job id") + + +class AllModelNamesResponse(BaseModel): + model_filenames: List[str] + lora_filenames: List[str] \ No newline at end of file From da6d273ccf1db578cad7763a00271e6accfb4a7d Mon Sep 17 00:00:00 2001 From: Konie Date: Wed, 25 Oct 2023 13:44:16 +0800 Subject: [PATCH 2/2] Add get fooocus styles api --- README.md | 5 ++++- docs/openapi.json | 23 +++++++++++++++++++++++ fooocus_api_version.py | 2 +- fooocusapi/api.py | 6 ++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bdfdd23..4236e2c 100644 --- a/README.md +++ b/README.md @@ -109,4 +109,7 @@ Get all filenames of base model and lora. #### Refresh Models > POST /v1/engines/refresh-models -Refresh local files and get all filenames of base model and lora. \ No newline at end of file +#### Get All Fooocus Styles +> GET /v1/engines/styles + +Get all legal Fooocus styles. \ No newline at end of file diff --git a/docs/openapi.json b/docs/openapi.json index 321e03f..0c0d1b6 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -497,6 +497,29 @@ } } } + }, + "/v1/engines/styles": { + "get": { + "summary": "All Styles", + "description": "Get all legal Fooocus styles", + "operationId": "all_styles_v1_engines_styles_get", + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "items": { + "type": "string" + }, + "type": "array", + "title": "Response All Styles V1 Engines Styles Get" + } + } + } + } + } + } } }, "components": { diff --git a/fooocus_api_version.py b/fooocus_api_version.py index c3e4772..cec771e 100644 --- a/fooocus_api_version.py +++ b/fooocus_api_version.py @@ -1 +1 @@ -version = '0.2.3' \ No newline at end of file +version = '0.2.4' \ No newline at end of file diff --git a/fooocusapi/api.py b/fooocusapi/api.py index 9b4f2ec..d5673d6 100644 --- a/fooocusapi/api.py +++ b/fooocusapi/api.py @@ -164,6 +164,12 @@ def refresh_models(): path.update_all_model_names() return AllModelNamesResponse(model_filenames=path.model_filenames, lora_filenames=path.lora_filenames) + +@app.get("/v1/engines/styles", response_model=List[str], description="Get all legal Fooocus styles") +def all_styles(): + from modules.sdxl_styles import legal_style_names + return legal_style_names + def start_app(args): uvicorn.run("fooocusapi.api:app", host=args.host, port=args.port, log_level=args.log_level)