randydev commited on
Commit
d0d9591
1 Parent(s): 206e6f2

Update fluxai.py

Browse files
Files changed (1) hide show
  1. fluxai.py +11 -11
fluxai.py CHANGED
@@ -13,7 +13,7 @@ from models import *
13
  class FluxAI(BaseModel):
14
  user_id: int
15
  args: str
16
- auto_enhancer: bool
17
 
18
  router = APIRouter()
19
 
@@ -65,16 +65,16 @@ async def fluxai_image(payload: FluxAI):
65
  )
66
 
67
  if payload.enhancer:
68
- image = Image.open(io.BytesIO(image_bytes))
69
- enhancer = ImageEnhance.Sharpness(image)
70
- image = enhancer.enhance(1.5)
71
- enhancer = ImageEnhance.Contrast(image)
72
- image = enhancer.enhance(1.2)
73
- enhancer = ImageEnhance.Color(image)
74
- image = enhancer.enhance(1.1)
75
- enhanced_image_bytes = io.BytesIO()
76
- image.save(enhanced_image_bytes, format="JPEG", quality=95)
77
- enhanced_image_bytes.seek(0)
78
  return StreamingResponse(enhanced_image_bytes, media_type="image/jpeg")
79
  else:
80
  return StreamingResponse(io.BytesIO(image_bytes), media_type="image/jpeg")
 
13
  class FluxAI(BaseModel):
14
  user_id: int
15
  args: str
16
+ auto_enhancer: bool = False
17
 
18
  router = APIRouter()
19
 
 
65
  )
66
 
67
  if payload.enhancer:
68
+ with Image.open(io.BytesIO(image_bytes)) as image:
69
+ enhancer = ImageEnhance.Sharpness(image)
70
+ image = enhancer.enhance(1.5)
71
+ enhancer = ImageEnhance.Contrast(image)
72
+ image = enhancer.enhance(1.2)
73
+ enhancer = ImageEnhance.Color(image)
74
+ image = enhancer.enhance(1.1)
75
+ enhanced_image_bytes = io.BytesIO()
76
+ image.save(enhanced_image_bytes, format="JPEG", quality=95)
77
+ enhanced_image_bytes.seek(0)
78
  return StreamingResponse(enhanced_image_bytes, media_type="image/jpeg")
79
  else:
80
  return StreamingResponse(io.BytesIO(image_bytes), media_type="image/jpeg")