From 002b2572d29b1c362ad0ad0b8f0a79525a02e752 Mon Sep 17 00:00:00 2001 From: Rishika-pasricha <2401730086@krmu.edu.in> Date: Sat, 22 Feb 2025 00:52:56 +0530 Subject: [PATCH] Add files via upload --- bharat pathshala/Backend/Packages.json | 17 ++++ bharat pathshala/Backend/models/Quizs.js | 9 ++ bharat pathshala/Backend/models/Resource.js | 0 bharat pathshala/Backend/models/user.js | 0 bharat pathshala/Backend/server.js | 0 bharat pathshala/ai-services/chatbot/app.py | 0 .../ai-services/chatbot/requirements.txt | 2 + .../ai-services/doubt-solver/app.py | 17 ++++ .../ai-services/doubt-solver/requirements.txt | 2 + bharat pathshala/frontend/Style.css | 71 ++++++++++++++ bharat pathshala/frontend/app.js | 34 +++++++ bharat pathshala/frontend/package.json | 20 ++++ bharat pathshala/frontend/public/index.html | 92 +++++++++++++++++++ bharat pathshala/frontend/socket.js | 8 ++ .../frontend/src/components/Chatbot.js | 37 ++++++++ .../frontend/src/components/Dashboard.js | 0 .../frontend/src/components/DoubtSolver.js | 38 ++++++++ .../frontend/src/components/Navbar.js | 35 +++++++ .../frontend/src/components/Quiz.js | 45 +++++++++ .../frontend/src/components/VideoPlayer.js | 65 +++++++++++++ bharat pathshala/frontend/src/pages/Home.js | 12 +++ bharat pathshala/frontend/src/pages/Login.js | 0 .../frontend/src/pages/Register.js | 31 +++++++ 23 files changed, 535 insertions(+) create mode 100644 bharat pathshala/Backend/Packages.json create mode 100644 bharat pathshala/Backend/models/Quizs.js create mode 100644 bharat pathshala/Backend/models/Resource.js create mode 100644 bharat pathshala/Backend/models/user.js create mode 100644 bharat pathshala/Backend/server.js create mode 100644 bharat pathshala/ai-services/chatbot/app.py create mode 100644 bharat pathshala/ai-services/chatbot/requirements.txt create mode 100644 bharat pathshala/ai-services/doubt-solver/app.py create mode 100644 bharat pathshala/ai-services/doubt-solver/requirements.txt create mode 100644 bharat pathshala/frontend/Style.css create mode 100644 bharat pathshala/frontend/app.js create mode 100644 bharat pathshala/frontend/package.json create mode 100644 bharat pathshala/frontend/public/index.html create mode 100644 bharat pathshala/frontend/socket.js create mode 100644 bharat pathshala/frontend/src/components/Chatbot.js create mode 100644 bharat pathshala/frontend/src/components/Dashboard.js create mode 100644 bharat pathshala/frontend/src/components/DoubtSolver.js create mode 100644 bharat pathshala/frontend/src/components/Navbar.js create mode 100644 bharat pathshala/frontend/src/components/Quiz.js create mode 100644 bharat pathshala/frontend/src/components/VideoPlayer.js create mode 100644 bharat pathshala/frontend/src/pages/Home.js create mode 100644 bharat pathshala/frontend/src/pages/Login.js create mode 100644 bharat pathshala/frontend/src/pages/Register.js diff --git a/bharat pathshala/Backend/Packages.json b/bharat pathshala/Backend/Packages.json new file mode 100644 index 000000000..58d4a93cd --- /dev/null +++ b/bharat pathshala/Backend/Packages.json @@ -0,0 +1,17 @@ +{ + "name": "eduwebsite-backend", + "version": "1.0.0", + "dependencies": { + "axios": "^1.6.0", + "bcrypt": "^5.1.0", + "cors": "^2.8.5", + "express": "^4.18.2", + "jsonwebtoken": "^9.0.0", + "mongoose": "^7.4.0", + "openai": "^4.0.0", + "socket.io": "^4.7.0" + }, + "scripts": { + "start": "node server.js" + } + } \ No newline at end of file diff --git a/bharat pathshala/Backend/models/Quizs.js b/bharat pathshala/Backend/models/Quizs.js new file mode 100644 index 000000000..02e56a6b4 --- /dev/null +++ b/bharat pathshala/Backend/models/Quizs.js @@ -0,0 +1,9 @@ +const mongoose = require('mongoose'); + +const quizSchema = new mongoose.Schema({ + userId: String, + score: Number, + date: { type: Date, default: Date.now }, +}); + +module.exports = mongoose.model('Quiz', quizSchema); \ No newline at end of file diff --git a/bharat pathshala/Backend/models/Resource.js b/bharat pathshala/Backend/models/Resource.js new file mode 100644 index 000000000..e69de29bb diff --git a/bharat pathshala/Backend/models/user.js b/bharat pathshala/Backend/models/user.js new file mode 100644 index 000000000..e69de29bb diff --git a/bharat pathshala/Backend/server.js b/bharat pathshala/Backend/server.js new file mode 100644 index 000000000..e69de29bb diff --git a/bharat pathshala/ai-services/chatbot/app.py b/bharat pathshala/ai-services/chatbot/app.py new file mode 100644 index 000000000..e69de29bb diff --git a/bharat pathshala/ai-services/chatbot/requirements.txt b/bharat pathshala/ai-services/chatbot/requirements.txt new file mode 100644 index 000000000..694043581 --- /dev/null +++ b/bharat pathshala/ai-services/chatbot/requirements.txt @@ -0,0 +1,2 @@ +Flask==2.3.2 +chatterbot==1.0.5 \ No newline at end of file diff --git a/bharat pathshala/ai-services/doubt-solver/app.py b/bharat pathshala/ai-services/doubt-solver/app.py new file mode 100644 index 000000000..c0648979a --- /dev/null +++ b/bharat pathshala/ai-services/doubt-solver/app.py @@ -0,0 +1,17 @@ +from flask import Flask, request, jsonify +from sympy import sympify, solve + +app = Flask(__name__) + +@app.route('/solve', methods=['POST']) +def solve_equation(): + equation = request.json['equation'] + try: + expr = sympify(equation) + solutions = solve(expr) + return jsonify({'solutions': [str(sol) for sol in solutions]}) + except Exception as e: + return jsonify({'error': str(e)}) + +if __name__ == '__main__': + app.run(port=5002) \ No newline at end of file diff --git a/bharat pathshala/ai-services/doubt-solver/requirements.txt b/bharat pathshala/ai-services/doubt-solver/requirements.txt new file mode 100644 index 000000000..4579fb712 --- /dev/null +++ b/bharat pathshala/ai-services/doubt-solver/requirements.txt @@ -0,0 +1,2 @@ +Flask==2.3.2 +sympy==1.12 \ No newline at end of file diff --git a/bharat pathshala/frontend/Style.css b/bharat pathshala/frontend/Style.css new file mode 100644 index 000000000..bd0709676 --- /dev/null +++ b/bharat pathshala/frontend/Style.css @@ -0,0 +1,71 @@ +body { + font-family: Arial, sans-serif; + margin: 0; + padding: 0; + } + + .container { + padding: 20px; + max-width: 1200px; + margin: 0 auto; + } + + .navbar { + background-color: #333; + padding: 10px; + display: flex; + justify-content: space-between; + align-items: center; + } + + .nav-brand { + color: white; + text-decoration: none; + font-size: 1.5em; + } + + .nav-links { + list-style: none; + display: flex; + margin: 0; + } + + .nav-links li { + margin-left: 20px; + } + + .nav-links a, .nav-links button { + color: white; + text-decoration: none; + background: none; + border: none; + cursor: pointer; + } + + .nav-links a:hover, .nav-links button:hover { + color: #ddd; + } + + .chat-container { + border: 1px solid #ccc; + padding: 10px; + height: 300px; + overflow-y: auto; + margin-bottom: 10px; + } + + input, button { + margin: 5px; + padding: 8px; + } + + button { + background-color: #007bff; + color: white; + border: none; + cursor: pointer; + } + + button:hover { + background-color: #0056b3; + } \ No newline at end of file diff --git a/bharat pathshala/frontend/app.js b/bharat pathshala/frontend/app.js new file mode 100644 index 000000000..6c1c39842 --- /dev/null +++ b/bharat pathshala/frontend/app.js @@ -0,0 +1,34 @@ +import React from 'react'; +import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; +import Navbar from './components/Navbar'; +import Home from './pages/Home'; +import Login from './pages/Login'; +import Register from './pages/Register'; +import Dashboard from './components/Dashboard'; +import Chatbot from './components/Chatbot'; +import DoubtSolver from './components/DoubtSolver'; +import VideoPlayer from './components/VideoPlayer'; +import Quiz from './components/Quiz'; +import './styles.css'; + +function App() { + return ( + + +
+ + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + +
+
+ ); +} + +export default App; \ No newline at end of file diff --git a/bharat pathshala/frontend/package.json b/bharat pathshala/frontend/package.json new file mode 100644 index 000000000..8472dd693 --- /dev/null +++ b/bharat pathshala/frontend/package.json @@ -0,0 +1,20 @@ +{ + "name": "bharatphathshala-frontend", + "version": "0.1.0", + "dependencies": { + "axios": "^1.6.0", + "d3": "^7.8.0", + "p5": "^1.4.2", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "react-router-dom": "^6.14.0", + "socket.io-client": "^4.7.0" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "proxy": "http://localhost:5000" + } \ No newline at end of file diff --git a/bharat pathshala/frontend/public/index.html b/bharat pathshala/frontend/public/index.html new file mode 100644 index 000000000..df1b1a7dd --- /dev/null +++ b/bharat pathshala/frontend/public/index.html @@ -0,0 +1,92 @@ + + + + + + Chat UI + + + + +
+ +
+
+ +
+ What can I help with? +
+ +
+
+ +
🎤
+
+ + + \ No newline at end of file diff --git a/bharat pathshala/frontend/socket.js b/bharat pathshala/frontend/socket.js new file mode 100644 index 000000000..75586325f --- /dev/null +++ b/bharat pathshala/frontend/socket.js @@ -0,0 +1,8 @@ +import io from 'socket.io-client'; + +const socket = io('http://localhost:5000'); +socket.on('notification', (msg) => { + alert(msg); +}); + +export default socket; \ No newline at end of file diff --git a/bharat pathshala/frontend/src/components/Chatbot.js b/bharat pathshala/frontend/src/components/Chatbot.js new file mode 100644 index 000000000..75db934ed --- /dev/null +++ b/bharat pathshala/frontend/src/components/Chatbot.js @@ -0,0 +1,37 @@ +import React, { useState } from 'react'; +import axios from 'axios'; + +function Chatbot() { + const [message, setMessage] = useState(''); + const [chat, setChat] = useState([]); + + const sendMessage = async () => { + if (!message) return; + const response = await axios.post('/chat', { message }); + setChat([...chat, { user: message, bot: response.data.response }]); + setMessage(''); + }; + + return ( +
+

AI Chatbot Tutor

+
+ {chat.map((entry, idx) => ( +
+

You: {entry.user}

+

Bot: {entry.bot}

+
+ ))} +
+ setMessage(e.target.value)} + placeholder="Ask a question..." + /> + +
+ ); +} + +export default Chatbot; \ No newline at end of file diff --git a/bharat pathshala/frontend/src/components/Dashboard.js b/bharat pathshala/frontend/src/components/Dashboard.js new file mode 100644 index 000000000..e69de29bb diff --git a/bharat pathshala/frontend/src/components/DoubtSolver.js b/bharat pathshala/frontend/src/components/DoubtSolver.js new file mode 100644 index 000000000..328987114 --- /dev/null +++ b/bharat pathshala/frontend/src/components/DoubtSolver.js @@ -0,0 +1,38 @@ +import React, { useState } from 'react'; +import axios from 'axios'; + +function DoubtSolver() { + const [equation, setEquation] = useState(''); + const [solutions, setSolutions] = useState([]); + const [error, setError] = useState(''); + + const solveEquation = async () => { + try { + const response = await axios.post('/solve', { equation }); + setSolutions(response.data.solutions); + setError(''); + } catch (err) { + setError(err.response?.data?.error || 'Invalid input'); + setSolutions([]); + } + }; + + return ( +
+

Doubt Solver

+ setEquation(e.target.value)} + placeholder="e.g., x^2 - 4 = 0" + /> + + {solutions.length > 0 && ( +

Solutions: {solutions.join(', ')}

+ )} + {error &&

{error}

} +
+ ); +} + +export default DoubtSolver; \ No newline at end of file diff --git a/bharat pathshala/frontend/src/components/Navbar.js b/bharat pathshala/frontend/src/components/Navbar.js new file mode 100644 index 000000000..3dfba7985 --- /dev/null +++ b/bharat pathshala/frontend/src/components/Navbar.js @@ -0,0 +1,35 @@ +import React from 'react'; +import { Link, useNavigate } from 'react-router-dom'; + +function Navbar() { + const navigate = useNavigate(); + const token = localStorage.getItem('token'); + + const handleLogout = () => { + localStorage.removeItem('token'); + navigate('/login'); + }; + + return ( + + ); +} + +export default Navbar; \ No newline at end of file diff --git a/bharat pathshala/frontend/src/components/Quiz.js b/bharat pathshala/frontend/src/components/Quiz.js new file mode 100644 index 000000000..a5da38d19 --- /dev/null +++ b/bharat pathshala/frontend/src/components/Quiz.js @@ -0,0 +1,45 @@ +import React, { useState } from 'react'; +import axios from 'axios'; + +function Quiz() { + const [answers, setAnswers] = useState({}); + const [score, setScore] = useState(null); + const questions = [ + { id: 1, text: 'What is 2 + 2?', options: ['3', '4', '5'], correct: '4' }, + { id: 2, text: 'What is the capital of France?', options: ['Paris', 'London', 'Berlin'], correct: 'Paris' }, + ]; + + const handleSubmit = async () => { + const token = localStorage.getItem('token'); + const userScore = questions.reduce((acc, q) => acc + (answers[q.id] === q.correct ? 1 : 0), 0); + const total = questions.length; + setScore(`${userScore}/${total}`); + await axios.post('/quiz', { score: userScore / total * 100 }, { headers: { Authorization: `Bearer ${token}` } }); + }; + + return ( +
+

Interactive Quiz

+ {questions.map(q => ( +
+

{q.text}

+ {q.options.map(opt => ( + + ))} +
+ ))} + + {score &&

Your Score: {score}

} +
+ ); +} + +export default Quiz; \ No newline at end of file diff --git a/bharat pathshala/frontend/src/components/VideoPlayer.js b/bharat pathshala/frontend/src/components/VideoPlayer.js new file mode 100644 index 000000000..52ab71b51 --- /dev/null +++ b/bharat pathshala/frontend/src/components/VideoPlayer.js @@ -0,0 +1,65 @@ +import React, { useState } from 'react'; +import axios from 'axios'; +import p5 from 'p5'; + +function VideoPlayer() { + const [prompt, setPrompt] = useState(''); + const [explanation, setExplanation] = useState(''); + const [error, setError] = useState(''); + let sketchInstance; + + const sketch = (p) => { + p.setup = () => { + p.createCanvas(400, 400); + p.background(220); + }; + p.draw = () => { + p.fill(255, 0, 0); + p.ellipse(p.width / 2, p.height / 2, 50 + p.sin(p.frameCount * 0.05) * 20); + }; + }; + + useEffect(() => { + sketchInstance = new p5(sketch, document.getElementById('simulation')); + return () => sketchInstance.remove(); + }, []); + + const generateExplanation = async () => { + try { + const response = await axios.post('/generate-explanation', { prompt }); + setExplanation(response.data.explanation); + setError(''); + } catch (err) { + if (err.response?.status === 503) { + setError('Video generation unavailable (API key missing). Enjoy this simulation instead!'); + } else { + setError('Error generating explanation.'); + } + setExplanation(''); + } + }; + + return ( +
+

Concept Videos

+ setPrompt(e.target.value)} + placeholder="e.g., Explain projectile motion" + /> + + {explanation && ( +
+

Explanation

+

{explanation}

+
+ )} + {error &&

{error}

} +

Interactive Simulation

+
+
+ ); +} + +export default VideoPlayer; \ No newline at end of file diff --git a/bharat pathshala/frontend/src/pages/Home.js b/bharat pathshala/frontend/src/pages/Home.js new file mode 100644 index 000000000..75a6b326b --- /dev/null +++ b/bharat pathshala/frontend/src/pages/Home.js @@ -0,0 +1,12 @@ +import React from 'react'; + +function Home() { + return ( +
+

Welcome to EduWebsite

+

Learn with personalized paths, AI tutors, and interactive tools.

+
+ ); +} + +export default Home; \ No newline at end of file diff --git a/bharat pathshala/frontend/src/pages/Login.js b/bharat pathshala/frontend/src/pages/Login.js new file mode 100644 index 000000000..e69de29bb diff --git a/bharat pathshala/frontend/src/pages/Register.js b/bharat pathshala/frontend/src/pages/Register.js new file mode 100644 index 000000000..5d120f8d4 --- /dev/null +++ b/bharat pathshala/frontend/src/pages/Register.js @@ -0,0 +1,31 @@ +import React, { useState } from 'react'; +import axios from 'axios'; +import { useNavigate } from 'react-router-dom'; + +function Register() { + const [username, setUsername] = useState(''); + const [password, setPassword] = useState(''); + const [error, setError] = useState(''); + const navigate = useNavigate(); + + const handleRegister = async () => { + try { + await axios.post('/register', { username, password }); + navigate('/login'); + } catch (err) { + setError('Registration failed'); + } + }; + + return ( +
+

Register

+ setUsername(e.target.value)} placeholder="Username" /> + setPassword(e.target.value)} placeholder="Password" /> + + {error &&

{error}

} +
+ ); +} + +export default Register; \ No newline at end of file