Spaces:
Running
Running
updare
Browse files- index.html +74 -17
index.html
CHANGED
@@ -1,19 +1,76 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Sentiment Analysis Web App</title>
|
7 |
+
<link rel="stylesheet" href="style.css">
|
8 |
+
</head>
|
9 |
+
<body>
|
10 |
+
<div class="container">
|
11 |
+
<h1>Sentiment Analysis</h1>
|
12 |
+
<textarea id="textInput" placeholder="Enter text..."></textarea>
|
13 |
+
<button onclick="classifySentiment()">Classify</button>
|
14 |
+
<div id="result" class="result-container"></div>
|
15 |
+
</div>
|
16 |
+
|
17 |
+
<script>
|
18 |
+
async function query(data) {
|
19 |
+
try {
|
20 |
+
const response = await fetch(
|
21 |
+
"https://api-inference.huggingface.co/models/ahmedrachid/FinancialBERT-Sentiment-Analysis",
|
22 |
+
{
|
23 |
+
headers: { Authorization: "Bearer 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" },
|
24 |
+
method: "POST",
|
25 |
+
body: JSON.stringify(data),
|
26 |
+
}
|
27 |
+
);
|
28 |
+
|
29 |
+
if (!response.ok) {
|
30 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
31 |
+
}
|
32 |
+
|
33 |
+
const result = await response.json();
|
34 |
+
return result;
|
35 |
+
} catch (error) {
|
36 |
+
console.error("Error during API request:", error);
|
37 |
+
return { error: "Failed to get predictions from the model." };
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
function classifySentiment() {
|
42 |
+
const textInput = document.getElementById("textInput").value;
|
43 |
+
|
44 |
+
if (textInput.trim() === "") {
|
45 |
+
alert("Please enter text for sentiment analysis.");
|
46 |
+
return;
|
47 |
+
}
|
48 |
+
|
49 |
+
const data = { "inputs": textInput };
|
50 |
+
|
51 |
+
// Call the query function and handle the response
|
52 |
+
query(data).then((response) => {
|
53 |
+
console.log(JSON.stringify(response));
|
54 |
+
|
55 |
+
const resultDiv = document.getElementById("result");
|
56 |
+
|
57 |
+
if (response && Array.isArray(response) && response.length > 0) {
|
58 |
+
const predictions = response[0];
|
59 |
+
|
60 |
+
// Display the results for each sentiment label and score
|
61 |
+
resultDiv.innerHTML = predictions.map((prediction) => {
|
62 |
+
return `
|
63 |
+
<div class="result-item">
|
64 |
+
<p>Sentiment: ${prediction.label}</p>
|
65 |
+
<p>Confidence Score: ${prediction.score}</p>
|
66 |
+
</div>
|
67 |
+
`;
|
68 |
+
}).join('');
|
69 |
+
} else {
|
70 |
+
resultDiv.textContent = "Unable to determine sentiment.";
|
71 |
+
}
|
72 |
+
});
|
73 |
+
}
|
74 |
+
</script>
|
75 |
+
</body>
|
76 |
</html>
|