-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_client.py
30 lines (27 loc) · 1014 Bytes
/
api_client.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
import urllib3
http_client = urllib3.PoolManager(
retries=urllib3.Retry(
connect=5,
read=2,
redirect=5,
status_forcelist=[429, 500, 501, 502, 503, 504],
backoff_factor=0.2,
),
timeout=urllib3.Timeout(connect=5.0, read=120.0),
num_pools=10,
)
def summarize(text):
_min = min(max(int(len(text)/100*8), 10), 200)
_max = min(max(int(len(text)/100*12), 50), 400)
if _min > _max:
_min, _max = _max, _min
fields= {
'min_length': _min,
'max_length': _max,
'text': text
}
print(f"{_min} - {_max}")
_request = http_client.request(method='POST', url='http://localhost:8001/v1/summarize/', fields=fields)
print(f"{text} summary generation {_request.status} finished in {_request.headers.get('x-process-time')} seconds, summary:")
return _request.data.decode("utf-8")
print(summarize('This is the text to summarize'))