ParthCodes commited on
Commit
07c0591
·
verified ·
1 Parent(s): b3d32cb

Upload 9 files

Browse files
app.py ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, jsonify, request
2
+ from flask_cors import CORS
3
+ from pymongo.mongo_client import MongoClient
4
+ from pymongo.server_api import ServerApi
5
+ import google.generativeai as genai
6
+ import urllib.parse
7
+ from models import UserSchema
8
+ from flask_bcrypt import Bcrypt
9
+ from flask_jwt_extended import JWTManager, create_access_token
10
+ from middleware.authUser import auth_user
11
+ from datetime import timedelta
12
+ from controllers.demo import get_initial_data
13
+
14
+ from dotenv import load_dotenv
15
+ import os
16
+
17
+ load_dotenv()
18
+
19
+ app = Flask(__name__)
20
+
21
+
22
+
23
+ bcrypt = Bcrypt(app)
24
+ jwt = JWTManager(app)
25
+
26
+ app.config['JWT_SECRET_KEY'] = os.getenv('JWT_SECRET')
27
+
28
+ # MongoDB configuration
29
+ username = urllib.parse.quote_plus(os.getenv('MONGO_USERNAME'))
30
+ password = urllib.parse.quote_plus(os.getenv('MONGO_PASSWORD'))
31
+ restUri = os.getenv('REST_URI')
32
+
33
+ uri = f'mongodb+srv://{username}:{password}@cluster0.iidzcbc.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0'
34
+
35
+ client = MongoClient(uri)
36
+ db = client.GenUpNexus
37
+ users_collection = db["users3"]
38
+
39
+ # Send a ping to confirm a successful connection
40
+ try:
41
+ client.admin.command('ping')
42
+ print("Pinged your deployment. You successfully connected to MongoDB!")
43
+ except Exception as e:
44
+ print(e)
45
+
46
+
47
+ GOOGLE_API_KEY=os.getenv('GOOGLE_API_KEY')
48
+
49
+ genai.configure(api_key=GOOGLE_API_KEY)
50
+ model = genai.GenerativeModel('gemini-pro')
51
+
52
+ @app.route('/')
53
+ def index():
54
+ return "Server is Running..."
55
+
56
+ @app.route('/tree', methods=["POST", "GET"])
57
+ def tree():
58
+ if request.method == 'POST':
59
+ data = request.get_json()
60
+ query = data.get('query')
61
+ print(query)
62
+ response = model.generate_content('''I will give you a topic and you have to generate an explanation of the topic and respond with JSON structure as follows as i want to use this json are Nodes & Edges and visualise this using ReactFlow library, the json structure will be :
63
+ nodes = [
64
+ {
65
+ id: "1",
66
+ type: "input",
67
+ data: {
68
+ label: "Input Node",
69
+ },
70
+ position: { x: 250, y: 0 },
71
+ },
72
+ {
73
+ id: "2",
74
+ data: {
75
+ label: "Default Node",
76
+ },
77
+ position: { x: 100, y: 100 },
78
+ },
79
+ {
80
+ id: "3",
81
+ type: "output",
82
+ data: {
83
+ label: "Output Node",
84
+ },
85
+ position: { x: 400, y: 100 },
86
+ },
87
+ {
88
+ id: "4",
89
+ type: "custom",
90
+ position: { x: 100, y: 200 },
91
+ data: {
92
+ selects: {
93
+ "handle-0": "smoothstep",
94
+ "handle-1": "smoothstep",
95
+ },
96
+ },
97
+ },
98
+ {
99
+ id: "5",
100
+ type: "output",
101
+ data: {
102
+ label: "custom style",
103
+ },
104
+ className: "circle",
105
+ style: {
106
+ background: "#2B6CB0",
107
+ color: "white",
108
+ },
109
+ position: { x: 400, y: 200 },
110
+ sourcePosition: Position.Right,
111
+ targetPosition: Position.Left,
112
+ },
113
+ {
114
+ id: "6",
115
+ type: "output",
116
+ style: {
117
+ background: "#63B3ED",
118
+ color: "white",
119
+ width: 100,
120
+ },
121
+ data: {
122
+ label: "Node",
123
+ },
124
+ position: { x: 400, y: 325 },
125
+ sourcePosition: Position.Right,
126
+ targetPosition: Position.Left,
127
+ },
128
+ {
129
+ id: "7",
130
+ type: "default",
131
+ className: "annotation",
132
+ data: {
133
+ label: (
134
+ <>
135
+ On the bottom left you see the <strong>Controls</strong> and the
136
+ bottom right the <strong>MiniMap</strong>. This is also just a node 🥳
137
+ </>
138
+ ),
139
+ },
140
+ draggable: false,
141
+ selectable: false,
142
+ position: { x: 150, y: 400 },
143
+ },
144
+ ];
145
+
146
+ edges = [
147
+ { id: "e1-2", source: "1", target: "2", label: "this is an edge label" },
148
+ { id: "e1-3", source: "1", target: "3", animated: true },
149
+ {
150
+ id: "e4-5",
151
+ source: "4",
152
+ target: "5",
153
+ type: "smoothstep",
154
+ sourceHandle: "handle-0",
155
+ data: {
156
+ selectIndex: 0,
157
+ },
158
+ markerEnd: {
159
+ type: MarkerType.ArrowClosed,
160
+ },
161
+ },
162
+ {
163
+ id: "e4-6",
164
+ source: "4",
165
+ target: "6",
166
+ type: "smoothstep",
167
+ sourceHandle: "handle-1",
168
+ data: {
169
+ selectIndex: 1,
170
+ },
171
+ markerEnd: {
172
+ type: MarkerType.ArrowClosed,
173
+ },
174
+ },
175
+ ];
176
+ Topic is: ''' + query)
177
+
178
+ # print(response.text)
179
+ return jsonify({'success': True, 'data': response.text})
180
+ # return temp
181
+
182
+ @app.route('/interview', methods=["POST", "GET"])
183
+ def interview():
184
+ if request.method == 'POST':
185
+ data = request.get_json()
186
+ if data.get('from') == 'client':
187
+ return "Success"
188
+ elif data.get('from') == 'gradio':
189
+ print(data)
190
+ return "Success"
191
+
192
+
193
+ # User Routes
194
+ @app.route('/user/signup', methods=['POST'])
195
+ def signup():
196
+ data = request.json
197
+ name = data.get('name')
198
+ email = data.get('email')
199
+ password = data.get('password')
200
+
201
+ if not email:
202
+ return jsonify({"error": "Invalid email"}), 400
203
+
204
+ existing_user = users_collection.find_one({"email": email})
205
+
206
+ if existing_user:
207
+ return jsonify({"message": "User already exists"}), 404
208
+
209
+ hashed_password = bcrypt.generate_password_hash(password).decode('utf-8')
210
+
211
+ result = users_collection.insert_one({
212
+ "name": name,
213
+ "email": email,
214
+ "password": hashed_password
215
+ })
216
+
217
+ print(result);
218
+
219
+ expires = timedelta(days=7)
220
+ access_token = create_access_token(identity={"email": email, "id": str(result.inserted_id)}, expires_delta=expires)
221
+
222
+ res = {"name": name, "email": email}
223
+
224
+ return jsonify({"result": res, "token": access_token}), 201
225
+
226
+ @app.route('/user/signin', methods=['POST'])
227
+ def signin():
228
+ data = request.json
229
+ email = data.get('email')
230
+ password = data.get('password')
231
+
232
+ user = users_collection.find_one({"email": email})
233
+
234
+ if not user:
235
+ return jsonify({"message": "User doesn't exist"}), 404
236
+
237
+ if not bcrypt.check_password_hash(user['password'], password):
238
+ return jsonify({"message": "Invalid Credentials"}), 404
239
+
240
+ expires = timedelta(days=7)
241
+ access_token = create_access_token(identity={"email": user['email'], "id": str(user['_id'])}, expires_delta=expires)
242
+
243
+ res = {"name": user['name'], "email": user['email']}
244
+
245
+ return jsonify({"result": res, "token": access_token}), 200
246
+
247
+ #protected route wiht auth_user middleware
248
+ @app.route('/user/delete', methods=['POST'])
249
+ @auth_user
250
+ def delete_account():
251
+ email = request.email
252
+ print(email)
253
+ try:
254
+ result = users_collection.delete_one({"email": email})
255
+ if result.deleted_count == 1:
256
+ return jsonify({"result": True}), 200
257
+ else:
258
+ return jsonify({"result": False, "message": "User not found"}), 404
259
+ except Exception as e:
260
+ print(e)
261
+ return jsonify({"message": "Something went wrong"}), 500
262
+
263
+ @app.route('/mindmap/demo', methods=['POST'])
264
+ def mindmapDemo():
265
+ data = request.json
266
+ print(data)
267
+ return get_initial_data(), 200
268
+
269
+
270
+
271
+
272
+ CORS(app)
273
+
274
+ if __name__ == '__main__':
275
+ app.run(debug=True)
body_language.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:868ca17ddf789c90a9b44709dce5ec67ad173ea31ba9835237f98ad5881c422c
3
+ size 255814
controllers/__pycache__/demo.cpython-311.pyc ADDED
Binary file (1.41 kB). View file
 
