-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcloudFunction.py
27 lines (21 loc) · 1007 Bytes
/
cloudFunction.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
import functions_framework
from transformers import RobertaTokenizerFast, TFRobertaForSequenceClassification, pipeline
tokenizer = RobertaTokenizerFast.from_pretrained("arpanghoshal/EmoRoBERTa")
model = TFRobertaForSequenceClassification.from_pretrained("arpanghoshal/EmoRoBERTa")
emotion = pipeline("sentiment-analysis", model="arpanghoshal/EmoRoBERTa", return_all_scores=True)
@functions_framework.http
def echo(request):
"""HTTP Cloud Function.
Args:
request (flask.Request): The request object.
<https://flask.palletsprojects.com/en/1.1.x/api/#incoming-request-data>
Returns:
The response text, or any set of values that can be turned into a
Response object using `make_response`
<https://flask.palletsprojects.com/en/1.1.x/api/#flask.make_response>.
"""
data = request.get_json(silent=True)
if "input" in data:
scores = emotion(data['input'])
return scores
return 'Bad input. expecting json: {"input": "<phrase here>"}'