randydev commited on
Commit
5270826
1 Parent(s): feee7ef

Upload fluxai.py

Browse files
Files changed (1) hide show
  1. fluxai.py +16 -3
fluxai.py CHANGED
@@ -1,5 +1,6 @@
1
  from fastapi import APIRouter, Depends
2
  from fastapi.responses import StreamingResponse
 
3
  import io
4
  import requests
5
  import os
@@ -10,7 +11,8 @@ from models import *
10
 
11
  class FluxAI(BaseModel):
12
  user_id: int
13
- args: str
 
14
 
15
  router = APIRouter()
16
 
@@ -59,8 +61,19 @@ async def fluxai_image(payload: FluxAI):
59
  status="False",
60
  randydev={"error": "Failed to generate an image"}
61
  )
62
-
63
- return StreamingResponse(io.BytesIO(image_bytes), media_type="image/jpeg")
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  except Exception as e:
66
  return SuccessResponse(
 
1
  from fastapi import APIRouter, Depends
2
  from fastapi.responses import StreamingResponse
3
+ from PIL import Image, ImageEnhance
4
  import io
5
  import requests
6
  import os
 
11
 
12
  class FluxAI(BaseModel):
13
  user_id: int
14
+ args: str,
15
+ auto_enhancer: bool
16
 
17
  router = APIRouter()
18
 
 
61
  status="False",
62
  randydev={"error": "Failed to generate an image"}
63
  )
64
+ if payload.enhancer:
65
+ image = Image.open(io.BytesIO(image_bytes))
66
+ enhancer = ImageEnhance.Sharpness(image)
67
+ image = enhancer.enhance(1.5)
68
+ enhancer = ImageEnhance.Contrast(image)
69
+ image = enhancer.enhance(1.2)
70
+ enhancer = ImageEnhance.Color(image)
71
+ image = enhancer.enhance(1.1)
72
+ file_path = "response_image.jpg"
73
+ image.save(file_path, quality=95)
74
+ return StreamingResponse(file_path, media_type="image/jpeg")
75
+ else:
76
+ return StreamingResponse(io.BytesIO(image_bytes), media_type="image/jpeg")
77
 
78
  except Exception as e:
79
  return SuccessResponse(