-
Notifications
You must be signed in to change notification settings - Fork 0
/
blockutils.py
86 lines (66 loc) · 2.24 KB
/
blockutils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from enum import IntEnum
from typing import Any, Dict, List
import requests
from abc import ABC, abstractmethod
import socket
from fastapi import WebSocket
BufferSize = 4096
class PackageType(IntEnum):
Login = 0 # Server login request
Verification = 1 # Scheduler return verification
ServerState = 2
Request = 3 # Request size <= Buffer size
RequestHead = 4
# RequestPayload = 5
Response = 5 # Response size <= Buffer size
ResponseHead = 6
# ResponsePayload = 8
PulseCheck = 7 # check the pulse.
class ModelServer:
def __init__(self,
model: str,
wsoc: WebSocket = None,
info: Dict = None) -> None:
self.model = model
self.wsoc = wsoc
self.info = info
def server_register(username: str, password: str, email: str, url: str):
headers = {
'accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
}
data = 'username={}&password={}&re_password={}&email={}'.format(username, password, password, email)
response = requests.post(url, headers=headers, data=data)
return response
def get_token(username: str, password: str, url: str):
headers = {
'accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
}
data = {
'username': username,
'password': password,
}
response = requests.post(url, headers=headers, data=data)
# 如果用户名不存在,这里‘authorization'字段不存在,
return response.headers['authorization']
model_list = [
"Stable Diffution v1.4"
]
model_server_list:Dict[str, List[ModelServer]] = {
"Stable Diffution v1.4": []
}
class RemoteFunction(ABC):
'''
Base class of all gradio remote function in AntGrid.
'''
def __init__(self, username: str = None,
model: str = None,
soc: socket.socket = None) -> None:
self.username = username
self.model = model
self.soc = soc
@abstractmethod
def __call__(self, *args: Any, **kwds: Any) -> Any:
return None
__all__ = ["PackageType", "ModelServer","server_register", "get_token", "model_list"]