top001 commited on
Commit
42f5a78
·
verified ·
1 Parent(s): c71ddef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -10,7 +10,7 @@ from PIL import Image
10
  from huggingface_hub import hf_hub_download
11
  import io
12
 
13
- from fastapi import FastAPI, File, UploadFile
14
  from fastapi.responses import JSONResponse
15
  import uvicorn
16
 
@@ -94,14 +94,18 @@ def image_to_deepdanbooru_tags(
94
 
95
  return output_text, filtered_tags
96
 
 
 
97
  @app.post("/tagging")
98
- async def tagging_endpoint(image: UploadFile = File(...)):
 
 
 
99
  image_data = await image.read()
100
  pil_image = Image.open(io.BytesIO(image_data)).convert("RGB")
101
- # Use default parameters or customize as needed
102
  output_text, filtered_tags = image_to_deepdanbooru_tags(
103
  pil_image,
104
- threshold=0.5,
105
  use_spaces=False,
106
  use_escape=False,
107
  include_ranks=False,
 
10
  from huggingface_hub import hf_hub_download
11
  import io
12
 
13
+ from fastapi import FastAPI, File, UploadFile, Form
14
  from fastapi.responses import JSONResponse
15
  import uvicorn
16
 
 
94
 
95
  return output_text, filtered_tags
96
 
97
+ from typing import Optional
98
+
99
  @app.post("/tagging")
100
+ async def tagging_endpoint(
101
+ image: UploadFile = File(...),
102
+ threshold: Optional[float] = Form(0.5)
103
+ ):
104
  image_data = await image.read()
105
  pil_image = Image.open(io.BytesIO(image_data)).convert("RGB")
 
106
  output_text, filtered_tags = image_to_deepdanbooru_tags(
107
  pil_image,
108
+ threshold=threshold,
109
  use_spaces=False,
110
  use_escape=False,
111
  include_ranks=False,