mirror of
https://github.com/azaion/ai-training.git
synced 2026-04-22 22:26:36 +00:00
upload model to cdn and api
switch to yolov11
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import io
|
||||
import requests
|
||||
|
||||
|
||||
class ApiCredentials:
|
||||
def __init__(self, url, email, password, folder):
|
||||
self.url = url
|
||||
self.email = email
|
||||
self.password = password
|
||||
self.folder = folder
|
||||
|
||||
|
||||
class Api:
|
||||
def __init__(self, credentials):
|
||||
self.token = None
|
||||
self.credentials = credentials
|
||||
|
||||
def login(self):
|
||||
response = requests.post(f'{self.credentials.url}/login',
|
||||
json={"email": self.credentials.email, "password": self.credentials.password})
|
||||
response.raise_for_status()
|
||||
token = response.json()["token"]
|
||||
self.token = token
|
||||
|
||||
def upload_file(self, filename: str, file_bytes: bytearray):
|
||||
folder = self.credentials.folder
|
||||
if self.token is None:
|
||||
self.login()
|
||||
url = f"{self.credentials.url}/resources/{folder}"
|
||||
headers = {"Authorization": f"Bearer {self.token}"}
|
||||
files = {'data': (filename, io.BytesIO(file_bytes))}
|
||||
try:
|
||||
r = requests.post(url, headers=headers, files=files, allow_redirects=True)
|
||||
r.raise_for_status()
|
||||
print(f"Upload {len(file_bytes)} bytes ({filename}) to {self.credentials.url}. Result: {r.status_code}")
|
||||
except Exception as e:
|
||||
print(f"Upload fail: {e}")
|
||||
Reference in New Issue
Block a user