Agrimr commited on
Commit
b9bd274
1 Parent(s): 19544dd
Files changed (1) hide show
  1. index.html +74 -17
index.html CHANGED
@@ -1,19 +1,76 @@
1
  <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>