Spaces:
Running
Running
File size: 1,583 Bytes
c8dedad 46a080f c8dedad 46a080f |
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 |
<!DOCTYPE html>
<html>
<head>
<title>YouTube Summarizer</title>
</head>
<body>
<h2>Summarize a YouTube Video</h2>
<input type="text" id="youtubeUrl" placeholder="Paste YouTube URL">
<button onclick="summarizeVideo()">Summarize</button>
<pre id="summaryOutput"></pre>
<script>
async function summarizeVideo() {
const url = document.getElementById('youtubeUrl').value;
const videoId = extractVideoID(url);
if (!videoId) return alert("Invalid YouTube URL");
const transcript = await fetchTranscript(videoId);
const summary = await summarizeText(transcript);
document.getElementById('summaryOutput').textContent = summary;
}
function extractVideoID(url) {
const match = url.match(/(?:v=|\/)([0-9A-Za-z_-]{11})/);
return match ? match[1] : null;
}
async function fetchTranscript(videoId) {
const response = await fetch(`https://youtubetranscriptapi.streamlit.app/api/transcript/${videoId}`);
const data = await response.json();
return data.transcript.map(t => t.text).join(' ');
}
async function summarizeText(text) {
const response = await fetch('https://api-inference.huggingface.co/models/facebook/bart-large-cnn', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_HF_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ inputs: text })
});
const result = await response.json();
return result[0]?.summary_text || "No summary available";
}
</script>
</body>
</html>
|