import React, { useState } from "react"; import { Link } from "react-router-dom"; import Navbar from "./Components/Navbar"; import Alert from "./Components/Alert"; import axios from "axios"; import { useNavigate } from "react-router-dom"; const HomePage = () => { const [userInput, setUserInput] = useState(""); const navigate = useNavigate(); const [alert, setAlert] = useState({ state: false, type: "", message: "", }); const [isLoading, setIsLoading] = useState(false); // New state for loading const handleInputChange = (e) => { setUserInput(e.target.value); }; const isValidYouTubeURL = () => { const youtubePattern = /^(https?:\/\/)?(www\.)?(youtube\.com\/watch\?v=|youtu\.be\/)[\w-]{11}(&\S*)?$/; return userInput.match(youtubePattern); }; function extractYouTubeVideoUrl(url) { const regex = /^(https:\/\/www\.youtube\.com\/watch\?v=[^&]+)/; const match = url.match(regex); return match ? match[1] : null; } const handleSendClick = async () => { if (isValidYouTubeURL()) { // If the input is a valid YouTube URL // Extract the video ID from the URL const videoId = extractYouTubeVideoUrl(userInput); setUserInput(videoId); setAlert({ state: false, type: "", message: "" }); setIsLoading(true); // Set loading to true before making the request try { const response = await axios.post("http://localhost:5000/init", { yt_link: videoId, }); console.log("Sent YT link :)", response); navigate("/app", { state: { videoLink: videoId, metaData: response.data.metadata.title, }, }); } catch (error) { console.error("Error sending YT link:", error); setAlert({ state: true, type: "danger", message: "Error processing your request. Please try again.", }); } finally { setIsLoading(false); // Set loading to false after receiving the response or if there's an error } } else { setAlert({ state: true, type: "danger", message: "Please enter a valid video link", }); } }; return (
{alert.state && ( )} {/* Loading overlay */} {isLoading && ( //
//
//
Loading...
)}

Welcome to Video Chad!

Chat with Youtube videos! 🎉 Created by {/* add href anchor for name and github */} {" "} Malhar Kulkarni {" "}, {" "} Kuldeep Aher {" "} and {" "} Sandesh Tangade {" "} Under the guidance of {" "} Prof. Jyoti Madake {". "} VIT, Pune Dept of Electronics and Telecommunications Engineering

{/* What is NPTEL and what does this tool do */}

How to use this tool?

Simply find any youtube video that you would like to chat with and paste the link below. 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. 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.

⚠️ Just ensure the video has english subtitles

{/* 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 */}
{/* input for nptel video link (YT) */}
); }; export default HomePage;