-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscript.js
More file actions
107 lines (90 loc) · 3.53 KB
/
script.js
File metadata and controls
107 lines (90 loc) · 3.53 KB
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
const chatsContainer = document.querySelector(".chats-container");
const promptForm = document.querySelector(".prompt-form");
const inputType = document.querySelector("#input-type");
const exportFormat = document.querySelector("#export-format");
const youtubeInput = document.querySelector("#youtube-link");
const fileInput = document.querySelector("#audio-file");
const themeToggleBtn = document.querySelector("#theme-toggle-btn");
const deleteChatsBtn = document.querySelector("#delete-chats-btn");
const BACKEND_URL = "http://127.0.0.1:5000/summarize";
// Handle UI toggle based on input type
inputType.addEventListener("change", () => {
youtubeInput.style.display = inputType.value === "youtube" ? "block" : "none";
fileInput.style.display = inputType.value === "file" ? "block" : "none";
});
// Display chat-style summary blocks
function showResultBlock(title, content, type = "bot-message") {
const messageDiv = document.createElement("div");
messageDiv.classList.add("message", type);
messageDiv.innerHTML = `
<img class="avatar" src="frenzy.svg" />
<div class="message-text"><strong>${title}</strong><br><br>${content}</div>
`;
chatsContainer.appendChild(messageDiv);
document.body.classList.add("chats-active");
setTimeout(() => {
messageDiv.scrollIntoView({ behavior: "smooth", block: "end" });
}, 100);
}
// Submit to backend
promptForm.addEventListener("submit", async (e) => {
e.preventDefault();
chatsContainer.innerHTML = ""; // Clear previous
const selected = inputType.value;
const format = exportFormat.value;
const youtubeURL = youtubeInput.value;
const file = fileInput.files[0];
if (!selected || !format) {
alert("Please select input type and export format.");
return;
}
if (selected === "youtube" && !youtubeURL.trim()) {
alert("Enter a valid YouTube URL.");
return;
}
if (selected === "file" && !file) {
alert("Upload a file first.");
return;
}
const formData = new FormData();
formData.append("input_type", selected);
formData.append("export_format", format);
if (selected === "file") {
formData.append("file", file);
} else if (selected === "youtube") {
formData.append("youtube_url", youtubeURL);
} else if (selected === "mic") {
formData.append("duration", "60");
}
showResultBlock("🔄 Processing Input...", "Please wait...");
try {
const response = await fetch(BACKEND_URL, {
method: "POST",
body: formData
});
const data = await response.json();
chatsContainer.innerHTML = "";
if (data.error) {
showResultBlock("❌ Error", data.error);
} else {
showResultBlock("📜 Overall Summary", data.overall_summary);
showResultBlock("📄 Overview", data.overview);
showResultBlock("📌 Key Points", data.keypoints);
showResultBlock("⬇️ Export", `File saved as: <code>${data.output_file}</code>`);
}
} catch (err) {
chatsContainer.innerHTML = "";
showResultBlock("❌ Server Error", err.message || "Failed to connect to backend.");
}
});
// Theme toggle
themeToggleBtn.addEventListener("click", () => {
const isLight = document.body.classList.toggle("light-theme");
localStorage.setItem("themeColor", isLight ? "light_mode" : "dark_mode");
themeToggleBtn.textContent = isLight ? "dark_mode" : "light_mode";
});
// Delete chats
deleteChatsBtn.addEventListener("click", () => {
chatsContainer.innerHTML = "";
document.body.classList.remove("chats-active");
});