Spaces:
Sleeping
Sleeping
updated frontend (added css)
Browse files- app.py +1 -1
- frontend/index.html +112 -12
app.py
CHANGED
@@ -69,7 +69,7 @@ def get_prediction(iids, ams):
|
|
69 |
def classify_lyrics(lyrics):
|
70 |
input_ids, attention_masks = tokenize_and_format([lyrics.replace('\n', ' ')])
|
71 |
prediction = get_prediction(input_ids, attention_masks)
|
72 |
-
mood = ["
|
73 |
return mood
|
74 |
|
75 |
@app.route('/')
|
|
|
69 |
def classify_lyrics(lyrics):
|
70 |
input_ids, attention_masks = tokenize_and_format([lyrics.replace('\n', ' ')])
|
71 |
prediction = get_prediction(input_ids, attention_masks)
|
72 |
+
mood = ["Angry", "Happy", "Relaxed", "Sad"][prediction]
|
73 |
return mood
|
74 |
|
75 |
@app.route('/')
|
frontend/index.html
CHANGED
@@ -1,18 +1,97 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<html>
|
3 |
<head>
|
4 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
</head>
|
6 |
<body>
|
7 |
-
<
|
8 |
-
|
9 |
-
<
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
16 |
<script>
|
17 |
document.getElementById('mood-form').addEventListener('submit', async function(event) {
|
18 |
event.preventDefault();
|
@@ -29,7 +108,28 @@
|
|
29 |
const data = await response.json();
|
30 |
document.getElementById('mood-result').innerText = `Predicted Mood: ${data.mood}`;
|
31 |
document.getElementById('lyrics').innerText = data.lyrics;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
});
|
33 |
</script>
|
34 |
</body>
|
35 |
-
</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>Moody Lyrics</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
font-family: 'Georgia', serif;
|
10 |
+
background-color: #f4f4f9;
|
11 |
+
color: #333;
|
12 |
+
margin: 0;
|
13 |
+
padding: 0;
|
14 |
+
display: flex;
|
15 |
+
justify-content: center;
|
16 |
+
align-items: center;
|
17 |
+
height: 100vh;
|
18 |
+
}
|
19 |
+
.container {
|
20 |
+
background: #fff;
|
21 |
+
padding: 30px;
|
22 |
+
border-radius: 15px;
|
23 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
24 |
+
max-width: 700px;
|
25 |
+
width: 100%;
|
26 |
+
text-align: center;
|
27 |
+
overflow-y: auto;
|
28 |
+
max-height: 90vh;
|
29 |
+
}
|
30 |
+
h1 {
|
31 |
+
color: #2c3e50;
|
32 |
+
font-size: 2.5em;
|
33 |
+
margin-bottom: 20px;
|
34 |
+
}
|
35 |
+
form {
|
36 |
+
display: flex;
|
37 |
+
flex-direction: column;
|
38 |
+
align-items: center;
|
39 |
+
gap: 20px;
|
40 |
+
}
|
41 |
+
input[type="text"] {
|
42 |
+
padding: 12px;
|
43 |
+
width: 80%;
|
44 |
+
border: 2px solid #2c3e50;
|
45 |
+
border-radius: 10px;
|
46 |
+
font-size: 1em;
|
47 |
+
}
|
48 |
+
button {
|
49 |
+
padding: 12px 30px;
|
50 |
+
background-color: #2c3e50;
|
51 |
+
color: #fff;
|
52 |
+
border: none;
|
53 |
+
border-radius: 10px;
|
54 |
+
font-size: 1.2em;
|
55 |
+
cursor: pointer;
|
56 |
+
transition: background-color 0.3s;
|
57 |
+
}
|
58 |
+
button:hover {
|
59 |
+
background-color: #1a242f;
|
60 |
+
}
|
61 |
+
#mood-result {
|
62 |
+
margin-top: 30px;
|
63 |
+
font-size: 1.5em;
|
64 |
+
}
|
65 |
+
pre {
|
66 |
+
background: #f4f4f9;
|
67 |
+
padding: 20px;
|
68 |
+
border-radius: 10px;
|
69 |
+
white-space: pre-wrap;
|
70 |
+
word-wrap: break-word;
|
71 |
+
margin-top: 20px;
|
72 |
+
font-family: 'Courier New', Courier, monospace;
|
73 |
+
text-align: left;
|
74 |
+
}
|
75 |
+
#results-container {
|
76 |
+
margin-top: 30px;
|
77 |
+
padding: 20px;
|
78 |
+
border-radius: 10px;
|
79 |
+
}
|
80 |
+
</style>
|
81 |
</head>
|
82 |
<body>
|
83 |
+
<div class="container">
|
84 |
+
<h1>Moody Lyrics</h1>
|
85 |
+
<form id="mood-form">
|
86 |
+
<input type="text" id="title" placeholder="Song Title" required>
|
87 |
+
<input type="text" id="artist" placeholder="Artist" required>
|
88 |
+
<button type="submit">Predict Mood</button>
|
89 |
+
</form>
|
90 |
+
<div id="results-container">
|
91 |
+
<h2 id="mood-result"></h2>
|
92 |
+
<pre id="lyrics"></pre>
|
93 |
+
</div>
|
94 |
+
</div>
|
95 |
<script>
|
96 |
document.getElementById('mood-form').addEventListener('submit', async function(event) {
|
97 |
event.preventDefault();
|
|
|
108 |
const data = await response.json();
|
109 |
document.getElementById('mood-result').innerText = `Predicted Mood: ${data.mood}`;
|
110 |
document.getElementById('lyrics').innerText = data.lyrics;
|
111 |
+
// Scroll to the top of the container to ensure the form remains visible
|
112 |
+
document.querySelector('.container').scrollTop = 0;
|
113 |
+
|
114 |
+
// Change background color based on the predicted mood
|
115 |
+
const resultsContainer = document.getElementById('results-container');
|
116 |
+
switch (data.mood.toLowerCase()) {
|
117 |
+
case 'happy':
|
118 |
+
resultsContainer.style.backgroundColor = '#fff9c4'; // light yellow
|
119 |
+
break;
|
120 |
+
case 'angry':
|
121 |
+
resultsContainer.style.backgroundColor = '#ffcdd2'; // light red
|
122 |
+
break;
|
123 |
+
case 'relaxed':
|
124 |
+
resultsContainer.style.backgroundColor = '#c8e6c9'; // light green
|
125 |
+
break;
|
126 |
+
case 'sad':
|
127 |
+
resultsContainer.style.backgroundColor = '#bbdefb'; // light blue
|
128 |
+
break;
|
129 |
+
default:
|
130 |
+
resultsContainer.style.backgroundColor = '#f4f4f9'; // default background color
|
131 |
+
}
|
132 |
});
|
133 |
</script>
|
134 |
</body>
|
135 |
+
</html>
|