Slide 27
Slide 27 text
リクエストのコードスニペット
@postman_japan
% python
Python 3.10.10 (main, Jul 14 2023, 11:54:03) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> import json
>>>
>>> url = "https://api-inference.huggingface.co/models/SamLowe/roberta-base-go_emotions"
>>>
>>> payload = json.dumps({
... "text": "I am not having a great day."
... })
>>> headers = {
... 'Content-Type': 'application/json',
... 'Authorization': 'Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
... }
>>>
>>> response = requests.request("POST", url, headers=headers, data=payload)
>>>
>>> print(response.text)
[{"label":"disappointment","score":0.5044485330581665},{"label":"sadness","score":0.3469431400299072},{"label":
"annoyance","score":0.08485797047615051},{"label":"neutral","score":0.05476689338684082},{"label":"disapproval"
,"score":0.05280729755759239},{"label":"realization","score":0.0147128039970994},{"label":"nervousness","score"
:0.013806507922708988},{"label":"approval","score":0.011522370390594006},{"label":"joy","score":0.0062008751556
277275},{"label":"anger","score":0.005856028757989407},{"label":"embarrassment","score":0.005520221311599016},{
"label":"caring","score":0.005480862222611904},{"label":"remorse","score":0.0053450302220880985},{"label":"disg
ust","score":0.004901108331978321},{"label":"grief","score":0.0035944394767284393},{"label":"confusion","score"
:0.0035573095083236694},{"label":"relief","score":0.0030994510743767023},{"label":"desire","score":0.0028612534
515559673},{"label":"admiration","score":0.0027561066672205925},{"label":"optimism","score":0.00272876257076859
47},{"label":"fear","score":0.002634430304169655},{"label":"love","score":0.00248360657133162},{"label":"excite
ment","score":0.002481137402355671},{"label":"curiosity","score":0.0022594754118472338},{"label":"amusement","s
core":0.001642841612920165},{"label":"surprise","score":0.0015645057428628206},{"label":"gratitude","score":0.0
006519951275549829},{"label":"pride","score":0.000576098682358861}]