forked from jph00/tinypets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1single.html
32 lines (30 loc) · 990 Bytes
/
1single.html
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
28
29
30
31
32
---
title: Sentiment
layout: default
---
<form id="myForm">
<label for="prompt">Input:</label><br>
<input type="text" id="prompt" name="prompt"><br>
<input type="submit" value="Submit">
</form>
<div id="results"></div>
<script>
document.getElementById("myForm").addEventListener("submit", function(event){
event.preventDefault();
let inputValue = document.getElementById("prompt").value;
analyze(inputValue);
});
async function analyze(prompt) {
var promptList = [];
promptList.push(prompt);
const response = await fetch('https://calebo95-pets.hf.space/api/predict/', {
method: "POST", body: JSON.stringify({ "data": promptList }),
headers: { "Content-Type": "application/json" }
});
const json = await response.json();
firstItemString = json.data[0].replace(/'/g, '"');
let firstItem = JSON.parse(firstItemString);
let label = firstItem[0].label;
results.innerHTML = `<p>The feeling is: ${label}</p>`
}
</script>