randydev commited on
Commit
68a9051
1 Parent(s): 2ce2da5

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -5
main.py CHANGED
@@ -441,9 +441,9 @@ async def tebakgambar_answer():
441
  )
442
 
443
  @app.post("/akeno/toanime", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
444
- async def toanimes(file_path=None):
445
  try:
446
- image = Image.open(file_path)
447
  buffer = io.BytesIO()
448
  image.save(buffer, format='JPEG')
449
  buffer.seek(0)
@@ -453,7 +453,10 @@ async def toanimes(file_path=None):
453
  headers = {"accept": "application/json"}
454
  response = requests.post("https://tools.betabotz.eu.org/ai/toanime", files=files, headers=headers)
455
  if response.status_code != 200:
456
- return None
 
 
 
457
  data = response.json()
458
  res = {
459
  "image_data": data['result'],
@@ -463,12 +466,13 @@ async def toanimes(file_path=None):
463
  status="True",
464
  randydev={"results": res}
465
  )
466
- except Exception:
467
  return SuccessResponse(
468
  status="False",
469
- randydev={"error": "Error during processing"}
470
  )
471
 
 
472
  async def api_tools_fix(name, ok, query):
473
  url = f"https://tools.betabotz.eu.org/tools/{name}?{ok}={query}"
474
  response = requests.get(url).json()
 
441
  )
442
 
443
  @app.post("/akeno/toanime", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
444
+ async def toanimes_(file: UploadFile = File(...)):
445
  try:
446
+ image = Image.open(io.BytesIO(await file.read()))
447
  buffer = io.BytesIO()
448
  image.save(buffer, format='JPEG')
449
  buffer.seek(0)
 
453
  headers = {"accept": "application/json"}
454
  response = requests.post("https://tools.betabotz.eu.org/ai/toanime", files=files, headers=headers)
455
  if response.status_code != 200:
456
+ return SuccessResponse(
457
+ status="False",
458
+ randydev={"error": "Failed to process the image"}
459
+ )
460
  data = response.json()
461
  res = {
462
  "image_data": data['result'],
 
466
  status="True",
467
  randydev={"results": res}
468
  )
469
+ except Exception as e:
470
  return SuccessResponse(
471
  status="False",
472
+ randydev={"error": f"Error during processing: {str(e)}"}
473
  )
474
 
475
+
476
  async def api_tools_fix(name, ok, query):
477
  url = f"https://tools.betabotz.eu.org/tools/{name}?{ok}={query}"
478
  response = requests.get(url).json()