Agrimr commited on
Commit
eaa439e
1 Parent(s): 0e11b97

Delete index.html

Browse files
Files changed (1) hide show
  1. index.html +0 -113
index.html DELETED
@@ -1,113 +0,0 @@
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
- <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
9
- </head>
10
- <body>
11
- <div class="container">
12
- <h1>Sentiment Analysis</h1>
13
- <textarea id="textInput" placeholder="Enter text..."></textarea>
14
- <button onclick="classifySentiment()">Classify</button>
15
- <div id="result" class="result-container"></div>
16
- <canvas id="chart"></canvas>
17
- </div>
18
-
19
- <script>
20
- let chart; // Declare chart variable outside the function
21
-
22
- async function query(data) {
23
- try {
24
- const response = await fetch(
25
- "https://api-inference.huggingface.co/models/ahmedrachid/FinancialBERT-Sentiment-Analysis",
26
- {
27
- headers: { Authorization: "Bearer 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" },
28
- method: "POST",
29
- body: JSON.stringify(data),
30
- }
31
- );
32
-
33
- if (!response.ok) {
34
- throw new Error(`HTTP error! Status: ${response.status}`);
35
- }
36
-
37
- const result = await response.json();
38
- return result;
39
- } catch (error) {
40
- console.error("Error during API request:", error);
41
- return { error: "Failed to get predictions from the model." };
42
- }
43
- }
44
-
45
- function classifySentiment() {
46
- const textInput = document.getElementById("textInput").value;
47
- const chartCanvas = document.getElementById("chart");
48
-
49
- if (textInput.trim() === "") {
50
- alert("Please enter text for sentiment analysis.");
51
- return;
52
- }
53
-
54
- const data = { "inputs": textInput };
55
-
56
- // Call the query function and handle the response
57
- query(data).then((response) => {
58
- console.log(JSON.stringify(response));
59
-
60
- const resultDiv = document.getElementById("result");
61
-
62
- if (response && Array.isArray(response) && response.length > 0) {
63
- const predictions = response[0];
64
-
65
- // Display the results for each sentiment label and score
66
- resultDiv.innerHTML = predictions.map((prediction) => {
67
- return `
68
- <div class="result-item">
69
- <p>Sentiment: ${prediction.label}</p>
70
- <p>Confidence Score: ${prediction.score * 100}</p>
71
- </div>
72
- `;
73
- }).join('');
74
-
75
- // Destroy the existing chart if it exists
76
- if (chart) {
77
- chart.destroy();
78
- }
79
-
80
- // Create a new bar chart
81
- const labels = predictions.map(prediction => prediction.label);
82
- const scores = predictions.map(prediction => prediction.score * 100); // Scale scores to percentage
83
-
84
- const ctx = chartCanvas.getContext('2d');
85
- chart = new Chart(ctx, {
86
- type: 'bar',
87
- data: {
88
- labels: labels,
89
- datasets: [{
90
- label: 'Confidence Scores (%)',
91
- data: scores,
92
- backgroundColor: 'rgba(75, 192, 192, 0.2)',
93
- borderColor: 'rgba(75, 192, 192, 1)',
94
- borderWidth: 1
95
- }]
96
- },
97
- options: {
98
- scales: {
99
- y: {
100
- beginAtZero: true,
101
- max: 100
102
- }
103
- }
104
- }
105
- });
106
- } else {
107
- resultDiv.textContent = "Unable to determine sentiment.";
108
- }
109
- });
110
- }
111
- </script>
112
- </body>
113
- </html>