Skip to content

Commit

Permalink
Add get and refresh model names apis
Browse files Browse the repository at this point in the history
  • Loading branch information
konieshadow committed Oct 25, 2023
1 parent a795b21 commit 65edfd2
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.
62 changes: 62 additions & 0 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion fooocus_api_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '0.2.2'
version = '0.2.3'
14 changes: 13 additions & 1 deletion fooocusapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
7 changes: 6 additions & 1 deletion fooocusapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
last_job_id: int = Field(description="Last submit generation job id")


class AllModelNamesResponse(BaseModel):
model_filenames: List[str]
lora_filenames: List[str]

0 comments on commit 65edfd2

Please sign in to comment.