Sunday 23 January 2022

Fire off function without waiting for answer (Python)

Here is sample code for thread based method invocation additionally desired threading.stack_size can be added to boost the performance. Also its important to invoke Garbage collector if the number of threaded invocation is greater in number.
 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 threading
import requests
import gc
#The stack size set by threading.stack_size is the amount of memory to allocate for the call stack in threads.
threading.stack_size(524288)

def alpha_gun(url, json, headers):
    #r=requests.post(url, data=json, headers=headers)
    r=requests.get(url)
    print(r.text)


def trigger(url, json, headers):
    threading.Thread(target=alpha_gun, args=(url, json, headers)).start()


url = "https://raw.githubusercontent.com/jyotiprakash-work/Live_Video_steaming/master/README.md"
payload="{}"
headers = {
  'Content-Type': 'application/json'
}

for i in range(10):
    print(i)
    #for condition 
    if i==5:
        trigger(url=url, json =payload, headers=headers)
        gc.collect()
        print('invoked')
    

Saturday 22 January 2022

Face Recognition With python and face-net model

 Here i have added face recognition code in a flask app. The Face app contains registration, training model and recognition where each having a separate end point.




To access the endpoints please follow cUrls-

For Respiration- 
curl -X POST \
  http://127.0.0.1:5000/upload \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -H 'postman-token: 2bf86477-f928-9ff2-d677-9b42a802e381' \
  -F file=@WIN_20220123_00_56_49_Pro.jpg \
  -F id=jp

For training-
curl -X POST \
  http://127.0.0.1:5000/train \
  -H 'cache-control: no-cache' \
  -H 'postman-token: 374826ca-15b5-7508-5052-f3ec43b1ca07'

For Recognition-
curl -X POST \
  http://127.0.0.1:5000/recognize \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -H 'postman-token: 4183a550-5278-a7fe-c618-f100d164c7f8' \
  -F file=@WIN_20220123_00_57_28_Pro.jpg