randydev commited on
Commit
2ce2da5
1 Parent(s): 20265ba

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +17 -18
main.py CHANGED
@@ -440,36 +440,35 @@ async def tebakgambar_answer():
440
  randydev={"error": "Error fucking"}
441
  )
442
 
443
- @app.get("/akeno/toanime", response_model=SuccessResponse, responses={422: {"model": SuccessResponse}})
444
  async def toanimes(file_path=None):
445
  try:
 
 
 
 
446
  files = {
447
- 'image': ('toanime.jpg', file_path, 'image/jpeg')
448
  }
449
  headers = {"accept": "application/json"}
450
  response = requests.post("https://tools.betabotz.eu.org/ai/toanime", files=files, headers=headers)
451
- if response.status_code == 200:
452
- data = response.json()
453
- res = {
454
- "image_data": data['result'],
455
- "image_size": data['size']
456
- }
457
- return SuccessResponse(
458
- status="True",
459
- randydev={"results": res}
460
- )
461
- else:
462
- return SuccessResponse(
463
- status="False",
464
- randydev={"error": "Identifikasi Gagal"}
465
- )
466
  except Exception:
467
  return SuccessResponse(
468
  status="False",
469
  randydev={"error": "Error during processing"}
470
  )
471
 
472
-
473
  async def api_tools_fix(name, ok, query):
474
  url = f"https://tools.betabotz.eu.org/tools/{name}?{ok}={query}"
475
  response = requests.get(url).json()
 
440
  randydev={"error": "Error fucking"}
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)
450
  files = {
451
+ 'image': ('toanime.jpg', buffer, 'image/jpeg')
452
  }
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'],
460
+ "image_size": data['size']
461
+ }
462
+ return SuccessResponse(
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()