vijay7788 commited on
Commit
827cd15
·
verified ·
1 Parent(s): b82c71b

i want in html css js and backend python with fully workiung ai models..fro an chatbot that acts as an menotr to leean ai and ml..gimme all the css and js inlined

Browse files
Files changed (4) hide show
  1. README.md +7 -4
  2. app.py +136 -0
  3. index.html +214 -19
  4. requirements.txt +8 -0
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Ai Mentor Bot Your Fuchsia Guide To Ml Mastery
3
- emoji: 😻
4
- colorFrom: green
5
  colorTo: yellow
 
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: AI Mentor Bot - Your Fuchsia Guide to ML Mastery 🧠
3
+ colorFrom: red
 
4
  colorTo: yellow
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://huggingface.co/deepsite).
app.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ python
2
+ from flask import Flask, request, jsonify
3
+ from flask_cors import CORS
4
+ import numpy as np
5
+ from transformers import pipeline
6
+
7
+ app = Flask(__name__)
8
+ CORS(app)
9
+
10
+ # Load AI models
11
+ qa_pipeline = pipeline(
12
+ "question-answering",
13
+ model="distilbert-base-cased-distilled-squad",
14
+ tokenizer="distilbert-base-cased"
15
+ )
16
+
17
+ text_gen_pipeline = pipeline(
18
+ "text-generation",
19
+ model="gpt2",
20
+ tokenizer="gpt2"
21
+ )
22
+
23
+ @app.route('/api/chat', methods=['POST'])
24
+ def chat():
25
+ data = request.json
26
+ user_message = data.get('message', '').lower()
27
+
28
+ # AI/ML specific responses
29
+ ml_keywords = {
30
+ 'backpropagation': explain_backpropagation,
31
+ 'python': python_ml_example,
32
+ 'gan': explain_gan,
33
+ 'neural network': explain_neural_network,
34
+ 'regression': explain_regression,
35
+ 'classification': explain_classification
36
+ }
37
+
38
+ # Check for specific ML topics
39
+ response = None
40
+ for keyword, handler in ml_keywords.items():
41
+ if keyword in user_message:
42
+ response = handler()
43
+ break
44
+
45
+ if not response:
46
+ # Use QA model for general questions
47
+ context = """
48
+ Machine learning is a field of artificial intelligence that uses statistical techniques
49
+ to give computer systems the ability to "learn" from data. There are three main types:
50
+ supervised learning (labeled data), unsupervised learning (unlabeled data), and
51
+ reinforcement learning (reward-based). Popular algorithms include linear regression,
52
+ decision trees, neural networks, and support vector machines.
53
+ """
54
+ qa_result = qa_pipeline(question=user_message, context=context)
55
+
56
+ if qa_result['score'] > 0.3:
57
+ response = qa_result['answer']
58
+ else:
59
+ # Fallback to text generation
60
+ prompt = f"Q: {user_message}\nA:"
61
+ gen_result = text_gen_pipeline(
62
+ prompt,
63
+ max_length=100,
64
+ num_return_sequences=1,
65
+ temperature=0.7
66
+ )
67
+ response = gen_result[0]['generated_text'].replace(prompt, '').strip()
68
+
69
+ return jsonify({'response': response})
70
+
71
+ def explain_backpropagation():
72
+ return """Backpropagation is the algorithm used to train neural networks. It involves:
73
+ 1. Forward pass: Compute predictions
74
+ 2. Calculate loss between predictions and true values
75
+ 3. Backward pass: Compute gradients of loss w.r.t. all parameters
76
+ 4. Update weights using gradient descent
77
+
78
+ The "back" in backpropagation refers to how gradients flow backward through the network from output to input layers."""
79
+
80
+ def python_ml_example():
81
+ return """Here's a simple machine learning example using scikit-learn:
82
+
83
+ python
84
+ from sklearn.datasets import load_iris
85
+ from sklearn.model_selection import train_test_split
86
+ from sklearn.ensemble import RandomForestClassifier
87
+
88
+ # Load dataset
89
+ iris = load_iris()
90
+ X, y = iris.data, iris.target
91
+
92
+ # Split data
93
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
94
+
95
+ # Create and train model
96
+ model = RandomForestClassifier(n_estimators=100)
97
+ model.fit(X_train, y_train)
98
+
99
+ # Evaluate
100
+ accuracy = model.score(X_test, y_test)
101
+ print(f"Model accuracy: {accuracy:.2f}")
102
+ """
103
+
104
+ def explain_gan():
105
+ return """GAN stands for Generative Adversarial Network. It consists of two neural networks:
106
+ 1. Generator: Creates fake data samples
107
+ 2. Discriminator: Tries to distinguish real from fake samples
108
+
109
+ They compete in a game where the generator improves its outputs to fool the discriminator, while the discriminator gets better at detection. This adversarial process leads to highly realistic generated data."""
110
+
111
+ def explain_neural_network():
112
+ return """A neural network is a series of algorithms that attempts to recognize underlying relationships in data through a process that mimics how the human brain operates. Key components:
113
+ - Input layer: Receives the data
114
+ - Hidden layers: Perform computations (with weights and biases)
115
+ - Output layer: Produces the final prediction
116
+ - Activation functions: Introduce non-linearity (ReLU, sigmoid, tanh)"""
117
+
118
+ def explain_regression():
119
+ return """Regression is a supervised learning technique for predicting continuous values. Common types:
120
+ 1. Linear Regression: Models linear relationships
121
+ 2. Polynomial Regression: Fits polynomial functions
122
+ 3. Ridge/Lasso Regression: Regularized linear models
123
+ 4. Logistic Regression: Despite the name, used for classification"""
124
+
125
+ def explain_classification():
126
+ return """Classification is a supervised learning technique for predicting discrete class labels. Popular algorithms:
127
+ 1. Decision Trees
128
+ 2. Random Forest
129
+ 3. Support Vector Machines (SVM)
130
+ 4. Neural Networks
131
+ 5. k-Nearest Neighbors (k-NN)"""
132
+
133
+ if __name__ == '__main__':
134
+ app.run(host='0.0.0.0', port=5000)
135
+
136
+ </html>
index.html CHANGED
@@ -1,19 +1,214 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en" class="dark">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>AI Mentor Bot</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
9
+ <script src="https://unpkg.com/feather-icons"></script>
10
+ <script>
11
+ tailwind.config = {
12
+ darkMode: 'class',
13
+ theme: {
14
+ extend: {
15
+ colors: {
16
+ primary: {
17
+ 500: '#d946ef',
18
+ },
19
+ secondary: {
20
+ 500: '#eab308',
21
+ }
22
+ }
23
+ }
24
+ }
25
+ }
26
+ </script>
27
+ <style>
28
+ .chat-container {
29
+ height: calc(100vh - 180px);
30
+ }
31
+ .typing-indicator::after {
32
+ content: '...';
33
+ animation: typing 1.5s infinite;
34
+ }
35
+ @keyframes typing {
36
+ 0% { content: '.'; }
37
+ 33% { content: '..'; }
38
+ 66% { content: '...'; }
39
+ }
40
+ .gradient-bg {
41
+ background: linear-gradient(135deg, rgba(217, 70, 239, 0.2) 0%, rgba(234, 179, 8, 0.2) 100%);
42
+ }
43
+ </style>
44
+ </head>
45
+ <body class="bg-gray-900 text-gray-100">
46
+ <div class="flex flex-col h-screen">
47
+ <!-- Header -->
48
+ <header class="bg-gray-800 p-4 shadow-lg">
49
+ <div class="container mx-auto flex items-center justify-between">
50
+ <div class="flex items-center space-x-3">
51
+ <i data-feather="cpu" class="text-primary-500 w-8 h-8"></i>
52
+ <h1 class="text-2xl font-bold bg-gradient-to-r from-primary-500 to-secondary-500 bg-clip-text text-transparent">
53
+ AI Mentor Bot
54
+ </h1>
55
+ </div>
56
+ <div class="flex items-center space-x-4">
57
+ <button id="themeToggle" class="p-2 rounded-full bg-gray-700 hover:bg-gray-600 transition">
58
+ <i data-feather="moon" class="w-5 h-5"></i>
59
+ </button>
60
+ <button class="p-2 rounded-full bg-gray-700 hover:bg-gray-600 transition">
61
+ <i data-feather="settings" class="w-5 h-5"></i>
62
+ </button>
63
+ </div>
64
+ </div>
65
+ </header>
66
+
67
+ <!-- Main Content -->
68
+ <main class="flex-1 container mx-auto p-4 overflow-hidden">
69
+ <div class="gradient-bg rounded-xl p-6 shadow-lg mb-6">
70
+ <div class="flex items-center space-x-3">
71
+ <div class="bg-primary-500 p-3 rounded-full">
72
+ <i data-feather="zap" class="w-6 h-6 text-white"></i>
73
+ </div>
74
+ <div>
75
+ <h2 class="text-xl font-bold">Welcome to AI Mentor!</h2>
76
+ <p class="text-gray-300">Ask me anything about Machine Learning, AI concepts, or coding help.</p>
77
+ </div>
78
+ </div>
79
+ </div>
80
+
81
+ <!-- Chat Container -->
82
+ <div class="chat-container overflow-y-auto mb-4 bg-gray-800 rounded-xl p-4 shadow-inner">
83
+ <div id="chatMessages" class="space-y-4">
84
+ <!-- Messages will appear here -->
85
+ <div class="chat-message bot-message">
86
+ <div class="flex items-start space-x-3">
87
+ <div class="bg-secondary-500 p-2 rounded-full">
88
+ <i data-feather="cpu" class="w-5 h-5 text-gray-900"></i>
89
+ </div>
90
+ <div class="bg-gray-700 rounded-lg p-3 max-w-3xl">
91
+ <p>Hello! I'm your AI Mentor. I can help you learn Machine Learning concepts, debug your code, explain algorithms, and guide you through AI projects. What would you like to learn today?</p>
92
+ </div>
93
+ </div>
94
+ </div>
95
+ </div>
96
+ </div>
97
+
98
+ <!-- Input Area -->
99
+ <div class="bg-gray-800 rounded-xl p-4 shadow-lg">
100
+ <div class="flex space-x-2">
101
+ <input
102
+ id="userInput"
103
+ type="text"
104
+ placeholder="Ask about neural networks, Python code, or ML concepts..."
105
+ class="flex-1 bg-gray-700 border border-gray-600 rounded-lg px-4 py-3 focus:outline-none focus:ring-2 focus:ring-primary-500"
106
+ >
107
+ <button
108
+ id="sendButton"
109
+ class="bg-primary-500 hover:bg-primary-600 text-white px-6 py-3 rounded-lg font-medium transition flex items-center"
110
+ >
111
+ <i data-feather="send" class="w-5 h-5 mr-2"></i>
112
+ Send
113
+ </button>
114
+ </div>
115
+ <div class="mt-2 flex space-x-2">
116
+ <button class="quick-prompt bg-gray-700 hover:bg-gray-600 px-3 py-1 rounded text-sm transition">
117
+ Explain backpropagation
118
+ </button>
119
+ <button class="quick-prompt bg-gray-700 hover:bg-gray-600 px-3 py-1 rounded text-sm transition">
120
+ Show Python ML example
121
+ </button>
122
+ <button class="quick-prompt bg-gray-700 hover:bg-gray-600 px-3 py-1 rounded text-sm transition">
123
+ What's a GAN?
124
+ </button>
125
+ </div>
126
+ </div>
127
+ </main>
128
+
129
+ <!-- Footer -->
130
+ <footer class="bg-gray-800 p-3 text-center text-gray-400 text-sm">
131
+ <p>AI Mentor Bot © 2023 - Your guide to Machine Learning mastery</p>
132
+ </footer>
133
+ </div>
134
+
135
+ <script>
136
+ // Theme Toggle
137
+ const themeToggle = document.getElementById('themeToggle');
138
+ themeToggle.addEventListener('click', () => {
139
+ document.documentElement.classList.toggle('dark');
140
+ const icon = themeToggle.querySelector('i');
141
+ if (document.documentElement.classList.contains('dark')) {
142
+ feather.icons['moon'].toSvg().then(svg => icon.outerHTML = svg);
143
+ } else {
144
+ feather.icons['sun'].toSvg().then(svg => icon.outerHTML = svg);
145
+ }
146
+ });
147
+
148
+ // Chat functionality
149
+ const chatMessages = document.getElementById('chatMessages');
150
+ const userInput = document.getElementById('userInput');
151
+ const sendButton = document.getElementById('sendButton');
152
+ const quickPrompts = document.querySelectorAll('.quick-prompt');
153
+
154
+ function addUserMessage(message) {
155
+ const messageDiv = document.createElement('div');
156
+ messageDiv.className = 'chat-message user-message';
157
+ messageDiv.innerHTML = `
158
+ <div class="flex items-start space-x-3 justify-end">
159
+ <div class="bg-gray-700 rounded-lg p-3 max-w-3xl">
160
+ <p>${message}</p>
161
+ </div>
162
+ <div class="bg-primary-500 p-2 rounded-full">
163
+ <i data-feather="user" class="w-5 h-5 text-white"></i>
164
+ </div>
165
+ </div>
166
+ `;
167
+ chatMessages.appendChild(messageDiv);
168
+ scrollToBottom();
169
+ }
170
+
171
+ function addBotMessage(message, isTyping = false) {
172
+ const messageDiv = document.createElement('div');
173
+ messageDiv.className = 'chat-message bot-message';
174
+
175
+ let messageContent = isTyping
176
+ ? '<span class="typing-indicator"></span>'
177
+ : `<p>${message}</p>`;
178
+
179
+ messageDiv.innerHTML = `
180
+ <div class="flex items-start space-x-3">
181
+ <div class="bg-secondary-500 p-2 rounded-full">
182
+ <i data-feather="cpu" class="w-5 h-5 text-gray-900"></i>
183
+ </div>
184
+ <div class="bg-gray-700 rounded-lg p-3 max-w-3xl">
185
+ ${messageContent}
186
+ </div>
187
+ </div>
188
+ `;
189
+ chatMessages.appendChild(messageDiv);
190
+ scrollToBottom();
191
+
192
+ if (isTyping) {
193
+ return messageDiv;
194
+ }
195
+ return null;
196
+ }
197
+
198
+ function scrollToBottom() {
199
+ chatMessages.scrollTop = chatMessages.scrollHeight;
200
+ }
201
+
202
+ // Simulate API call to Python backend
203
+ async function getBotResponse(userMessage) {
204
+ // In a real app, this would call your Python backend API
205
+ // For demo purposes, we'll simulate responses
206
+
207
+ const responses = {
208
+ "hello": "Hello! How can I assist you with your AI/ML learning today?",
209
+ "hi": "Hi there! What AI concept would you like to explore?",
210
+ "explain backpropagation": "Backpropagation is the algorithm used to train neural networks. It works by:\n1. Forward pass: Compute predictions\n2. Calculate loss\n3. Backward pass: Compute gradients\n4. Update weights using gradient descent\n\nIt's called 'back' propagation because gradients flow backward through the network from output to input layers.",
211
+ "show python ml example": "Here's a simple linear regression example using scikit-learn:\n
212
+ <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
213
+ </body>
214
+ </html>
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+
2
+ flask==2.3.2
3
+ flask-cors==3.0.10
4
+ numpy==1.24.3
5
+ transformers==4.30.2
6
+ torch==2.0.1
7
+
8
+ </html>