mirror of
https://github.com/azaion/detections.git
synced 2026-06-23 15:41:09 +00:00
Add AIAvailabilityStatus and AIRecognitionConfig classes for AI model management
- Introduced `AIAvailabilityStatus` class to manage the availability status of AI models, including methods for setting status and logging messages. - Added `AIRecognitionConfig` class to encapsulate configuration parameters for AI recognition, with a static method for creating instances from dictionaries. - Implemented enums for AI availability states to enhance clarity and maintainability. - Updated related Cython files to support the new classes and ensure proper type handling. These changes aim to improve the structure and functionality of the AI model management system, facilitating better status tracking and configuration handling.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import requests
|
||||
from loguru import logger
|
||||
|
||||
HTTP_TIMEOUT = 120
|
||||
|
||||
|
||||
cdef class LoadResult:
|
||||
def __init__(self, err, data=None):
|
||||
self.err = err
|
||||
self.data = data
|
||||
|
||||
|
||||
cdef class LoaderHttpClient:
|
||||
def __init__(self, base_url: str):
|
||||
self.base_url = base_url.rstrip("/")
|
||||
|
||||
cdef LoadResult load_big_small_resource(self, str filename, str directory):
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{self.base_url}/load/{filename}",
|
||||
json={"filename": filename, "folder": directory},
|
||||
stream=True,
|
||||
timeout=HTTP_TIMEOUT,
|
||||
)
|
||||
response.raise_for_status()
|
||||
return LoadResult(None, response.content)
|
||||
except Exception as e:
|
||||
logger.error(f"LoaderHttpClient.load_big_small_resource failed: {e}")
|
||||
return LoadResult(str(e))
|
||||
|
||||
cdef LoadResult upload_big_small_resource(self, bytes content, str filename, str directory):
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{self.base_url}/upload/{filename}",
|
||||
files={"data": (filename, content)},
|
||||
data={"folder": directory},
|
||||
timeout=HTTP_TIMEOUT,
|
||||
)
|
||||
response.raise_for_status()
|
||||
return LoadResult(None)
|
||||
except Exception as e:
|
||||
logger.error(f"LoaderHttpClient.upload_big_small_resource failed: {e}")
|
||||
return LoadResult(str(e))
|
||||
Reference in New Issue
Block a user