michaellee8 commited on
Commit
a4d117e
1 Parent(s): e09b5a1

feat: add jwt code

Browse files
Files changed (2) hide show
  1. handler.py +33 -0
  2. requirements.txt +2 -0
handler.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict
2
+ from transformers import pipeline
3
+ import requests
4
+ import jwt
5
+
6
+ SAMPLE_RATE = 16000
7
+
8
+ PUBLIC_KEY = b"-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu1SU1LfVLPHCozMxH2Mo4lgOEePzNm0tRgeLezV6ffAt0gunVTLw7onLRnrq0/IzW7yWR7QkrmBL7jTKEn5u+qKhbwKfBstIs+bMY2Zkp18gnTxKLxoS2tFczGkPLPgizskuemMghRniWaoLcyehkd3qqGElvW/VDL5AaWTg0nLVkjRo9z+40RQzuVaE8AkAFmxZzow3x+VJYKdjykkJ0iT9wCS0DRTXu269V264Vf/3jvredZiKRkgwlL9xNAwxXFg0x/XFw005UWVRIkdgcKWTjpBP2dPwVZ4WWC+9aGVd+Gyn1o0CLelf4rEjGoXbAAEgAqeGUxrcIlbjXfbcmwIDAQAB-----END PUBLIC KEY-----"
9
+
10
+
11
+ class EndpointHandler:
12
+ def __init__(self, path=""):
13
+ print(requests.get("https://google.com").text)
14
+ self.pipeline = pipeline(
15
+ "automatic-speech-recognition", model="openai/whisper-base"
16
+ )
17
+
18
+ def __call__(self, data: Dict[str, bytes]) -> Dict[str, str]:
19
+ """
20
+ Args:
21
+ data (:obj:):
22
+ includes the deserialized audio file as bytes
23
+ Return:
24
+ A :obj:`dict`:. base64 encoded image
25
+ """
26
+ # process input
27
+ token = data.pop("token", None)
28
+ if token is None:
29
+ raise RuntimeError("missing token")
30
+ decoded = jwt.decode(token, PUBLIC_KEY, algorithms=["RS512"])
31
+ print("received input from jti=", decoded["jti"])
32
+
33
+ return pipeline(*data)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ pyjwt[crypto]
2
+ requests