怎么在html调用Infermedica API
时间: 2024-06-08 22:11:40 浏览: 11
要HTML中调用Infermedica API,您需要使用JavaScript编写代码。以下是一个简单的示例,展示如何使用Infermedica API来对症状进行诊断:
```html
<!DOCTYPE html>
<html>
<head>
<title>Infermedica API Demo</title>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
function diagnose() {
var input = document.getElementById("input").value;
var data = {
"sex": "male",
"age": 35,
"evidence": [
{"id": input, "choice_id": "present"}
]
};
axios.post("https://api.infermedica.com/covid19/diagnosis", data, {
headers: {
"App-Id": "YOUR_APP_ID",
"App-Key": "YOUR_APP_KEY",
"Content-Type": "application/json",
"Accept": "application/json"
}
})
.then(function(response) {
var conditions = response.data.conditions;
var output = "";
for (var i = 0; i < conditions.length; i++) {
output += conditions[i].name + " (" + conditions[i].probability + ")<br>";
}
document.getElementById("output").innerHTML = output;
})
.catch(function(error) {
console.log(error);
});
}
</script>
</head>
<body>
<h1>Infermedica API Demo</h1>
<label for="input">Symptom:</label>
<input type="text" id="input">
<button onclick="diagnose()">Diagnose</button>
<div id="output"></div>
</body>
</html>
```
在这个示例中,我们使用Axios库来发送POST请求到Infermedica API,并传递一些必要的参数,例如性别、年龄和症状。您需要将“YOUR_APP_ID”和“YOUR_APP_KEY”替换为您自己的应用程序ID和密钥。在成功接收响应后,我们从响应中提取条件列表,并将其显示在HTML页面上。
请注意,此示例仅用于演示目的,并且可能需要根据您的应用程序的要求进行修改。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)