Skip to content

Commit

Permalink
Merge for Fooocus v2.1.25
Browse files Browse the repository at this point in the history
  • Loading branch information
konieshadow committed Oct 9, 2023
1 parent dab7920 commit bde4a9b
Show file tree
Hide file tree
Showing 9 changed files with 752 additions and 429 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Fooocus-API
FastAPI powered API for [Fooocus](https://github.com/lllyasviel/Fooocus)

Currently loaded Fooocus version: 2.0.93
Currently loaded Fooocus version: 2.1.25

### Install dependencies.
Need python version >= 3.10
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.1.9'
version = '0.1.10'
28 changes: 24 additions & 4 deletions fooocusapi/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import List
from fastapi import Depends, FastAPI, File, Header, Query, Response, UploadFile
from typing import List, Optional
from fastapi import Depends, FastAPI, Header, Query, UploadFile
from fastapi.params import File
import uvicorn
from fooocusapi.api_utils import generation_output, narray_to_base64img, narray_to_bytesimg
from fooocusapi.models import GeneratedImageBase64, GenerationFinishReason, ImgInpaintOrOutpaintRequest, ImgUpscaleOrVaryRequest, Text2ImgRequest
from fooocusapi.api_utils import generation_output
from fooocusapi.models import GeneratedImageBase64, ImgInpaintOrOutpaintRequest, ImgPromptRequest, ImgUpscaleOrVaryRequest, Text2ImgRequest
from fooocusapi.task_queue import TaskQueue
from fooocusapi.worker import process_generate

Expand Down Expand Up @@ -82,6 +83,25 @@ def img_inpaint_or_outpaint(input_image: UploadFile, req: ImgInpaintOrOutpaintRe
return generation_output(results, streaming_output)


@app.post("/v1/generation/image-prompt", response_model=List[GeneratedImageBase64], responses=img_generate_responses)
def img_prompt(cn_img1: Optional[UploadFile] = File(None),
req: ImgPromptRequest = Depends(ImgPromptRequest.as_form),
accept: str = Header(None),
accept_query: str | None = Query(None, alias='accept', description="Parameter to overvide 'Accept' header, 'image/png' for output bytes")):
if accept_query is not None and len(accept_query) > 0:
accept = accept_query

if accept == 'image/png':
streaming_output = True
# image_number auto set to 1 in streaming mode
req.image_number = 1
else:
streaming_output = False

results = process_generate(req)
return generation_output(results, streaming_output)


def start_app(args):
uvicorn.run("fooocusapi.api:app", host=args.host,
port=args.port, log_level=args.log_level)
2 changes: 1 addition & 1 deletion fooocusapi/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def read_input_image(input_image: UploadFile) -> np.ndarray:
input_image_bytes = input_image.file.read()
pil_image = Image.open(io.BytesIO(input_image_bytes))
image = np.array(pil_image)
return HWC3(image)
return image


def generation_output(results: List[GeneratedImage], streaming_output: bool) -> Response | List[GeneratedImageBase64]:
Expand Down
Loading

0 comments on commit bde4a9b

Please sign in to comment.