sreevidya16
commited on
Commit
•
862b14b
1
Parent(s):
981bfd0
Upload 10 files
Browse files- src/App.jsx +511 -0
- src/Components/Alert.jsx +139 -0
- src/Components/Mindmap.jsx +38 -0
- src/Components/Navbar.jsx +28 -0
- src/Components/YoutubeC.jsx +53 -0
- src/Home.jsx +250 -0
- src/assets/react.svg +1 -0
- src/index.css +31 -0
- src/main.jsx +19 -0
- src/temp.jsx +143 -0
src/App.jsx
ADDED
@@ -0,0 +1,511 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, { useState, useEffect, useRef } from "react";
|
2 |
+
import { useNavigate, useLocation } from "react-router-dom";
|
3 |
+
import Navbar from "./Components/Navbar";
|
4 |
+
import axios from "axios";
|
5 |
+
import YouTube from "react-youtube";
|
6 |
+
import ReactMarkdown from "react-markdown";
|
7 |
+
// import { fetchTranscript } from "youtube-subtitle-transcript";
|
8 |
+
// import Mindmap from "./Components/Mindmap";
|
9 |
+
import ForceGraph2D from "react-force-graph-2d";
|
10 |
+
import ForceGraph3D from "react-force-graph-3d";
|
11 |
+
import SpriteText from "three-spritetext";
|
12 |
+
|
13 |
+
function App() {
|
14 |
+
const { useRef } = React;
|
15 |
+
const fgRef = useRef();
|
16 |
+
|
17 |
+
const navigate = useNavigate();
|
18 |
+
const [messages, setMessages] = useState([]);
|
19 |
+
const [userInput, setUserInput] = useState("");
|
20 |
+
const [timestamps, setTimestamps] = useState([]);
|
21 |
+
const [transcript, setTranscript] = useState("");
|
22 |
+
const [loading, setLoading] = useState(false);
|
23 |
+
const [transcriptStatus, setTranscriptStatus] = useState(false);
|
24 |
+
const location = useLocation();
|
25 |
+
const videoLink = location.state?.videoLink;
|
26 |
+
const metaData = location.state?.metaData;
|
27 |
+
const [videoId, setVideoId] = useState("");
|
28 |
+
const endOfMessagesRef = useRef(null);
|
29 |
+
const [player, setPlayer] = React.useState(null);
|
30 |
+
|
31 |
+
const routebody = "http://localhost:5000";
|
32 |
+
|
33 |
+
const handleClick = async () => {
|
34 |
+
if (!loading) {
|
35 |
+
try {
|
36 |
+
const response = await axios.post(routebody.concat("/transcript"));
|
37 |
+
// console.log("Transcript", response.data.transcript);
|
38 |
+
const temp = response.data.transcript; // This should now correctly reflect the updated state
|
39 |
+
// console.log("Tt", temp);
|
40 |
+
const element = document.createElement("a");
|
41 |
+
const file = new Blob([temp], { type: "text/plain" }); // Use the fetched transcript directly
|
42 |
+
element.href = URL.createObjectURL(file);
|
43 |
+
element.download = "transcript.txt";
|
44 |
+
document.body.appendChild(element); // Required for this to work in FireFox
|
45 |
+
element.click();
|
46 |
+
} catch (error) {
|
47 |
+
window.alert("Failed to fetch transcript:", error);
|
48 |
+
}
|
49 |
+
}
|
50 |
+
};
|
51 |
+
|
52 |
+
const fetch = async () => {
|
53 |
+
try {
|
54 |
+
setTranscript(response.data.transcript);
|
55 |
+
setTranscriptStatus(response.data.status);
|
56 |
+
} catch (error) {
|
57 |
+
console.error("Failed to fetch transcript:", error);
|
58 |
+
}
|
59 |
+
};
|
60 |
+
|
61 |
+
const onPlayerReady = (event) => {
|
62 |
+
setPlayer(event.target);
|
63 |
+
console.log("Player is ready");
|
64 |
+
};
|
65 |
+
const scrollToBottom = () => {
|
66 |
+
if (endOfMessagesRef.current) {
|
67 |
+
endOfMessagesRef.current.scrollIntoView({ behavior: "smooth" });
|
68 |
+
}
|
69 |
+
};
|
70 |
+
|
71 |
+
useEffect(() => {
|
72 |
+
scrollToBottom();
|
73 |
+
}, [messages]);
|
74 |
+
|
75 |
+
console.log(videoLink);
|
76 |
+
useEffect(() => {
|
77 |
+
function convertToEmbedUrl(watchUrl) {
|
78 |
+
return watchUrl.replace("/watch?v=", "/embed/");
|
79 |
+
}
|
80 |
+
|
81 |
+
if (videoLink) {
|
82 |
+
setVideoId(videoLink.split("v=")[1]);
|
83 |
+
|
84 |
+
console.log(videoId);
|
85 |
+
} else {
|
86 |
+
setVideoId("dQw4w9WgXcQ") // Easter Egg 🥚
|
87 |
+
// navigate("/");
|
88 |
+
}
|
89 |
+
}, []);
|
90 |
+
|
91 |
+
const sendMessage = async () => {
|
92 |
+
try {
|
93 |
+
console.log("Sending message...");
|
94 |
+
setLoading(true);
|
95 |
+
let formattedMessages = [];
|
96 |
+
for (let i = 0; i < messages.length; i += 2) {
|
97 |
+
let message = [];
|
98 |
+
message.push(messages[i].content);
|
99 |
+
message.push(messages[i + 1].content);
|
100 |
+
formattedMessages.push(message);
|
101 |
+
}
|
102 |
+
console.log("Formatted", formattedMessages);
|
103 |
+
// const formattedInput =
|
104 |
+
// userInput +
|
105 |
+
// "?. In bulleted points, respond with the key points of the answer for the question and provide a concise answer in markdown format highlighting the keypoints and features using markdown.";
|
106 |
+
const response = await axios.post(routebody.concat("/response"), {
|
107 |
+
query: userInput,
|
108 |
+
chat_history: formattedMessages,
|
109 |
+
});
|
110 |
+
console.log("Answer", response.data.answer);
|
111 |
+
console.log("Time sta", response.data.timestamps);
|
112 |
+
setTimestamps(response.data.timestamps.slice(0, 5));
|
113 |
+
setMessages([
|
114 |
+
...messages,
|
115 |
+
{ role: "user", content: userInput + "?" },
|
116 |
+
{ role: "assistant", content: response.data.answer },
|
117 |
+
]);
|
118 |
+
|
119 |
+
console.log(messages);
|
120 |
+
setUserInput("");
|
121 |
+
setLoading(false);
|
122 |
+
} catch (error) {
|
123 |
+
console.log(error);
|
124 |
+
}
|
125 |
+
};
|
126 |
+
|
127 |
+
const handleKeyPress = (e) => {
|
128 |
+
if (e.key === "Enter" && userInput.trim() !== "") {
|
129 |
+
sendMessage();
|
130 |
+
e.preventDefault(); // To prevent any default behavior, such as a line break in a textarea
|
131 |
+
}
|
132 |
+
};
|
133 |
+
const markdown = "";
|
134 |
+
|
135 |
+
useEffect(() => {
|
136 |
+
async function fetchSummary() {
|
137 |
+
try {
|
138 |
+
console.log("Summarizing...");
|
139 |
+
setLoading(true);
|
140 |
+
const response = await axios.post(routebody.concat("/response"), {
|
141 |
+
query:
|
142 |
+
`You are a Intelligent Tutor. Your task is to smartly summarize the the Youtube video transcript provided as context. \
|
143 |
+
Don't mention the transcript as 'transcript' but refer to it as Youtube video or just video while having a conversation with a student.\
|
144 |
+
Give me in-depth response for the summaray part only... something like : Short-Intro to what is being said in the video transcript.\
|
145 |
+
5 - KEY points to understand in bullet point format... Conclusion as to what can be learnt from this video transcript....\
|
146 |
+
Only the Conclusion in the summary should be application perspective.... \ Also you are a friendly tutor, so if the question asked is casual or something not realted to the video transcript then answer it casually like a friend,
|
147 |
+
only if the question asked is casual or not realted to the context... more of general question ... only then you do this ... other wise stick to the context provided...
|
148 |
+
From thsi point provide all the responses in this chat in Markdown Format highlighting keypoints and fetures. Also for every response you have to give introduction, keypoints and conclusion. Keep in mind that the markdown syntax should be followed for every response that you will give in fututre.`,
|
149 |
+
chat_history: "",
|
150 |
+
});
|
151 |
+
console.log("Answer", response.data.answer);
|
152 |
+
console.log("Time stamp", response.data.timestamps);
|
153 |
+
|
154 |
+
// setTimestamps(response.data.timestamps);
|
155 |
+
// only set first five timestamps
|
156 |
+
setTimestamps(response.data.timestamps.slice(0, 5));
|
157 |
+
setMessages([
|
158 |
+
...messages,
|
159 |
+
{ role: "user", content: userInput },
|
160 |
+
{ role: "assistant", content: response.data.answer },
|
161 |
+
]);
|
162 |
+
|
163 |
+
console.log(messages);
|
164 |
+
setUserInput("");
|
165 |
+
setLoading(false);
|
166 |
+
} catch (error) {
|
167 |
+
console.log(error);
|
168 |
+
}
|
169 |
+
}
|
170 |
+
return () => {
|
171 |
+
// fetch
|
172 |
+
fetchSummary();
|
173 |
+
}
|
174 |
+
}, []);
|
175 |
+
|
176 |
+
// /////////////// data for mindmap ///////////////////////
|
177 |
+
const [data, setData] = useState();
|
178 |
+
|
179 |
+
useEffect(() => {
|
180 |
+
async function fetchMindMap() {
|
181 |
+
try {
|
182 |
+
console.log("Mind Mapping...");
|
183 |
+
setLoading(true);
|
184 |
+
const response = await axios.post(routebody.concat("/response"), {
|
185 |
+
query:
|
186 |
+
`Smart Tutor, please provide a consize creative Mind Map!... The Idea is to Show an intricate, easy to understand (in terms of concept "linking") mind map, based on the provided context\
|
187 |
+
so that the users can understand the video --key contepts-- helping them to know what the video is discussing in-depth!, remember not to over simplifiy the mind-map,\
|
188 |
+
WE can have beautiful looking mind map with branches of important points from the video...
|
189 |
+
We want your response in json object for example: \
|
190 |
+
{
|
191 |
+
"nodes": [
|
192 |
+
{
|
193 |
+
"id": "Main Concept",
|
194 |
+
"group": 1,
|
195 |
+
"size": 30
|
196 |
+
},
|
197 |
+
{
|
198 |
+
"id": "Sub-Concept 1",
|
199 |
+
"group": 2,
|
200 |
+
"size": 20
|
201 |
+
},
|
202 |
+
{
|
203 |
+
"id": "Sub-Concept 2",
|
204 |
+
"group": 2,
|
205 |
+
"size": 20
|
206 |
+
},
|
207 |
+
{
|
208 |
+
"id": "Sub-Concept 3",
|
209 |
+
"group": 2,
|
210 |
+
"size": 20
|
211 |
+
},
|
212 |
+
{
|
213 |
+
"id": "Sub-Concept 4",
|
214 |
+
"group": 2,
|
215 |
+
"size": 20
|
216 |
+
},
|
217 |
+
{
|
218 |
+
"id": "Sub-Concept 5",
|
219 |
+
"group": 2,
|
220 |
+
"size": 20
|
221 |
+
},
|
222 |
+
{
|
223 |
+
"id": "Sub-Concept 6",
|
224 |
+
"group": 2,
|
225 |
+
"size": 20
|
226 |
+
},
|
227 |
+
{
|
228 |
+
"id":"Sub-Sub-Concept 7",
|
229 |
+
"group":2,
|
230 |
+
"size": 15
|
231 |
+
}
|
232 |
+
],
|
233 |
+
"links": [
|
234 |
+
{
|
235 |
+
"source": "Main Concept",
|
236 |
+
"target": "Sub-Concept 1",
|
237 |
+
"value": 10
|
238 |
+
},
|
239 |
+
{
|
240 |
+
"source": "Main Concept",
|
241 |
+
"target": "Sub-Concept 2",
|
242 |
+
"value": 9
|
243 |
+
},
|
244 |
+
{
|
245 |
+
"source": "Main Concept",
|
246 |
+
"target": "Sub-Concept 3",
|
247 |
+
"value": 8
|
248 |
+
},
|
249 |
+
{
|
250 |
+
"source": "Main Concept",
|
251 |
+
"target": "Sub-Concept 4",
|
252 |
+
"value": 7
|
253 |
+
},
|
254 |
+
{
|
255 |
+
"source": "Main Concept",
|
256 |
+
"target": "Sub-Concept 5",
|
257 |
+
"value": 6
|
258 |
+
},
|
259 |
+
{
|
260 |
+
"source": "Main Concept",
|
261 |
+
"target": "Sub-Concept 6",
|
262 |
+
"value": 5
|
263 |
+
},
|
264 |
+
{
|
265 |
+
"source": "Sub-Concept 6",
|
266 |
+
"target": "Sub-Sub-Concept 7",
|
267 |
+
"value": 5
|
268 |
+
}
|
269 |
+
]
|
270 |
+
}
|
271 |
+
This structure can be used as a template or guide to create more specific mind maps based on the requirements of the youtube video transcript provided. You can customize the node names, group assignments, and link weights to reflect the content and relationships in your mind map.
|
272 |
+
only json object of mindmap is expected as output`,
|
273 |
+
chat_history: "",
|
274 |
+
});
|
275 |
+
console.log("MindMap: ", response.data.answer);
|
276 |
+
setData(JSON.parse(response.data.answer));
|
277 |
+
setLoading(false);
|
278 |
+
} catch (error) {
|
279 |
+
console.log(error);
|
280 |
+
}
|
281 |
+
}
|
282 |
+
// fetchMindMap();
|
283 |
+
return () => {
|
284 |
+
// fetch
|
285 |
+
fetchMindMap();
|
286 |
+
}
|
287 |
+
}, []);
|
288 |
+
// /////////////// data for mindmap ///////////////////////
|
289 |
+
|
290 |
+
const CameraOrbit = () => {
|
291 |
+
return (
|
292 |
+
<ForceGraph3D
|
293 |
+
ref={fgRef}
|
294 |
+
graphData={data}
|
295 |
+
// dynamically give width and height based on vh and vw
|
296 |
+
width={window.innerWidth/2 -20}
|
297 |
+
height={window.innerHeight/3}
|
298 |
+
nodeAutoColorBy="id"
|
299 |
+
|
300 |
+
backgroundColor="#f5f5f5"
|
301 |
+
// nodeLabel={(node) => `${node.name}`}
|
302 |
+
// nodeVal={(node) => 2}
|
303 |
+
nodeThreeObject={(node) => {
|
304 |
+
|
305 |
+
const sprite = new SpriteText(node.id);
|
306 |
+
sprite.color = node.color;
|
307 |
+
sprite.textHeight = 8;
|
308 |
+
return sprite;
|
309 |
+
}}
|
310 |
+
linkColor={() => "black"}
|
311 |
+
linkDirectionalParticleColor={() => "red"}
|
312 |
+
linkDirectionalParticleWidth={6}
|
313 |
+
linkHoverPrecision={10}
|
314 |
+
onLinkClick={(link) => fgRef.current.emitParticle(link)}
|
315 |
+
// reset position of camera on double click
|
316 |
+
onNodeClick={(node) => {
|
317 |
+
fgRef.current.centerAt(node.x, node.y, node.z, 1000);
|
318 |
+
}
|
319 |
+
}
|
320 |
+
|
321 |
+
|
322 |
+
/>
|
323 |
+
);
|
324 |
+
};
|
325 |
+
|
326 |
+
const downloadMindmapSVG = () => {
|
327 |
+
console.log("Downloading SVG")
|
328 |
+
const svg = fgRef.current.exportSVG();
|
329 |
+
const blob = new Blob([svg], { type: "image/svg+xml" });
|
330 |
+
const url = URL.createObjectURL(blob);
|
331 |
+
const a = document.createElement
|
332 |
+
("a");
|
333 |
+
a.href = url;
|
334 |
+
a.download = "mindmap.svg";
|
335 |
+
a.click();
|
336 |
+
URL.revokeObjectURL(url);
|
337 |
+
}
|
338 |
+
|
339 |
+
|
340 |
+
return (
|
341 |
+
<div id="App" className="w-full h-screen">
|
342 |
+
<div>
|
343 |
+
<Navbar />
|
344 |
+
</div>
|
345 |
+
<div id="chat-ui" className="grid grid-cols-2 divide-x-2 h-5/6">
|
346 |
+
<div className="flex flex-col lg:col-span-1 col-span-2">
|
347 |
+
<div className=" w-full h-80 justify-center items-center">
|
348 |
+
<h1 className="text-gray-800 font-semibold text-2xl ml-2 mt-2">
|
349 |
+
{metaData}
|
350 |
+
</h1>
|
351 |
+
|
352 |
+
<YouTube
|
353 |
+
className="flex w-full h-full p-2 justify-center items-center"
|
354 |
+
videoId={videoId}
|
355 |
+
opts={{
|
356 |
+
width: "100%",
|
357 |
+
height: "100%",
|
358 |
+
playerVars: {
|
359 |
+
autoplay: 0,
|
360 |
+
start: 40,
|
361 |
+
},
|
362 |
+
}}
|
363 |
+
onReady={onPlayerReady}
|
364 |
+
/>
|
365 |
+
|
366 |
+
{/* <div className="flex justify-center items-center mt-2">
|
367 |
+
<button
|
368 |
+
className={`px-2.5 py-2.5 bg-indigo-600 text-white rounded-md font-semibold text-lg hover:bg-indigo-700 focus:outline-none focus:ring ${
|
369 |
+
loading && "cursor-not-allowed opacity-35 "
|
370 |
+
}`}
|
371 |
+
disabled={loading}
|
372 |
+
onClick={handleClick}
|
373 |
+
>
|
374 |
+
Download transcript. 📥
|
375 |
+
</button>
|
376 |
+
</div> */}
|
377 |
+
<div className="ml-2">
|
378 |
+
{/* <h1>
|
379 |
+
Mindmap
|
380 |
+
</h1> */}
|
381 |
+
<button
|
382 |
+
className={`px-2.5 py-2.5 bg-indigo-600 text-white rounded-md font-semibold text-lg hover:bg-indigo-700 focus:outline-none focus:ring ${
|
383 |
+
loading && "cursor-not-allowed opacity-35 "
|
384 |
+
}`}
|
385 |
+
disabled={loading}
|
386 |
+
onClick={downloadMindmapSVG}
|
387 |
+
>
|
388 |
+
Download transcript. 📥
|
389 |
+
</button>
|
390 |
+
<CameraOrbit />
|
391 |
+
</div>
|
392 |
+
</div>
|
393 |
+
</div>
|
394 |
+
|
395 |
+
<div className="flex flex-col justify-between lg:col-span-1 col-span-2 overflow-auto">
|
396 |
+
<h1 className="p-2 text-2xl text-gray-800 font-semibold text-center">
|
397 |
+
📺 Chat with the Video 📺
|
398 |
+
</h1>
|
399 |
+
<div className="p-2">
|
400 |
+
<div className="flex items-center justify-start flex-col max-h-3/5">
|
401 |
+
<div
|
402 |
+
ref={endOfMessagesRef}
|
403 |
+
className=" p-4 flex flex-col m-4 w-full max-h-4/5 border text-xl border-gray-300 rounded-md bg-gray-100"
|
404 |
+
id="chat-message"
|
405 |
+
>
|
406 |
+
{/* <div>
|
407 |
+
<ReactMarkdown>{"# Markdown"}</ReactMarkdown>
|
408 |
+
</div> */}
|
409 |
+
{messages.map((msg, idx) => (
|
410 |
+
<div
|
411 |
+
key={idx}
|
412 |
+
className={` ${
|
413 |
+
msg.role === "user"
|
414 |
+
? "text-indigo-600 font-bold mt-3"
|
415 |
+
: "text-gray-700 "
|
416 |
+
}`}
|
417 |
+
ref={idx === messages.length - 1 ? endOfMessagesRef : null}
|
418 |
+
>
|
419 |
+
<ReactMarkdown className="markdown">
|
420 |
+
{msg.content}
|
421 |
+
</ReactMarkdown>
|
422 |
+
{/* Show buttopns of 3 timestamps */}
|
423 |
+
{/* {msg.content} */}
|
424 |
+
{msg.role === "assistant" && (
|
425 |
+
<div className="flex space-x-4 mt-2">
|
426 |
+
{timestamps.map((time, idx) => (
|
427 |
+
<button
|
428 |
+
key={idx}
|
429 |
+
className="bg-indigo-200 hover:bg-indigo-400 text-white py-1 px-3 rounded-lg"
|
430 |
+
onClick={() => {
|
431 |
+
if (player) {
|
432 |
+
player.seekTo(time);
|
433 |
+
player.pauseVideo();
|
434 |
+
}
|
435 |
+
}}
|
436 |
+
>
|
437 |
+
{"Ref "}
|
438 |
+
{idx + 1}
|
439 |
+
</button>
|
440 |
+
))}
|
441 |
+
</div>
|
442 |
+
)}
|
443 |
+
</div>
|
444 |
+
))}
|
445 |
+
</div>
|
446 |
+
</div>
|
447 |
+
</div>
|
448 |
+
<div
|
449 |
+
className="p-2 absolute w-full bg-white"
|
450 |
+
id="chat-input"
|
451 |
+
style={{ position: "sticky", bottom: 0 }}
|
452 |
+
>
|
453 |
+
<div className="flex items-center justify-end w-full space-x-4">
|
454 |
+
<input
|
455 |
+
value={userInput}
|
456 |
+
onChange={(e) => setUserInput(e.target.value)}
|
457 |
+
onKeyPress={handleKeyPress}
|
458 |
+
placeholder="🤔 Ask me anything! ... "
|
459 |
+
className="flex-grow w-5/6 px-8 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring focus:border-indigo-500"
|
460 |
+
/>
|
461 |
+
{/* {loading && (
|
462 |
+
<div
|
463 |
+
style={{ position: "relative", right: "640px", top: "50%" }}
|
464 |
+
className="animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-purple-500"
|
465 |
+
></div>
|
466 |
+
)} */}
|
467 |
+
{/* <button
|
468 |
+
onClick={sendMessage}
|
469 |
+
className={`px-2.5 py-2.5 bg-indigo-600 text-white rounded-md font-semibold text-lg hover:bg-indigo-700 focus:outline-none focus:ring ${
|
470 |
+
loading && "cursor-not-allowed opacity-35 "
|
471 |
+
}`}
|
472 |
+
disabled={loading}
|
473 |
+
>
|
474 |
+
📤Send
|
475 |
+
</button> */}
|
476 |
+
<button
|
477 |
+
onClick={sendMessage}
|
478 |
+
disabled={loading}
|
479 |
+
type="button"
|
480 |
+
className="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-3 py-2.5 text-center me-2 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800 inline-flex items-center"
|
481 |
+
>
|
482 |
+
{loading && (
|
483 |
+
<svg
|
484 |
+
aria-hidden="true"
|
485 |
+
role="status"
|
486 |
+
className="inline w-4 h-4 me-3 text-white animate-spin"
|
487 |
+
viewBox="0 0 100 101"
|
488 |
+
fill="none"
|
489 |
+
xmlns="http://www.w3.org/2000/svg"
|
490 |
+
>
|
491 |
+
<path
|
492 |
+
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
493 |
+
fill="#E5E7EB"
|
494 |
+
/>
|
495 |
+
<path
|
496 |
+
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
497 |
+
fill="currentColor"
|
498 |
+
/>
|
499 |
+
</svg>
|
500 |
+
)}
|
501 |
+
{loading ? "Loading..." : "📤 Send"}
|
502 |
+
</button>
|
503 |
+
</div>
|
504 |
+
</div>
|
505 |
+
</div>
|
506 |
+
</div>
|
507 |
+
</div>
|
508 |
+
);
|
509 |
+
}
|
510 |
+
|
511 |
+
export default App;
|
src/Components/Alert.jsx
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, { useState, useEffect } from "react";
|
2 |
+
const Alert = ({ message, type, timer, setState, relod }) => {
|
3 |
+
useEffect(() => {
|
4 |
+
let timeoutId;
|
5 |
+
if (timer) {
|
6 |
+
timeoutId = setTimeout(() => {
|
7 |
+
setState({ state: false });
|
8 |
+
if (relod) {
|
9 |
+
window.location.reload();
|
10 |
+
}
|
11 |
+
}, timer);
|
12 |
+
}
|
13 |
+
|
14 |
+
return () => {
|
15 |
+
clearTimeout(timeoutId);
|
16 |
+
};
|
17 |
+
}, [timer]);
|
18 |
+
const dismissAlert = () => {
|
19 |
+
if (relod) {
|
20 |
+
window.location.reload();
|
21 |
+
}
|
22 |
+
|
23 |
+
setState({ state: false });
|
24 |
+
};
|
25 |
+
|
26 |
+
const renderAlert = () => {
|
27 |
+
let alertClasses = "flex w-96 shadow-lg rounded-lg";
|
28 |
+
let iconColor = "text-gray-700";
|
29 |
+
|
30 |
+
switch (type) {
|
31 |
+
case "info":
|
32 |
+
alertClasses += " bg-blue-500";
|
33 |
+
iconColor = "text-white";
|
34 |
+
break;
|
35 |
+
case "success":
|
36 |
+
alertClasses += " bg-green-600";
|
37 |
+
iconColor = "text-white";
|
38 |
+
break;
|
39 |
+
case "warn":
|
40 |
+
alertClasses += " bg-yellow-600";
|
41 |
+
iconColor = "text-white";
|
42 |
+
break;
|
43 |
+
case "danger":
|
44 |
+
alertClasses += " bg-red-600";
|
45 |
+
iconColor = "text-white";
|
46 |
+
break;
|
47 |
+
default:
|
48 |
+
break;
|
49 |
+
}
|
50 |
+
|
51 |
+
return (
|
52 |
+
<div className="absolute top-4 right-4">
|
53 |
+
<div className={alertClasses}>
|
54 |
+
<div
|
55 |
+
className={`py-4 px-6 rounded-l-lg flex items-center ${iconColor}`}
|
56 |
+
>
|
57 |
+
{type === "info" && (
|
58 |
+
<svg
|
59 |
+
xmlns="http://www.w3.org/2000/svg"
|
60 |
+
className="fill-current"
|
61 |
+
viewBox="0 0 16 16"
|
62 |
+
width="20"
|
63 |
+
height="20"
|
64 |
+
>
|
65 |
+
<path
|
66 |
+
fillRule="evenodd"
|
67 |
+
d="M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM0 8a8 8 0 1116 0A8 8 0 010 8zm6.5-.25A.75.75 0 017.25 7h1a.75.75 0 01.75.75v2.75h.25a.75.75 0 010 1.5h-2a.75.75 0 010-1.5h.25v-2h-.25a.75.75 0 01-.75-.75zM8 6a1 1 0 100-2 1 1 0 000 2z"
|
68 |
+
></path>
|
69 |
+
</svg>
|
70 |
+
)}
|
71 |
+
{type === "success" && (
|
72 |
+
<svg
|
73 |
+
xmlns="http://www.w3.org/2000/svg"
|
74 |
+
className="text-white fill-current"
|
75 |
+
viewBox="0 0 16 16"
|
76 |
+
width="20"
|
77 |
+
height="20"
|
78 |
+
>
|
79 |
+
<path
|
80 |
+
fillRule="evenodd"
|
81 |
+
d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"
|
82 |
+
></path>
|
83 |
+
</svg>
|
84 |
+
)}
|
85 |
+
{type === "warn" && (
|
86 |
+
<svg
|
87 |
+
xmlns="http://www.w3.org/2000/svg"
|
88 |
+
viewBox="0 0 16 16"
|
89 |
+
className="fill-current text-white"
|
90 |
+
width="20"
|
91 |
+
height="20"
|
92 |
+
>
|
93 |
+
<path
|
94 |
+
fillRule="evenodd"
|
95 |
+
d="M8.22 1.754a.25.25 0 00-.44 0L1.698 13.132a.25.25 0 00.22.368h12.164a.25.25 0 00.22-.368L8.22 1.754zm-1.763-.707c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0114.082 15H1.918a1.75 1.75 0 01-1.543-2.575L6.457 1.047zM9 11a1 1 0 11-2 0 1 1 0 012 0zm-.25-5.25a.75.75 0 00-1.5 0v2.5a.75.75 0 001.5 0v-2.5z"
|
96 |
+
></path>
|
97 |
+
</svg>
|
98 |
+
)}
|
99 |
+
{type === "danger" && (
|
100 |
+
<svg
|
101 |
+
xmlns="http://www.w3.org/2000/svg"
|
102 |
+
viewBox="0 0 16 16"
|
103 |
+
className="fill-current text-white"
|
104 |
+
width="20"
|
105 |
+
height="20"
|
106 |
+
>
|
107 |
+
<path
|
108 |
+
fillRule="evenodd"
|
109 |
+
d="M4.47.22A.75.75 0 015 0h6a.75.75 0 01.53.22l4.25 4.25c.141.14.22.331.22.53v6a.75.75 0 01-.22.53l-4.25 4.25A.75.75 0 0111 16H5a.75.75 0 01-.53-.22L.22 11.53A.75.75 0 010 11V5a.75.75 0 01.22-.53L4.47.22zm.84 1.28L1.5 5.31v5.38l3.81 3.81h5.38l3.81-3.81V5.31L10.69 1.5H5.31zM8 4a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 018 4zm0 8a1 1 0 100-2 1 1 0 000 2z"
|
110 |
+
></path>
|
111 |
+
</svg>
|
112 |
+
)}
|
113 |
+
</div>
|
114 |
+
<div className="px-4 py-4 bg-white rounded-r-lg flex justify-between items-center w-full border border-l-transparent border-gray-200">
|
115 |
+
<div>{message}</div>
|
116 |
+
<button onClick={dismissAlert}>
|
117 |
+
<svg
|
118 |
+
xmlns="http://www.w3.org/2000/svg"
|
119 |
+
className="fill-current text-gray-700"
|
120 |
+
viewBox="0 0 16 16"
|
121 |
+
width="20"
|
122 |
+
height="20"
|
123 |
+
>
|
124 |
+
<path
|
125 |
+
fillRule="evenodd"
|
126 |
+
d="M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"
|
127 |
+
></path>
|
128 |
+
</svg>
|
129 |
+
</button>
|
130 |
+
</div>
|
131 |
+
</div>
|
132 |
+
</div>
|
133 |
+
);
|
134 |
+
};
|
135 |
+
|
136 |
+
return renderAlert();
|
137 |
+
};
|
138 |
+
|
139 |
+
export default Alert;
|
src/Components/Mindmap.jsx
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, {useRef} from 'react'
|
2 |
+
import ForceGraph3D from '3d-force-graph';
|
3 |
+
import SpriteText from 'three-spritetext';
|
4 |
+
|
5 |
+
function genRandomTree(N = 9000, reverse = false) {
|
6 |
+
return {
|
7 |
+
nodes: [...Array(N).keys()].map((i) => ({ id: i })),
|
8 |
+
links: [...Array(N).keys()]
|
9 |
+
.filter((id) => id)
|
10 |
+
.map((id) => ({
|
11 |
+
[reverse ? "target" : "source"]: id,
|
12 |
+
[reverse ? "source" : "target"]: Math.round(Math.random() * (id - 1))
|
13 |
+
}))
|
14 |
+
};
|
15 |
+
}
|
16 |
+
const Mindmap = () => {
|
17 |
+
const fgRef = useRef();
|
18 |
+
|
19 |
+
|
20 |
+
const data = genRandomTree();
|
21 |
+
return (
|
22 |
+
<div>
|
23 |
+
|
24 |
+
{/* if data available then only render */}
|
25 |
+
|
26 |
+
|
27 |
+
{data && (
|
28 |
+
<ForceGraph3D
|
29 |
+
ref={fgRef}
|
30 |
+
graphData={data}
|
31 |
+
nodeAutoColorBy="group"
|
32 |
+
/>
|
33 |
+
)}
|
34 |
+
</div>
|
35 |
+
);
|
36 |
+
};
|
37 |
+
|
38 |
+
export default Mindmap;
|
src/Components/Navbar.jsx
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React from "react";
|
2 |
+
import { useNavigate } from "react-router-dom";
|
3 |
+
function Navbar() {
|
4 |
+
const navigate = useNavigate();
|
5 |
+
const handleClick = () => {
|
6 |
+
console.log("Go to home page");
|
7 |
+
navigate("/");
|
8 |
+
};
|
9 |
+
return (
|
10 |
+
<div>
|
11 |
+
<header className="sticky top-0 bg-white shadow">
|
12 |
+
<div className="flex items-center justify-between p-2 mx-auto max-w-7xl">
|
13 |
+
<div className="text-3xl font-bold bg-indigo-600 hover:bg-indigo-700 rounded-lg hover:cursor-pointer ">
|
14 |
+
<h1 className="p-2">
|
15 |
+
<span className="text-white" onClick={handleClick}>
|
16 |
+
{" "}
|
17 |
+
VideoChad🗿{" "}
|
18 |
+
</span>
|
19 |
+
</h1>
|
20 |
+
</div>
|
21 |
+
<button className="flex btn btn-light justify-end">Contact Us</button>
|
22 |
+
</div>
|
23 |
+
</header>
|
24 |
+
</div>
|
25 |
+
);
|
26 |
+
}
|
27 |
+
|
28 |
+
export default Navbar;
|
src/Components/YoutubeC.jsx
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React from "react";
|
2 |
+
import YouTube from "react-youtube";
|
3 |
+
|
4 |
+
function YoutubeC({ videoId, navigate }) {
|
5 |
+
const [player, setPlayer] = React.useState(null);
|
6 |
+
|
7 |
+
const handleClick = () => {
|
8 |
+
console.log("Clicked");
|
9 |
+
if (player) {
|
10 |
+
player.seekTo(120);
|
11 |
+
player.pauseVideo();
|
12 |
+
console.log("Seeking to 120");
|
13 |
+
}
|
14 |
+
};
|
15 |
+
|
16 |
+
const onPlayerReady = (event) => {
|
17 |
+
setPlayer(event.target);
|
18 |
+
console.log("Player is ready");
|
19 |
+
};
|
20 |
+
|
21 |
+
return (
|
22 |
+
<div className="w-full h-96">
|
23 |
+
<h1 className="text-gray-800 font-semibold text-2xl ml-2 mt-2">
|
24 |
+
Youtube Video
|
25 |
+
</h1>
|
26 |
+
|
27 |
+
<YouTube
|
28 |
+
className="w-full h-full p-2"
|
29 |
+
videoId={videoId}
|
30 |
+
opts={{
|
31 |
+
width: "100%",
|
32 |
+
height: "100%",
|
33 |
+
playerVars: {
|
34 |
+
autoplay: 0,
|
35 |
+
start: 40,
|
36 |
+
},
|
37 |
+
}}
|
38 |
+
onReady={onPlayerReady}
|
39 |
+
/>
|
40 |
+
|
41 |
+
<div className="flex justify-center items-center mt-2">
|
42 |
+
<button
|
43 |
+
className="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded-lg"
|
44 |
+
onClick={handleClick}
|
45 |
+
>
|
46 |
+
Take me to Quiz
|
47 |
+
</button>
|
48 |
+
</div>
|
49 |
+
</div>
|
50 |
+
);
|
51 |
+
}
|
52 |
+
|
53 |
+
export default YoutubeC;
|
src/Home.jsx
ADDED
@@ -0,0 +1,250 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, { useState } from "react";
|
2 |
+
import { Link } from "react-router-dom";
|
3 |
+
import Navbar from "./Components/Navbar";
|
4 |
+
import Alert from "./Components/Alert";
|
5 |
+
import axios from "axios";
|
6 |
+
import { useNavigate } from "react-router-dom";
|
7 |
+
|
8 |
+
const HomePage = () => {
|
9 |
+
const [userInput, setUserInput] = useState("");
|
10 |
+
const navigate = useNavigate();
|
11 |
+
const [alert, setAlert] = useState({
|
12 |
+
state: false,
|
13 |
+
type: "",
|
14 |
+
message: "",
|
15 |
+
});
|
16 |
+
|
17 |
+
const [isLoading, setIsLoading] = useState(false); // New state for loading
|
18 |
+
|
19 |
+
const handleInputChange = (e) => {
|
20 |
+
setUserInput(e.target.value);
|
21 |
+
};
|
22 |
+
|
23 |
+
const isValidYouTubeURL = () => {
|
24 |
+
const youtubePattern =
|
25 |
+
/^(https?:\/\/)?(www\.)?(youtube\.com\/watch\?v=|youtu\.be\/)[\w-]{11}(&\S*)?$/;
|
26 |
+
return userInput.match(youtubePattern);
|
27 |
+
};
|
28 |
+
function extractYouTubeVideoUrl(url) {
|
29 |
+
const regex = /^(https:\/\/www\.youtube\.com\/watch\?v=[^&]+)/;
|
30 |
+
const match = url.match(regex);
|
31 |
+
return match ? match[1] : null;
|
32 |
+
}
|
33 |
+
|
34 |
+
const handleSendClick = async () => {
|
35 |
+
if (isValidYouTubeURL()) {
|
36 |
+
// If the input is a valid YouTube URL
|
37 |
+
// Extract the video ID from the URL
|
38 |
+
const videoId = extractYouTubeVideoUrl(userInput);
|
39 |
+
setUserInput(videoId);
|
40 |
+
setAlert({ state: false, type: "", message: "" });
|
41 |
+
setIsLoading(true); // Set loading to true before making the request
|
42 |
+
try {
|
43 |
+
const response = await axios.post("http://localhost:5000/init", {
|
44 |
+
yt_link: videoId,
|
45 |
+
});
|
46 |
+
console.log("Sent YT link :)", response);
|
47 |
+
navigate("/app", {
|
48 |
+
state: {
|
49 |
+
videoLink: videoId,
|
50 |
+
metaData: response.data.metadata.title,
|
51 |
+
},
|
52 |
+
});
|
53 |
+
} catch (error) {
|
54 |
+
console.error("Error sending YT link:", error);
|
55 |
+
setAlert({
|
56 |
+
state: true,
|
57 |
+
type: "danger",
|
58 |
+
message: "Error processing your request. Please try again.",
|
59 |
+
});
|
60 |
+
} finally {
|
61 |
+
setIsLoading(false); // Set loading to false after receiving the response or if there's an error
|
62 |
+
}
|
63 |
+
} else {
|
64 |
+
setAlert({
|
65 |
+
state: true,
|
66 |
+
type: "danger",
|
67 |
+
message: "Please enter a valid video link",
|
68 |
+
});
|
69 |
+
}
|
70 |
+
};
|
71 |
+
|
72 |
+
return (
|
73 |
+
<div>
|
74 |
+
<Navbar />
|
75 |
+
{alert.state && (
|
76 |
+
<Alert
|
77 |
+
message={alert.message}
|
78 |
+
type={alert.type}
|
79 |
+
setState={setAlert}
|
80 |
+
timer={5000}
|
81 |
+
/>
|
82 |
+
)}
|
83 |
+
|
84 |
+
{/* Loading overlay */}
|
85 |
+
{isLoading && (
|
86 |
+
// <div >
|
87 |
+
// <div className="animate-spin rounded-full h-40 w-40 border-t-2 border-b-2 border-purple-500"></div>
|
88 |
+
// </div>
|
89 |
+
<div
|
90 |
+
role="status"
|
91 |
+
className="fixed inset-0 bg-white bg-opacity-50 text-center mt-16 flex items-center justify-center z-50"
|
92 |
+
>
|
93 |
+
<svg
|
94 |
+
aria-hidden="true"
|
95 |
+
class="inline w-20 h-20 text-gray-200 animate-spin dark:text-gray-600 fill-purple-600"
|
96 |
+
viewBox="0 0 100 101"
|
97 |
+
fill="none"
|
98 |
+
xmlns="http://www.w3.org/2000/svg"
|
99 |
+
>
|
100 |
+
<path
|
101 |
+
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
102 |
+
fill="currentColor"
|
103 |
+
/>
|
104 |
+
<path
|
105 |
+
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
106 |
+
fill="currentFill"
|
107 |
+
/>
|
108 |
+
</svg>
|
109 |
+
<span class="sr-only">Loading...</span>
|
110 |
+
</div>
|
111 |
+
)}
|
112 |
+
|
113 |
+
<div
|
114 |
+
className={`${
|
115 |
+
alert.state ? "opacity-40 cursor-not-allowed mt-16" : ""
|
116 |
+
}`}
|
117 |
+
>
|
118 |
+
<div id="info">
|
119 |
+
<header className="bg-gray-50">
|
120 |
+
<div className="mx-auto max-w-screen-xl m-4">
|
121 |
+
<div className="sm:flex sm:items-center sm:justify-between">
|
122 |
+
<div className="text-left sm:text-left">
|
123 |
+
<h1 className=" text-5xl font-bold text-gray-900 sm:text-3xl">
|
124 |
+
Welcome to Video Chad!
|
125 |
+
</h1>
|
126 |
+
|
127 |
+
<p className="mt-1.5 text-lg text-gray-500">
|
128 |
+
Chat with Youtube videos! 🎉 Created by
|
129 |
+
{/* add href anchor for name and github */}
|
130 |
+
<a
|
131 |
+
href="https://github.com/MaxxCode8"
|
132 |
+
className="text-indigo-500 hover:underline"
|
133 |
+
>
|
134 |
+
{" "}
|
135 |
+
Malhar Kulkarni
|
136 |
+
</a>
|
137 |
+
{" "},
|
138 |
+
<a
|
139 |
+
href="https://github.com/kuldeepaher01
|
140 |
+
"
|
141 |
+
className="text-indigo-500 hover:underline"
|
142 |
+
>
|
143 |
+
{" "}
|
144 |
+
Kuldeep Aher
|
145 |
+
</a>
|
146 |
+
|
147 |
+
|
148 |
+
{" "}
|
149 |
+
and
|
150 |
+
<a
|
151 |
+
href="https://github.com/"
|
152 |
+
className="text-indigo-500 hover:underline"
|
153 |
+
>
|
154 |
+
{" "}
|
155 |
+
Sandesh Tangade
|
156 |
+
</a>
|
157 |
+
{" "}
|
158 |
+
Under the guidance of <a
|
159 |
+
href="https://www.linkedin.com/in/jyoti-madake-042b08ab/"
|
160 |
+
className="text-indigo-500 hover:underline"
|
161 |
+
>
|
162 |
+
{" "}
|
163 |
+
Prof. Jyoti Madake
|
164 |
+
</a>
|
165 |
+
{". "}
|
166 |
+
VIT, Pune Dept of Electronics and Telecommunications Engineering
|
167 |
+
|
168 |
+
</p>
|
169 |
+
</div>
|
170 |
+
|
171 |
+
<div className="mt-4 flex flex-col gap-4 sm:mt-0 sm:flex-row sm:items-center">
|
172 |
+
<button
|
173 |
+
className="inline-flex items-center justify-center gap-1.5 rounded-lg border border-gray-200 bg-white px-5 py-3 text-gray-500 transition hover:text-gray-700 focus:outline-none focus:ring"
|
174 |
+
type="button"
|
175 |
+
onClick={() =>
|
176 |
+
window.open("https://nptel.ac.in/course.html", "_blank")
|
177 |
+
}
|
178 |
+
>
|
179 |
+
<span className="text-sm font-medium"> Go To NPTEL </span>
|
180 |
+
|
181 |
+
<svg
|
182 |
+
xmlns="http://www.w3.org/2000/svg"
|
183 |
+
className="h-4 w-4"
|
184 |
+
fill="none"
|
185 |
+
viewBox="0 0 24 24"
|
186 |
+
stroke="currentColor"
|
187 |
+
strokeWidth="2"
|
188 |
+
>
|
189 |
+
<path
|
190 |
+
strokeLinecap="round"
|
191 |
+
strokeLinejoin="round"
|
192 |
+
d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
|
193 |
+
/>
|
194 |
+
</svg>
|
195 |
+
</button>
|
196 |
+
</div>
|
197 |
+
</div>
|
198 |
+
</div>
|
199 |
+
</header>
|
200 |
+
</div>
|
201 |
+
{/* What is NPTEL and what does this tool do */}
|
202 |
+
<div className="mx-auto max-w-screen-xl">
|
203 |
+
<div className="sm:flex sm:items-center sm:justify-between">
|
204 |
+
<div className=" sm:text-left">
|
205 |
+
<h1 className=" text-5xl font-bold text-gray-900 sm:text-3xl text-left ">
|
206 |
+
How to use this tool?
|
207 |
+
</h1>
|
208 |
+
|
209 |
+
<p className="mt-1.5 text-lg text-gray-500 text-justify">
|
210 |
+
Simply find any youtube video that you would like to chat with
|
211 |
+
and paste the link below.
|
212 |
+
New window will open with the video and chat box. First a summary of the video will be shown and then you can chat with the video.
|
213 |
+
Along with the answer of your question, the timestamps or refrences video will be showed in the chat box, You can simply click on the timestamp to jump to that part of the video.
|
214 |
+
</p>
|
215 |
+
<p className="mt-1.5 text-lg text-gray-900 text-justify">⚠️ Just ensure the video has english subtitles</p>
|
216 |
+
|
217 |
+
{/* This is an AI tool which will help you summarise long NPTEL educational Videos ndd then Chat with them, write how this will help in learning and understanding */}
|
218 |
+
|
219 |
+
</div>
|
220 |
+
</div>
|
221 |
+
</div>
|
222 |
+
<div>
|
223 |
+
{/* input for nptel video link (YT) */}
|
224 |
+
<div className="mt-4 flex flex-row items-center justify-center align-middle space-x-4 ">
|
225 |
+
<div className="mt-4 w-9/12">
|
226 |
+
<input
|
227 |
+
type="text"
|
228 |
+
placeholder="Enter a YouTube video link"
|
229 |
+
className="w-full px-2 py-2 text-lg border border-gray-300 rounded-md focus:outline-none focus:ring focus:border-indigo-500"
|
230 |
+
value={userInput}
|
231 |
+
onChange={handleInputChange}
|
232 |
+
/>
|
233 |
+
</div>
|
234 |
+
|
235 |
+
<div className="mt-4">
|
236 |
+
<button
|
237 |
+
className=" px-4 py-2 bg-indigo-600 text-white rounded-md font-semibold text-lg hover:bg-indigo-700 focus:outline-none focus:ring"
|
238 |
+
onClick={handleSendClick}
|
239 |
+
>
|
240 |
+
Chat Now
|
241 |
+
</button>
|
242 |
+
</div>
|
243 |
+
</div>
|
244 |
+
</div>
|
245 |
+
</div>
|
246 |
+
</div>
|
247 |
+
);
|
248 |
+
};
|
249 |
+
|
250 |
+
export default HomePage;
|
src/assets/react.svg
ADDED
src/index.css
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
@tailwind base;
|
2 |
+
@tailwind components;
|
3 |
+
@tailwind utilities;
|
4 |
+
@keyframes typing {
|
5 |
+
from {
|
6 |
+
width: 0;
|
7 |
+
}
|
8 |
+
to {
|
9 |
+
width: 100%;
|
10 |
+
}
|
11 |
+
}
|
12 |
+
.markdown > * {
|
13 |
+
all: revert;
|
14 |
+
}
|
15 |
+
.typing {
|
16 |
+
width: 100%;
|
17 |
+
white-space: nowrap;
|
18 |
+
overflow: hidden;
|
19 |
+
border-right: 0.15em solid rgb(255, 255, 255);
|
20 |
+
animation: typing 3.5s steps(40, end), blink-caret 0.75s step-end infinite;
|
21 |
+
}
|
22 |
+
|
23 |
+
@keyframes blink-caret {
|
24 |
+
from,
|
25 |
+
to {
|
26 |
+
border-color: transparent;
|
27 |
+
}
|
28 |
+
50% {
|
29 |
+
border-color: orange;
|
30 |
+
}
|
31 |
+
}
|
src/main.jsx
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React from "react";
|
2 |
+
import ReactDOM from "react-dom/client";
|
3 |
+
import App from "./App.jsx";
|
4 |
+
import Home from "./Home.jsx";
|
5 |
+
import { BrowserRouter, Routes, Route } from "react-router-dom";
|
6 |
+
import "bootstrap/dist/css/bootstrap.min.css";
|
7 |
+
import "./index.css";
|
8 |
+
|
9 |
+
const root = ReactDOM.createRoot(document.getElementById("root"));
|
10 |
+
root.render(
|
11 |
+
<React.StrictMode>
|
12 |
+
<BrowserRouter>
|
13 |
+
<Routes>
|
14 |
+
<Route path="/app" element={<App />}/>
|
15 |
+
<Route path="/" element={<Home />}/>
|
16 |
+
</Routes>
|
17 |
+
</BrowserRouter>
|
18 |
+
</React.StrictMode>
|
19 |
+
);
|
src/temp.jsx
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React, { useState, useEffect, useRef } from "react";
|
2 |
+
import { useNavigate, useLocation } from "react-router-dom";
|
3 |
+
import Navbar from "./Components/Navbar";
|
4 |
+
import axios from "axios";
|
5 |
+
import "./App.css";
|
6 |
+
import YouTube from "react-youtube";
|
7 |
+
|
8 |
+
function App() {
|
9 |
+
const navigate = useNavigate();
|
10 |
+
const [messages, setMessages] = useState([]);
|
11 |
+
const [userInput, setUserInput] = useState("");
|
12 |
+
const location = useLocation(); // Access the location object
|
13 |
+
const videoLink = location.state?.videoLink; // Access the videoLink from the state
|
14 |
+
const [embedLink, setEmbedLink] = useState("");
|
15 |
+
const [videoId, setVideoId] = useState("");
|
16 |
+
const endOfMessagesRef = useRef(null);
|
17 |
+
const scrollToBottom = () => {
|
18 |
+
if (endOfMessagesRef.current) {
|
19 |
+
endOfMessagesRef.current.scrollIntoView({ behavior: "smooth" });
|
20 |
+
}
|
21 |
+
};
|
22 |
+
|
23 |
+
useEffect(() => {
|
24 |
+
scrollToBottom();
|
25 |
+
}, [messages]);
|
26 |
+
|
27 |
+
const [loading, setLoading] = useState(false);
|
28 |
+
|
29 |
+
console.log(videoLink);
|
30 |
+
useEffect(() => {
|
31 |
+
function convertToEmbedUrl(watchUrl) {
|
32 |
+
return watchUrl.replace("/watch?v=", "/embed/");
|
33 |
+
}
|
34 |
+
if (videoLink) {
|
35 |
+
setEmbedLink(convertToEmbedUrl(videoLink));
|
36 |
+
setVideoId(videoLink.split("v=")[1]);
|
37 |
+
} else {
|
38 |
+
navigate("/");
|
39 |
+
}
|
40 |
+
}, []);
|
41 |
+
|
42 |
+
const sendMessage = async () => {
|
43 |
+
try {
|
44 |
+
console.log("Sending message...");
|
45 |
+
setLoading(true);
|
46 |
+
|
47 |
+
const response = await axios.post("http://localhost:5000/message", {
|
48 |
+
prompt: userInput,
|
49 |
+
});
|
50 |
+
setMessages([
|
51 |
+
...messages,
|
52 |
+
{ role: "user", content: userInput },
|
53 |
+
{ role: "assistant", content: response.data.assistant_message },
|
54 |
+
]);
|
55 |
+
setUserInput("");
|
56 |
+
setLoading(false);
|
57 |
+
} catch (error) {
|
58 |
+
console.log(error);
|
59 |
+
}
|
60 |
+
};
|
61 |
+
|
62 |
+
const handleKeyPress = (e) => {
|
63 |
+
if (e.key === "Enter" && userInput.trim() !== "") {
|
64 |
+
sendMessage();
|
65 |
+
e.preventDefault(); // To prevent any default behavior, such as a line break in a textarea
|
66 |
+
}
|
67 |
+
};
|
68 |
+
|
69 |
+
return (
|
70 |
+
<div className="flex flex-col h-screen">
|
71 |
+
<Navbar />
|
72 |
+
<div className="flex flex-grow">
|
73 |
+
{/* YouTube Video Player */}
|
74 |
+
<div className="w-1/2 bg-white">
|
75 |
+
<div className="p-4">
|
76 |
+
<h1></h1>
|
77 |
+
<YouTube
|
78 |
+
className="w-full h-96"
|
79 |
+
videoId={videoId}
|
80 |
+
opts={{
|
81 |
+
width: "100%",
|
82 |
+
playerVars: {
|
83 |
+
autoplay: 1,
|
84 |
+
},
|
85 |
+
}}
|
86 |
+
/>
|
87 |
+
</div>
|
88 |
+
</div>
|
89 |
+
<div>
|
90 |
+
<div className="border-r-2 border-gray-300 h-screen"></div>
|
91 |
+
</div>
|
92 |
+
|
93 |
+
<div className="w-1/2 bg-white">
|
94 |
+
<div className=" p-6">
|
95 |
+
<h1 className="text-2xl font-bold">Chat with Video!</h1>
|
96 |
+
<div
|
97 |
+
ref={endOfMessagesRef}
|
98 |
+
className="mt-4 overflow-y-auto flex-grow max-h-full border border-gray-300 rounded-md p-4 bg-gray-100"
|
99 |
+
id="chat-message"
|
100 |
+
>
|
101 |
+
{messages.map((msg, idx) => (
|
102 |
+
<div
|
103 |
+
key={idx}
|
104 |
+
className={`${
|
105 |
+
msg.role === "user"
|
106 |
+
? "text-indigo-600 font-semibold"
|
107 |
+
: "text-gray-700 "
|
108 |
+
}`}
|
109 |
+
ref={idx === messages.length - 1 ? endOfMessagesRef : null}
|
110 |
+
>
|
111 |
+
{msg.content}
|
112 |
+
</div>
|
113 |
+
))}
|
114 |
+
{loading && (
|
115 |
+
<div className="text-green-400">Getting response...</div>
|
116 |
+
)}
|
117 |
+
</div>
|
118 |
+
<div className="mb-4 flex sticky bottom-0 bg-white" id="chat-input">
|
119 |
+
<input
|
120 |
+
value={userInput}
|
121 |
+
onChange={(e) => setUserInput(e.target.value)}
|
122 |
+
onKeyPress={handleKeyPress}
|
123 |
+
placeholder="Type your query here..."
|
124 |
+
className="flex-grow px-2 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring focus:border-indigo-500"
|
125 |
+
/>
|
126 |
+
<button
|
127 |
+
onClick={sendMessage}
|
128 |
+
className={`ml-2 px-4 py-2 bg-indigo-600 text-white rounded-md font-semibold text-lg hover:bg-indigo-700 focus:outline-none focus:ring ${
|
129 |
+
loading && "cursor-not-allowed opacity-35"
|
130 |
+
}`}
|
131 |
+
disabled={loading}
|
132 |
+
>
|
133 |
+
Send
|
134 |
+
</button>
|
135 |
+
</div>
|
136 |
+
</div>
|
137 |
+
</div>
|
138 |
+
</div>
|
139 |
+
</div>
|
140 |
+
);
|
141 |
+
}
|
142 |
+
|
143 |
+
export default App;
|