字典和标点符号
Dictionaries and punctuation
url = "https://api-inference.huggingface.co/"
payload = json.dumps({
"inputs": "My name is Eesha I like surfing"
})
headers = {
'Authorization': 'Bearer Test',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Response.text:
[
{
"entity_group": "PERIOD",
"score": 0.8200734853744507,
"word": "eesha",
"start": 11,
"end": 15
},
{
"entity_group": "PERIOD",
"score": 0.8993015885353088,
"word": "surfing",
"start": 23,
"end": 30
}
]
我正在尝试遍历字典,但我得到的字符串索引必须是整数。我的目标是在 end 给出的字符数之后添加正确的标点符号。有什么建议吗?
您可能应该使用 response.json()
而不是 response.text
将响应转换为 JSON 字典。之后,您可以像往常一样遍历字典。
url = "https://api-inference.huggingface.co/"
payload = json.dumps({
"inputs": "My name is Eesha I like surfing"
})
headers = {
'Authorization': 'Bearer Test',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Response.text:
[
{
"entity_group": "PERIOD",
"score": 0.8200734853744507,
"word": "eesha",
"start": 11,
"end": 15
},
{
"entity_group": "PERIOD",
"score": 0.8993015885353088,
"word": "surfing",
"start": 23,
"end": 30
}
]
我正在尝试遍历字典,但我得到的字符串索引必须是整数。我的目标是在 end 给出的字符数之后添加正确的标点符号。有什么建议吗?
您可能应该使用 response.json()
而不是 response.text
将响应转换为 JSON 字典。之后,您可以像往常一样遍历字典。