mgbam commited on
Commit
03bbb65
·
verified ·
1 Parent(s): afada0a

Create index.html

Browse files
Files changed (1) hide show
  1. index.html +66 -0
index.html ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- index.html -->
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Transformer Sentiment Analyzer</title>
8
+ <link rel="stylesheet" href="style.css">
9
+ </head>
10
+ <body>
11
+ <header>
12
+ <h1>Transformer Sentiment Analyzer</h1>
13
+ </header>
14
+ <main class="container">
15
+ <form id="analyze-form">
16
+ <label for="inputText">Enter text to analyze:</label>
17
+ <textarea id="inputText" name="inputText" rows="4" placeholder="Type your text here..." required aria-required="true"></textarea>
18
+ <button type="submit" id="analyzeButton">Analyze Sentiment</button>
19
+ </form>
20
+ <section id="result" aria-live="polite"></section>
21
+ </main>
22
+ <script type="module" src="index.js"></script>
23
+ </body>
24
+ </html>
25
+ ```
26
+ ```javascript
27
+ // index.js
28
+ import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers';
29
+
30
+ const analyzeForm = document.getElementById('analyze-form');
31
+ const inputText = document.getElementById('inputText');
32
+ const resultSection = document.getElementById('result');
33
+ const analyzeButton = document.getElementById('analyzeButton');
34
+
35
+ let sentimentPipeline;
36
+
37
+ async function initPipeline() {
38
+ analyzeButton.disabled = true;
39
+ analyzeButton.textContent = 'Loading model...';
40
+ sentimentPipeline = await pipeline('sentiment-analysis');
41
+ analyzeButton.textContent = 'Analyze Sentiment';
42
+ analyzeButton.disabled = false;
43
+ }
44
+
45
+ analyzeForm.addEventListener('submit', async (event) => {
46
+ event.preventDefault();
47
+ const text = inputText.value.trim();
48
+ if (!text) return;
49
+
50
+ analyzeButton.disabled = true;
51
+ analyzeButton.textContent = 'Analyzing...';
52
+ resultSection.textContent = '';
53
+
54
+ try {
55
+ const output = await sentimentPipeline(text);
56
+ const { label, score } = output[0];
57
+ resultSection.textContent = `Sentiment: ${label} (Confidence: ${(score * 100).toFixed(2)}%)`;
58
+ } catch (error) {
59
+ resultSection.textContent = 'Error analyzing sentiment.';
60
+ }
61
+
62
+ analyzeButton.textContent = 'Analyze Sentiment';
63
+ analyzeButton.disabled = false;
64
+ });
65
+
66
+ initPipeline();