randydev commited on
Commit
2b4bb2f
·
verified ·
1 Parent(s): ab40556

Update fluxai.py

Browse files
Files changed (1) hide show
  1. fluxai.py +8 -12
fluxai.py CHANGED
@@ -115,7 +115,7 @@ def get_all_api_keys():
115
  return api_keys
116
 
117
  @router.post("/akeno/fluxai", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
118
- async def fluxai_image(payload: FluxAI, file: UploadFile):
119
  if deduct_tokens_gpt(payload.user_id, amount=20):
120
  USERS_API_KEYS = get_all_api_keys()
121
  if payload.api_key in USERS_API_KEYS:
@@ -134,22 +134,18 @@ async def fluxai_image(payload: FluxAI, file: UploadFile):
134
  image = enhancer.enhance(1.2)
135
  enhancer = ImageEnhance.Color(image)
136
  image = enhancer.enhance(1.1)
137
- enhanced_image_bytes = io.BytesIO()
 
138
  image.save(enhanced_image_bytes, format="JPEG", quality=95)
139
- enhanced_image_bytes.seek(0)
140
- ext = file.filename.split(".")[-1]
141
- unique_filename = f"{uuid.uuid4().hex}.{ext}"
142
- file_path = os.path.join("uploads", unique_filename)
143
- os.makedirs(os.path.dirname(file_path), exist_ok=True)
144
- with open(file_path, "wb") as f:
145
- f.write(enhanced_image_bytes.getvalue())
146
  example_test = "Accurately identify the baked good in the image and provide an appropriate and recipe consistent with your analysis."
147
  x = GeminiLatest(api_keys=GOOGLE_API_KEY)
148
- response = x.get_response_image(example_test, file_path)
149
- url = f"https://randydev-ryuzaki-api.hf.space/{file_path}"
150
  return SuccessResponse(
151
  status="True",
152
- randydev={"url": url, "caption": response}
153
  )
154
  else:
155
  return StreamingResponse(io.BytesIO(image_bytes), media_type="image/jpeg")
 
115
  return api_keys
116
 
117
  @router.post("/akeno/fluxai", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
118
+ async def fluxai_image(payload: FluxAI):
119
  if deduct_tokens_gpt(payload.user_id, amount=20):
120
  USERS_API_KEYS = get_all_api_keys()
121
  if payload.api_key in USERS_API_KEYS:
 
134
  image = enhancer.enhance(1.2)
135
  enhancer = ImageEnhance.Color(image)
136
  image = enhancer.enhance(1.1)
137
+
138
+ enhanced_image_bytes = "akeno.jpg"
139
  image.save(enhanced_image_bytes, format="JPEG", quality=95)
140
+ with open(enhanced_image_bytes, "rb") as image_file:
141
+ encoded_string = base64.b64encode(image_file.read())
142
+
 
 
 
 
143
  example_test = "Accurately identify the baked good in the image and provide an appropriate and recipe consistent with your analysis."
144
  x = GeminiLatest(api_keys=GOOGLE_API_KEY)
145
+ response = x.get_response_image(example_test, enhanced_image_bytes)
 
146
  return SuccessResponse(
147
  status="True",
148
+ randydev={"image_data": encoded_string, "caption": response}
149
  )
150
  else:
151
  return StreamingResponse(io.BytesIO(image_bytes), media_type="image/jpeg")