Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test(self, *_):
result = request("http://foo", "foo")
self.assertEqual(result, "bar")
img_base64 = base64.b64encode(f.read()).decode('ascii')
endpoint = args.endpoint
bboxes = []
for b in args.face_bb:
b = [int(x) for x in b.split(',')]
assert len(b) == 4
bboxes.append(dict(x=b[0], y=b[1], w=b[2], h=b[3]))
params = {"image": img_base64, "faces": bboxes}
if args.snet:
endpoint, job_address, job_signature = snet_setup(service_name="face_recognition")
params['job_address'] = job_address
params['job_signature'] = job_signature
response = jsonrpcclient.request(endpoint, "recognise_face", **params)
if args.out_image:
import numpy as np
from matplotlib import pyplot as plt
for idx, identity in enumerate(response['face_identities']):
face_a = np.array(identity)
out_fn = "stem_identity_" + str(idx) + "_" + args.out_image
x = np.linspace(0, face_a.shape[0], face_a.shape[0], endpoint=False)
plt.figure(figsize=(10, 5))
extent = 0.4
plt.ylim(-extent, extent)
markerline, stemlines, baseline = plt.stem(x, face_a)
plt.setp(baseline, color='r', linewidth=2)
plt.savefig(out_fn)
img_base64 = base64.b64encode(f.read()).decode('ascii')
endpoint = args.endpoint
bboxes = []
for b in args.face_bb:
b = [int(x) for x in b.split(',')]
assert len(b) == 4
bboxes.append(dict(x=b[0], y=b[1], w=b[2], h=b[3]))
params = {'landmark_model': args.model, "image": img_base64, "face_bboxes": bboxes}
if args.snet:
endpoint, job_address, job_signature = snet_setup(service_name="face_landmarks")
params['job_address'] = job_address
params['job_signature'] = job_signature
response = jsonrpcclient.request(endpoint, "get_landmarks", **params)
if args.out_image:
import cv2
import numpy as np
print("Rendering landmarks and saving to {}".format(args.out_image))
image = cv2.imread(args.image)
for l in response['landmarks']:
landmarks = np.matrix([[p['x'], p['y']] for p in l['points']])
for idx, point in enumerate(landmarks):
pos = (point[0, 0], point[0, 1])
# annotate the positions
cv2.putText(image, str(idx), pos,
fontFace=cv2.FONT_HERSHEY_SIMPLEX,
fontScale=0.4,
color=(0, 0, 255))
action='store_true')
parser.add_argument("--source-text", help="path to txt file to summarise",
type=str, required=True)
args = parser.parse_args(sys.argv[1:])
endpoint = args.endpoint
with open(args.source_text, 'r') as f:
text = f.read()
params = {'text': text}
if args.snet:
endpoint, job_address, job_signature = snet_setup(service_name="text_summarization", max_price=10000000)
params['job_address'] = job_address
params['job_signature'] = job_signature
response = jsonrpcclient.request(endpoint, "summarise", **params)
print(response)
def fetch_peers(ip, jrpc_port):
json_rpc_url = "http://{}:{}".format(ip, jrpc_port)
print("calling {}".format(json_rpc_url))
peers = jsonrpcclient.request(json_rpc_url, "getPeers")
return [
"{}:{}".format(ipaddress.ip_address(int(p["ip"], 16)), int(p["port"], 16))
for p in peers["peers"]
]
return 1
with open(args.source_text, 'r') as f:
text = f.read()
params = {
'text': text,
'source': args.source_language,
'target': args.target_language,
}
if args.snet:
endpoint, job_address, job_signature = snet_setup(service_name="translation", max_price=10000000)
params['job_address'] = job_address
params['job_signature'] = job_signature
response = jsonrpcclient.request(endpoint, "translate", **params)
print(response)
return 0
choices=['dlib_cnn','dlib_hog','haar_cascade'])
parser.add_argument("--out-image", help="Render bounding box on image and save",
type=str, required=False)
args = parser.parse_args(sys.argv[1:])
with open(args.image, "rb") as f:
img_base64 = base64.b64encode(f.read()).decode('ascii')
endpoint = args.endpoint
params = {'algorithm': args.algorithm, "image": img_base64}
if args.snet:
endpoint, job_address, job_signature = snet_setup(service_name="face_detect")
params['job_address'] = job_address
params['job_signature'] = job_signature
response = jsonrpcclient.request(endpoint, "find_face", **params)
if args.out_image:
print("Rendering bounding box and saving to {}".format(args.out_image))
import cv2
image = cv2.imread(args.image)
for d in response['faces']:
cv2.rectangle(image, (d['x'], d['y']), (d['x'] + d['w'], d['y'] + d['h']), (0, 255, 0), 2)
cv2.imwrite(args.out_image, image)
def __sendRequest(self, *args, **kwargs):
return jsonrpcclient.request("http://localhost:{}".format(self.port), *args, **kwargs)
def request(self, endpoint, method, **kwargs):
if self.enabled:
return jsonrpcclient.request(endpoint, method, **kwargs)
else:
return {"method": method, **kwargs}