controllers/demo.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import jsonify
2
+
3
+ def get_initial_data():
4
+ initial_nodes = [
5
+ {
6
+ "id": "data-input",
7
+ "position": {"x": 0, "y": 0},
8
+ "data": {"label": "Data Input"}
9
+ },
10
+ {
11
+ "id": "data-preprocessing",
12
+ "position": {"x": 200, "y": 0},
13
+ "data": {"label": "Data Preprocessing"}
14
+ },
15
+ {
16
+ "id": "model-training",
17
+ "position": {"x": 400, "y": 0},
18
+ "data": {"label": "Model Training"}
19
+ },
20
+ {
21
+ "id": "model-evaluation",
22
+ "position": {"x": 0, "y": 200},
23
+ "data": {"label": "Model Evaluation"}
24
+ },
25
+ {
26
+ "id": "prediction",
27
+ "position": {"x": 200, "y": 200},
28
+ "data": {"label": "Prediction"}
29
+ },
30
+ {
31
+ "id": "data-visualization",
32
+ "position": {"x": 400, "y": 200},
33
+ "data": {"label": "Data Visualization"}
34
+ },
35
+ ]
36
+
37
+ initial_edges = [
38
+ {"id": "data-input-to-preprocessing", "source": "data-input", "target": "data-preprocessing"},
39
+ {"id": "preprocessing-to-training", "source": "data-preprocessing", "target": "model-training"},
40
+ {"id": "training-to-evaluation", "source": "model-training", "target": "model-evaluation"},
41
+ {"id": "training-to-prediction", "source": "model-training", "target": "prediction"},
42
+ {"id": "evaluation-to-visualization", "source": "model-evaluation", "target": "data-visualization"},
43
+ {"id": "prediction-to-visualization", "source": "prediction", "target": "data-visualization"}
44
+ ]
45
+
46
+ return jsonify({
47
+ "initialNodes": initial_nodes,
48
+ "initialEdges": initial_edges
49
+ })
controllers/user.py ADDED
File without changes
middleware/__pycache__/authUser.cpython-311.pyc ADDED
Binary file (2.11 kB). View file
 
