-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
260 lines (229 loc) · 9.35 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta data-n-head="ssr" data-hid="theme-color" name="theme-color" content="#33a0e4">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YouTube Comment Generator</title>
<meta name="robots" content="index, archive">
<meta name="description" content="Easily generate human-like, engaging comments for YouTube videos with our advanced tool. Enter any video link and get witty, natural comments in seconds!">
<meta property="og:locale" content="en_US">
<meta property="og:type" content="website">
<meta property="og:title" content="YouTube Comment Generator">
<meta property="og:description" content="Easily generate human-like, engaging comments for YouTube videos with our advanced tool. Enter any video link and get witty, natural comments in seconds!">
<meta property="og:image" content="img/favicon.png">
<meta property="og:url" content="https://rojansapkota.github.io/YouTube-AI-Comment-Generator/">
<link rel="shortcut icon" href="img/favicon.png" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: #33a0e4;
--background-color: #8BC6EC;
--background-gradient: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%);
--text-color: #ffffff;
--box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
--border-radius: 10px;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background-color: var(--background-color);
background-image: var(--background-gradient);
}
.container {
max-width: 410px;
padding: 16px 25px;
background: rgba(31, 31, 31, 0.35);
box-shadow: var(--box-shadow);
backdrop-filter: blur(6px);
-webkit-backdrop-filter: blur(6px);
border-radius: var(--border-radius);
border: 1px solid rgba(255, 255, 255, 0.18);
text-align: center;
}
h1 {
font-size: 21px;
font-weight: 500;
color: var(--text-color);
}
form {
margin: 20px 0;
}
input[type="text"] {
width: 100%;
height: 55px;
padding: 0 17px;
border: none;
border-radius: var(--border-radius);
background: rgba(0, 0, 0, 0.3);
box-shadow: var(--box-shadow);
backdrop-filter: blur(3.5px);
-webkit-backdrop-filter: blur(3.5px);
border: 1px solid rgba(255, 255, 255, 0.18);
color: var(--text-color);
font-size: 18px;
transition: border-color 0.3s;
margin-bottom: 15px; /* Gap between input and button */
}
input[type="text"]:focus {
border-color: var(--primary-color);
outline: none;
}
button {
width: 100%;
height: 55px;
background: var(--primary-color);
color: var(--text-color);
border: none;
border-radius: var(--border-radius);
cursor: pointer;
font-size: 17px;
transition: background 0.3s ease;
}
button:hover {
background: #2989d8; /* Slightly darker color on hover */
}
#result {
margin-top: 20px;
font-size: 18px;
opacity: 0;
transition: opacity 1s ease-out;
}
#result.show {
opacity: 1;
}
#result-text {
animation: fadeInUp 1s ease-out;
}
@keyframes fadeInUp {
0% {
opacity: 0;
transform: translateY(20px);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
.loading {
margin-top: 20px;
font-size: 18px;
display: none;
}
.loading.show {
display: block;
}
.error-message {
color: #ff0000; /* Red color for error messages */
margin-top: 15px;
opacity: 0;
transition: opacity 1s ease-out;
}
.error-message.show {
opacity: 1;
}
</style>
</head>
<body>
<div class="container">
<h1>YT Video Comment Generator</h1>
<form id="commentForm">
<input type="text" id="video_id" name="video_id" placeholder="Enter Video Link" required>
<input type="text" id="api_key" name="api_key" placeholder="Enter Your Groq API Key" required>
<button type="submit">Generate Comment</button>
</form>
<div id="result" class="result">
<p id="result-text"></p>
</div>
<div id="loading" class="loading">Generating comment, please wait...</div>
<div id="error-message" class="error-message"></div> <!-- Error message container -->
</div>
<script>
document.getElementById('commentForm').addEventListener('submit', async (event) => {
event.preventDefault();
const videoId = document.getElementById('video_id').value;
const apiKey = document.getElementById('api_key').value; // Get the API key
const loading = document.getElementById('loading');
const resultContainer = document.getElementById('result');
const resultText = document.getElementById('result-text');
const errorMessage = document.getElementById('error-message'); // Error message container
loading.style.display = 'block';
resultContainer.classList.remove('show');
resultText.textContent = '';
errorMessage.textContent = ''; // Clear previous error message
try {
const extractedVidId = videoId.split('v=')[1];
const transcriptResponse = await fetch(`https://api.kome.ai/api/tools/youtube-transcripts`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ video_id: extractedVidId, format: true }),
});
const transcriptData = await transcriptResponse.json();
if (!transcriptResponse.ok) {
resultText.textContent = `Error fetching transcript: ${JSON.stringify(transcriptData)}`;
resultContainer.classList.add('show');
loading.style.display = 'none';
return;
}
const ins = "Imagine you're the wittiest writer on the planet—craft a short, hilarious comment based "
+ "on the video transcript I'll provide. The goal is to make it sound completely natural, "
+ "like something a real person would say, not an AI. Keep it light, funny, and relatable!: ";
const maxLength = 4500;
const availableSpace = maxLength - ins.length;
const transcriptText = transcriptData.transcript.slice(0, availableSpace);
const fullPrompt = ins + transcriptText;
const commentResponse = await fetch('https://api.groq.com/openai/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`, // Use the API key from the input
},
body: JSON.stringify({
messages: [
{
role: 'user',
content: fullPrompt,
}
],
model: 'llama3-70b-8192',
temperature: 1,
max_tokens: 1024,
top_p: 1,
stream: false,
stop: null,
}),
});
const commentData = await commentResponse.json();
if (commentResponse.ok) {
resultText.textContent = commentData.choices[0].message.content;
} else {
// Check for specific error message from API
if (commentData.error && commentData.error.message.includes("Invalid API Key")) {
errorMessage.textContent = "Invalid API Key. Please check your API key and try again. https://console.groq.com/keys";
errorMessage.classList.add('show'); // Show error message
} else {
resultText.textContent = `Error generating comment: ${JSON.stringify(commentData)}`;
}
}
resultContainer.classList.add('show');
loading.style.display = 'none';
} catch (error) {
loading.style.display = 'none';
resultText.textContent = `An error occurred: ${error.message}`;
resultContainer.classList.add('show');
}
});
</script>
</body>
</html>