-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
151 lines (126 loc) · 4.23 KB
/
index.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html>
<head>
<title>Sentiment Analysis Tool</title>
<style>
* {
box-sizing: border-box;
font-family: Arial, sans-serif;
}
.container {
width: 500px;
margin: 50px auto;
border: 1px solid #ccc;
padding: 10px;
border-radius: 5px;
background-color: #f0f0f0;
}
h1 {
text-align: center;
color: #333;
}
p {
text-align: center;
font-style: italic;
}
#input-container {
display: flex;
}
#input {
flex: 1;
padding: 5px;
border: 1px solid #ccc;
border-radius: 5px;
}
#submit {
margin-left: 5px;
padding: 5px 10px;
border: none;
background-color: #90EE90; /* soothing meditative color */
color: white;
cursor: pointer;
}
#output {
margin-top: 10px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
.positive {
color: green;
}
.negative {
color: red;
}
.neutral {
color: gray;
}
</style>
</head>
<body>
<div class="container">
<h1>Sentiment Analysis Tool</h1>
<p>Enter a sentence and click the button to see its sentiment.</p>
<div id="input-container">
<input type="text" id="input" placeholder="Type your sentence...">
<button id="submit">Analyze</button>
</div>
<div id="output"></div>
</div>
<script>
const inputField = document.getElementById('input');
const submitButton = document.getElementById('submit');
const outputElement = document.getElementById('output');
// Process user input
function processInput() {
const userInput = inputField.value.trim();
// Check if the input is not empty
if (userInput) {
// Call your API or perform logic to get the sentiment analysis result
const sentimentResult = getSentimentResult(userInput);
// Display the result in the output element
outputElement.textContent = `The sentiment of "${userInput}" is ${sentimentResult}.`;
outputElement.classList.add(sentimentResult);
// Clear the input field after displaying the result
inputField.value = '';
// Focus on the input field for convenience
inputField.focus();
// Play a sound effect based on the result
playSound(sentimentResult);
// Reset the output element class after a slight delay
setTimeout(() => {
outputElement.classList.remove(sentimentResult);
}, 5000);
}
}
// Simulated sentiment analysis API or logic result
function getSentimentResult(sentence) {
// Add your logic here to generate an appropriate sentiment result based on the sentence
if (sentence.toLowerCase().includes('love') || sentence.toLowerCase().includes('happy') || sentence.toLowerCase().includes('great')) {
return 'positive';
} else if (sentence.toLowerCase().includes('hate') || sentence.toLowerCase().includes('sad') || sentence.toLowerCase().includes('terrible')) {
return 'negative';
} else {
return 'neutral';
}
}
// Play a sound effect based on the result
function playSound(result) {
// Choose a sound file based on the result
let soundFile;
if (result === 'positive') {
soundFile = 'https://freesound.org/data/previews/341/341695_5858296-lq.mp3';
} else if (result === 'negative') {
soundFile = 'https://freesound.org/data/previews/171/171671_2437358-lq.mp3';
} else {
soundFile = 'https://freesound.org/data/previews/257/257357_4486188-lq.mp3';
}
// Create an audio element and play the sound file
const audio = new Audio(soundFile);
audio.play();
}
// Add an event listener for the submit button
submitButton.addEventListener('click', processInput);
</script>
</body>
</html>