-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
34 lines (28 loc) · 1.28 KB
/
utils.py
File metadata and controls
34 lines (28 loc) · 1.28 KB
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
from enum import Enum
import httpx
class ModelName(str, Enum):
distilbert = "distilbert-base-cased"
roberta = "roberta-base-squad2"
google = "google-bert"
electra_large_discriminator = "electra_large_discriminator"
class ResponseData:
status_code: int
content: dict
def __init__(this):
this.status_code = -1
this.content = {}
API_URL = {
'distilbert-base-cased' : "https://api-inference.huggingface.co/models/distilbert/distilbert-base-cased-distilled-squad",
'roberta-base-squad2' : "https://api-inference.huggingface.co/models/deepset/roberta-base-squad2",
'google-bert' : "https://api-inference.huggingface.co/models/google-bert/bert-large-uncased-whole-word-masking-finetuned-squad",
'electra_large_discriminator': "https://api-inference.huggingface.co/models/ahotrod/electra_large_discriminator_squad2_512"
}
def selectModel(model: ModelName)->str:
return API_URL[model.value]
async def send_rest_api_req(payload: dict, headers: dict, api_url: str)->ResponseData:
async with httpx.AsyncClient() as client:
response = await client.post(headers= headers, url = api_url, json= payload)
data = ResponseData()
data.status_code = response.status_code
data.content = response.json()
return data