middleware/authUser.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import request, jsonify
2
+ import jwt
3
+
4
+ from dotenv import load_dotenv
5
+ import os
6
+
7
+ load_dotenv()
8
+
9
+ def auth_user(next_function):
10
+ def middleware_function(*args, **kwargs):
11
+ try:
12
+ token = request.headers.get('Authorization', '').split(" ")[1]
13
+ is_custom_auth = len(token) < 500
14
+ decoded_data = None
15
+
16
+ if token and is_custom_auth:
17
+ secret_key = os.getenv('JWT_SECRET')
18
+ decoded_data = jwt.decode(token, secret_key, algorithms=["HS256"])
19
+ print(decoded_data)
20
+ dat = decoded_data.get('sub')
21
+ request.email = dat.get('email')
22
+ request.userId = dat.get('id')
23
+ else:
24
+ #google auth
25
+ decoded_data = jwt.decode(token)
26
+ request.email = decoded_data.get('email')
27
+ request.userId = decoded_data.get('sub')
28
+
29
+ return next_function(*args, **kwargs)
30
+
31
+ except Exception as e:
32
+ print(e) # Log the error if needed
33
+ return jsonify({"error": "Unauthorized"}), 401
34
+
35
+ return middleware_function
models.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from marshmallow import Schema, fields
2
+
3
+ class UserSchema(Schema):
4
+ name = fields.Str(required=True)
5
+ email = fields.Email(required=True)
6
+ password = fields.Str(required=True)
7
+ resume = fields.Str()
8
+ dp = fields.Str()
9
+
10
+ class DashboardSchema(Schema):
11
+ uniq_path_id = fields.Str(required=True)
12
+ name = fields.Str(required=True)
13
+ current_role = fields.Str()
14
+ desired_company = fields.Str()
15
+ learning_path_progress = fields.Dict()
16
+ recent_mindmaps = fields.Dict()
17
+ recent_interviews = fields.Dict()
18
+
19
+ class LearningPathSchema(Schema):
20
+ uniq_path_id = fields.Str(required=True)
21
+ data = fields.Dict()
22
+ total_path_tuples = fields.Int()
23
+ current_progress_tuples = fields.Int()
24
+
25
+ class MindmapSchema(Schema):
26
+ uniq_map_id = fields.Str(required=True)
27
+ data = fields.Dict()
28
+
29
+ class InterviewSchema(Schema):
30
+ uniq_interview_id = fields.Str(required=True)
31
+ data = fields.Dict()
32
+
33
+
requirements.txt ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ gradio==4.22.0
2
+ opencv-python==4.9.0.80
3
+ transformers==4.38.2
4
+ pydub==0.25.1
5
+ faster_whisper==1.0.1
6
+ joblib==1.3.2
7
+ mediapipe==0.10.11
8
+ numpy==1.26.4
9
+ pandas==2.2.1
10
+ moviepy==1.0.3
11
+ flask==3.0.2
12
+ Werkzeug==3.0.1
13
+ Flask-Cors==4.0.0
14
+ google-generativeai==0.4.1
15
+ python-dotenv==1.0.1
16
+ pymongo[srv]
17
+ marshmallow
18
+ flask_bcrypt
19
+ flask_jwt_extended