ishans24 commited on
Commit
8a3eb0b
1 Parent(s): 619c4ea

Upload 3 files

Browse files
Files changed (3) hide show
  1. main.py +118 -0
  2. reviews.json +689 -0
  3. util.py +51 -0
main.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ from fastapi import FastAPI, UploadFile, File, HTTPException, Form
4
+ from fastapi.middleware.cors import CORSMiddleware
5
+ from pydantic import BaseModel
6
+ import requests
7
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
8
+ from langchain_community.vectorstores.faiss import FAISS
9
+ from langchain.chains.question_answering import load_qa_chain
10
+ from langchain.prompts import PromptTemplate
11
+ from langchain_google_genai import GoogleGenerativeAIEmbeddings, ChatGoogleGenerativeAI
12
+ import google.generativeai as genai
13
+ from dotenv import load_dotenv
14
+
15
+ app = FastAPI()
16
+
17
+ # Configure CORS
18
+ app.add_middleware(
19
+ CORSMiddleware,
20
+ allow_origins=["*"],
21
+ allow_credentials=True,
22
+ allow_methods=["*"],
23
+ allow_headers=["*"],
24
+ )
25
+
26
+ # Load environment variables
27
+ load_dotenv()
28
+
29
+ # Configure Google API
30
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
31
+
32
+ class QuestionInput(BaseModel):
33
+ question: str
34
+
35
+ class UploadInput(BaseModel):
36
+ url: str = Form(None)
37
+
38
+ def scrape_data(url):
39
+
40
+ return "scraped data"
41
+
42
+ def split_text_into_chunks(text):
43
+ splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
44
+ text_chunks = splitter.split_text(text)
45
+ return text_chunks
46
+
47
+ def create_vector_store(chunks):
48
+ embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
49
+ vector_store = FAISS.from_texts(chunks, embedding=embeddings)
50
+ vector_store.save_local("faiss_index")
51
+
52
+ def setup_conversation_chain(template):
53
+ model = ChatGoogleGenerativeAI(model="gemini-pro", temperature=0.3)
54
+ prompt = PromptTemplate(template=template, input_variables=["context", "question"])
55
+ chain = load_qa_chain(model, chain_type="stuff", prompt=prompt)
56
+ return chain
57
+
58
+ @app.post("/upload")
59
+ async def upload_files(url: str = Form(None)):
60
+ try:
61
+ # print(url)
62
+ # all_text = ""
63
+
64
+ # # Process URL
65
+ # if url:
66
+ # # check if url is valid (request doesnt give error)
67
+ # if # doesnt give error
68
+ # all_text = scrape_data(url)
69
+ # else:
70
+ # raise HTTPException(status_code=400, detail="Invalid URL")
71
+
72
+ # if not all_text:
73
+ # raise HTTPException(status_code=400, detail="No content to process")
74
+
75
+ # chunks = split_text_into_chunks(all_text)
76
+ # create_vector_store(chunks)
77
+
78
+ return {"message": "Content uploaded and processed successfully"}
79
+ except HTTPException as http_exc:
80
+ print(f"HTTP Exception: {http_exc.detail}")
81
+ raise http_exc
82
+ except Exception as e:
83
+ print(f"Unhandled Exception: {e}")
84
+ raise HTTPException(status_code=500, detail=str(e))
85
+
86
+
87
+ @app.post("/ask")
88
+ async def ask_question(question_input: QuestionInput):
89
+ try:
90
+ embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
91
+ indexed_data = FAISS.load_local("reviews_index", embeddings, allow_dangerous_deserialization=True)
92
+ docs = indexed_data.similarity_search(question_input.question)
93
+
94
+ prompt_template = """
95
+ Your alias is AI Rate Professor. Your task is to provide a thorough response based on the given context, ensuring all relevant details are included.
96
+ If the requested information isn't available, simply state, "answer not available in context," then answer based on your understanding, connecting with the context.
97
+ Don't provide incorrect information.\n\n
98
+ Context: \n {context}?\n
99
+ Question: \n {question}\n
100
+ Answer:
101
+ """
102
+
103
+ chain = setup_conversation_chain(prompt_template)
104
+ response = chain({"input_documents": docs, "question": question_input.question}, return_only_outputs=True)
105
+
106
+ print(response["output_text"])
107
+ return {"answer": response["output_text"]}
108
+ except Exception as e:
109
+ raise HTTPException(status_code=500, detail=str(e))
110
+
111
+ # prompt_template = """
112
+ # Your alias is AI Rate Professor. Your task is to provide a thorough response based on the given context, ensuring all relevant details are included.
113
+ # If the requested information isn't available, simply state, "answer not available in context," then answer based on your understanding, connecting with the context.
114
+ # Don't provide incorrect information.\n\n
115
+ # Context: \n {context}?\n
116
+ # Question: \n {question}\n
117
+ # Answer:
118
+ # """
reviews.json ADDED
@@ -0,0 +1,689 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "professors": [
3
+ {
4
+ "professor_id": "A1B2C3",
5
+ "name": "Dr. A. Kumar",
6
+ "course": "Data Structures",
7
+ "reviews": [
8
+ {
9
+ "rating": 4.5,
10
+ "review_text": "Dr. Kumar explains data structures with great clarity and provides excellent examples."
11
+ },
12
+ {
13
+ "rating": 3.7,
14
+ "review_text": "The course content was good, but the pace was a bit fast for beginners."
15
+ },
16
+ {
17
+ "rating": 4.8,
18
+ "review_text": "One of the best professors I've had. Very knowledgeable and approachable."
19
+ }
20
+ ]
21
+ },
22
+ {
23
+ "professor_id": "D4E5F6",
24
+ "name": "Dr. S. Reddy",
25
+ "course": "Algorithms",
26
+ "reviews": [
27
+ {
28
+ "rating": 4.2,
29
+ "review_text": "Dr. Reddy's lectures are well-organized and engaging. The assignments are challenging but fair."
30
+ },
31
+ {
32
+ "rating": 3.9,
33
+ "review_text": "The concepts were well taught, but the grading seemed a bit harsh."
34
+ },
35
+ {
36
+ "rating": 4.7,
37
+ "review_text": "Fantastic teacher with a deep understanding of algorithms. Highly recommended."
38
+ }
39
+ ]
40
+ },
41
+ {
42
+ "professor_id": "G7H8I9",
43
+ "name": "Dr. P. Sharma",
44
+ "course": "Operating Systems",
45
+ "reviews": [
46
+ {
47
+ "rating": 4.0,
48
+ "review_text": "Good course, though the material was sometimes a bit dry."
49
+ },
50
+ {
51
+ "rating": 4.3,
52
+ "review_text": "Dr. Sharma is very knowledgeable and provides clear explanations."
53
+ },
54
+ {
55
+ "rating": 4.1,
56
+ "review_text": "The course was informative, but more interactive sessions would be beneficial."
57
+ }
58
+ ]
59
+ },
60
+ {
61
+ "professor_id": "J1K2L3",
62
+ "name": "Dr. L. Patel",
63
+ "course": "Database Systems",
64
+ "reviews": [
65
+ {
66
+ "rating": 4.5,
67
+ "review_text": "Excellent course with practical insights into database management."
68
+ },
69
+ {
70
+ "rating": 4.0,
71
+ "review_text": "Dr. Patel has a solid understanding of database systems but could improve on feedback timeliness."
72
+ },
73
+ {
74
+ "rating": 4.6,
75
+ "review_text": "Very engaging and knowledgeable. The practical sessions were very useful."
76
+ }
77
+ ]
78
+ },
79
+ {
80
+ "professor_id": "M4N5O6",
81
+ "name": "Dr. V. Singh",
82
+ "course": "Computer Networks",
83
+ "reviews": [
84
+ {
85
+ "rating": 4.4,
86
+ "review_text": "Dr. Singh provides a comprehensive overview of networking concepts and practical applications."
87
+ },
88
+ {
89
+ "rating": 3.8,
90
+ "review_text": "The course is good, but sometimes the theoretical parts are too lengthy."
91
+ },
92
+ {
93
+ "rating": 4.7,
94
+ "review_text": "Highly knowledgeable with great real-world examples and case studies."
95
+ }
96
+ ]
97
+ },
98
+ {
99
+ "professor_id": "P7Q8R9",
100
+ "name": "Dr. A. Mehta",
101
+ "course": "Software Engineering",
102
+ "reviews": [
103
+ {
104
+ "rating": 4.3,
105
+ "review_text": "Dr. Mehta covers software engineering principles effectively, with a focus on real-life applications."
106
+ },
107
+ {
108
+ "rating": 4.0,
109
+ "review_text": "Good insights into software project management, though sometimes the lectures are a bit dry."
110
+ },
111
+ {
112
+ "rating": 4.5,
113
+ "review_text": "Engaging lectures and useful project work that helps understand the concepts better."
114
+ }
115
+ ]
116
+ },
117
+ {
118
+ "professor_id": "S1T2U3",
119
+ "name": "Dr. R. Joshi",
120
+ "course": "Artificial Intelligence",
121
+ "reviews": [
122
+ {
123
+ "rating": 4.6,
124
+ "review_text": "Dr. Joshi is an expert in AI and makes complex topics easier to understand with practical examples."
125
+ },
126
+ {
127
+ "rating": 4.1,
128
+ "review_text": "The course is quite advanced, but Dr. Joshi’s explanations help in grasping difficult concepts."
129
+ },
130
+ {
131
+ "rating": 4.7,
132
+ "review_text": "Excellent course content with a lot of interactive sessions and real-world AI applications."
133
+ }
134
+ ]
135
+ },
136
+ {
137
+ "professor_id": "V4W5X6",
138
+ "name": "Dr. N. Kapoor",
139
+ "course": "Machine Learning",
140
+ "reviews": [
141
+ {
142
+ "rating": 4.5,
143
+ "review_text": "Dr. Kapoor provides a solid foundation in machine learning with well-structured coursework."
144
+ },
145
+ {
146
+ "rating": 4.2,
147
+ "review_text": "Good course but sometimes the pace of covering topics is too quick."
148
+ },
149
+ {
150
+ "rating": 4.8,
151
+ "review_text": "Highly engaging and informative, with a lot of practical exercises and real-world datasets."
152
+ }
153
+ ]
154
+ },
155
+ {
156
+ "professor_id": "Y7Z8A9",
157
+ "name": "Dr. G. Rao",
158
+ "course": "Web Development",
159
+ "reviews": [
160
+ {
161
+ "rating": 4.3,
162
+ "review_text": "Dr. Rao’s course is well-organized with practical projects that enhance learning."
163
+ },
164
+ {
165
+ "rating": 4.0,
166
+ "review_text": "The course covers the essentials, but more advanced topics could be included."
167
+ },
168
+ {
169
+ "rating": 4.6,
170
+ "review_text": "Excellent for beginners and intermediate learners, with a lot of hands-on exercises."
171
+ }
172
+ ]
173
+ },
174
+ {
175
+ "professor_id": "B1C2D3",
176
+ "name": "Dr. H. Sinha",
177
+ "course": "Human-Computer Interaction",
178
+ "reviews": [
179
+ {
180
+ "rating": 4.4,
181
+ "review_text": "Dr. Sinha’s course is insightful with a focus on user experience and interaction design."
182
+ },
183
+ {
184
+ "rating": 4.1,
185
+ "review_text": "Interesting content but sometimes the theoretical aspects can be quite dense."
186
+ },
187
+ {
188
+ "rating": 4.5,
189
+ "review_text": "Great course with a lot of practical examples and user-centered design principles."
190
+ }
191
+ ]
192
+ },
193
+ {
194
+ "professor_id": "E4F5G6",
195
+ "name": "Dr. J. Verma",
196
+ "course": "Cybersecurity",
197
+ "reviews": [
198
+ {
199
+ "rating": 4.6,
200
+ "review_text": "Dr. Verma is highly knowledgeable and provides deep insights into cybersecurity threats and solutions."
201
+ },
202
+ {
203
+ "rating": 4.2,
204
+ "review_text": "The content is relevant, though some practical exercises could be more hands-on."
205
+ },
206
+ {
207
+ "rating": 4.8,
208
+ "review_text": "Excellent understanding of cybersecurity issues with practical case studies."
209
+ }
210
+ ]
211
+ },
212
+ {
213
+ "professor_id": "H7I8J9",
214
+ "name": "Dr. M. Bhat",
215
+ "course": "Embedded Systems",
216
+ "reviews": [
217
+ {
218
+ "rating": 4.3,
219
+ "review_text": "Dr. Bhat's course is very informative with detailed explanations of embedded systems."
220
+ },
221
+ {
222
+ "rating": 4.0,
223
+ "review_text": "The course is good, but more real-world examples would make it even better."
224
+ },
225
+ {
226
+ "rating": 4.5,
227
+ "review_text": "Engaging lectures with a lot of practical applications and projects."
228
+ }
229
+ ]
230
+ },
231
+ {
232
+ "professor_id": "K1L2M3",
233
+ "name": "Dr. A. Gupta",
234
+ "course": "Cloud Computing",
235
+ "reviews": [
236
+ {
237
+ "rating": 4.6,
238
+ "review_text": "Dr. Gupta offers a thorough understanding of cloud computing with practical cloud services."
239
+ },
240
+ {
241
+ "rating": 4.2,
242
+ "review_text": "The course is well-structured but could benefit from more interactive sessions."
243
+ },
244
+ {
245
+ "rating": 4.7,
246
+ "review_text": "Fantastic insights into cloud technologies and hands-on experience with cloud platforms."
247
+ }
248
+ ]
249
+ },
250
+ {
251
+ "professor_id": "N4O5P6",
252
+ "name": "Dr. R. Jain",
253
+ "course": "Computer Graphics",
254
+ "reviews": [
255
+ {
256
+ "rating": 4.4,
257
+ "review_text": "Dr. Jain’s course provides a strong foundation in computer graphics with great practical exercises."
258
+ },
259
+ {
260
+ "rating": 4.1,
261
+ "review_text": "Interesting content, though the course could be more engaging with interactive elements."
262
+ },
263
+ {
264
+ "rating": 4.6,
265
+ "review_text": "Highly recommended for anyone interested in graphics programming. The practical work was excellent."
266
+ }
267
+ ]
268
+ },
269
+ {
270
+ "professor_id": "Q7R8S9",
271
+ "name": "Dr. P. Singh",
272
+ "course": "Computer Vision",
273
+ "reviews": [
274
+ {
275
+ "rating": 4.5,
276
+ "review_text": "Dr. Singh is an expert in computer vision, and the course material is very relevant and up-to-date."
277
+ },
278
+ {
279
+ "rating": 4.3,
280
+ "review_text": "Great course, though it could use more hands-on projects to complement the theory."
281
+ },
282
+ {
283
+ "rating": 4.7,
284
+ "review_text": "Excellent course with a lot of practical applications and real-world examples."
285
+ }
286
+ ]
287
+ },
288
+ {
289
+ "professor_id": "R1S2T3",
290
+ "name": "Dr. T. Kumar",
291
+ "course": "Distributed Systems",
292
+ "reviews": [
293
+ {
294
+ "rating": 4.3,
295
+ "review_text": "Dr. Kumar provides a thorough understanding of distributed systems with practical insights."
296
+ },
297
+ {
298
+ "rating": 4.0,
299
+ "review_text": "The course is good but could benefit from more interactive discussions and exercises."
300
+ },
301
+ {
302
+ "rating": 4.5,
303
+ "review_text": "Highly knowledgeable with a lot of practical examples and case studies."
304
+ }
305
+ ]
306
+ },
307
+ {
308
+ "professor_id": "U4V5W6",
309
+ "name": "Dr. V. Iyer",
310
+ "course": "Compiler Design",
311
+ "reviews": [
312
+ {
313
+ "rating": 4.4,
314
+ "review_text": "Dr. Iyer's course is detailed and comprehensive, covering all aspects of compiler design."
315
+ },
316
+ {
317
+ "rating": 4.1,
318
+ "review_text": "Theoretical content is well-taught but practical exercises could be improved."
319
+ },
320
+ {
321
+ "rating": 4.6,
322
+ "review_text": "Excellent teaching with a strong focus on practical compiler construction techniques."
323
+ }
324
+ ]
325
+ },
326
+ {
327
+ "professor_id": "X7Y8Z9",
328
+ "name": "Dr. W. Rao",
329
+ "course": "Natural Language Processing",
330
+ "reviews": [
331
+ {
332
+ "rating": 4.5,
333
+ "review_text": "Dr. Rao's expertise in NLP is evident, and the course material is very relevant."
334
+ },
335
+ {
336
+ "rating": 4.2,
337
+ "review_text": "Great course with a lot of practical exercises, though the pace is a bit fast."
338
+ },
339
+ {
340
+ "rating": 4.7,
341
+ "review_text": "Highly engaging with a lot of real-world NLP applications and examples."
342
+ }
343
+ ]
344
+ },
345
+ {
346
+ "professor_id": "Y1Z2A3",
347
+ "name": "Dr. Z. Patel",
348
+ "course": "Quantum Computing",
349
+ "reviews": [
350
+ {
351
+ "rating": 4.6,
352
+ "review_text": "Dr. Patel provides an excellent overview of quantum computing with practical insights."
353
+ },
354
+ {
355
+ "rating": 4.1,
356
+ "review_text": "The course is very advanced but Dr. Patel’s explanations make it more accessible."
357
+ },
358
+ {
359
+ "rating": 4.8,
360
+ "review_text": "Highly recommended for those interested in quantum computing. Great balance of theory and practice."
361
+ }
362
+ ]
363
+ },
364
+ {
365
+ "professor_id": "Z4A5B6",
366
+ "name": "Dr. C. Singh",
367
+ "course": "Information Retrieval",
368
+ "reviews": [
369
+ {
370
+ "rating": 4.4,
371
+ "review_text": "Dr. Singh’s course on information retrieval is well-structured and informative."
372
+ },
373
+ {
374
+ "rating": 4.0,
375
+ "review_text": "Good course content but could use more real-world examples and practical sessions."
376
+ },
377
+ {
378
+ "rating": 4.6,
379
+ "review_text": "Excellent teaching with a lot of practical exercises that enhance understanding."
380
+ }
381
+ ]
382
+ },
383
+ {
384
+ "professor_id": "A7B8C9",
385
+ "name": "Dr. D. Sharma",
386
+ "course": "Digital Logic Design",
387
+ "reviews": [
388
+ {
389
+ "rating": 4.3,
390
+ "review_text": "Dr. Sharma provides a solid foundation in digital logic design with clear explanations."
391
+ },
392
+ {
393
+ "rating": 4.0,
394
+ "review_text": "Theoretical parts are well-covered but practical aspects could be more interactive."
395
+ },
396
+ {
397
+ "rating": 4.5,
398
+ "review_text": "Very knowledgeable and the practical sessions were very helpful."
399
+ }
400
+ ]
401
+ },
402
+ {
403
+ "professor_id": "B1C2D3",
404
+ "name": "Dr. E. Patel",
405
+ "course": "Mobile Computing",
406
+ "reviews": [
407
+ {
408
+ "rating": 4.6,
409
+ "review_text": "Dr. Patel’s course is highly relevant with a focus on current mobile computing technologies."
410
+ },
411
+ {
412
+ "rating": 4.2,
413
+ "review_text": "Good content but the pace of the course could be adjusted for better understanding."
414
+ },
415
+ {
416
+ "rating": 4.7,
417
+ "review_text": "Excellent course with practical insights into mobile application development."
418
+ }
419
+ ]
420
+ },
421
+ {
422
+ "professor_id": "C4D5E6",
423
+ "name": "Dr. F. Kumar",
424
+ "course": "Network Security",
425
+ "reviews": [
426
+ {
427
+ "rating": 4.5,
428
+ "review_text": "Dr. Kumar’s course is very informative with a lot of practical network security scenarios."
429
+ },
430
+ {
431
+ "rating": 4.1,
432
+ "review_text": "Content is relevant, but more case studies would enhance the learning experience."
433
+ },
434
+ {
435
+ "rating": 4.7,
436
+ "review_text": "Highly detailed and practical course on network security with a lot of hands-on labs."
437
+ }
438
+ ]
439
+ },
440
+ {
441
+ "professor_id": "D7E8F9",
442
+ "name": "Dr. G. Rao",
443
+ "course": "Systems Programming",
444
+ "reviews": [
445
+ {
446
+ "rating": 4.4,
447
+ "review_text": "Dr. Rao’s course on systems programming is well-structured and comprehensive."
448
+ },
449
+ {
450
+ "rating": 4.0,
451
+ "review_text": "Good theoretical coverage but practical examples could be more in-depth."
452
+ },
453
+ {
454
+ "rating": 4.6,
455
+ "review_text": "Excellent course with practical exercises and real-world programming problems."
456
+ }
457
+ ]
458
+ },
459
+ {
460
+ "professor_id": "E1F2G3",
461
+ "name": "Dr. H. Gupta",
462
+ "course": "Computer Architecture",
463
+ "reviews": [
464
+ {
465
+ "rating": 4.4,
466
+ "review_text": "Dr. Gupta provides a thorough understanding of computer architecture with clear explanations."
467
+ },
468
+ {
469
+ "rating": 4.2,
470
+ "review_text": "Good course but some of the concepts are a bit complex for beginners."
471
+ },
472
+ {
473
+ "rating": 4.6,
474
+ "review_text": "Highly engaging with practical insights into computer hardware and architecture."
475
+ }
476
+ ]
477
+ },
478
+ {
479
+ "professor_id": "F1G2H3",
480
+ "name": "Dr. M. Verma",
481
+ "course": "Parallel Computing",
482
+ "reviews": [
483
+ {
484
+ "rating": 4.3,
485
+ "review_text": "Dr. Verma’s course on parallel computing is insightful with practical applications."
486
+ },
487
+ {
488
+ "rating": 4.0,
489
+ "review_text": "Good coverage of parallel computing concepts but could use more hands-on labs."
490
+ },
491
+ {
492
+ "rating": 4.5,
493
+ "review_text": "Excellent explanations and practical exercises. Highly recommended for advanced learners."
494
+ }
495
+ ]
496
+ },
497
+ {
498
+ "professor_id": "G2H3I4",
499
+ "name": "Dr. L. Shah",
500
+ "course": "Big Data",
501
+ "reviews": [
502
+ {
503
+ "rating": 4.4,
504
+ "review_text": "Dr. Shah provides a comprehensive overview of big data technologies and tools."
505
+ },
506
+ {
507
+ "rating": 4.1,
508
+ "review_text": "Good course, but the pace could be slower for better understanding."
509
+ },
510
+ {
511
+ "rating": 4.6,
512
+ "review_text": "Highly engaging with real-world examples and practical applications in big data."
513
+ }
514
+ ]
515
+ },
516
+ {
517
+ "professor_id": "H3I4J5",
518
+ "name": "Dr. P. Kumar",
519
+ "course": "Bioinformatics",
520
+ "reviews": [
521
+ {
522
+ "rating": 4.2,
523
+ "review_text": "Dr. Kumar’s course on bioinformatics is well-structured and informative."
524
+ },
525
+ {
526
+ "rating": 4.0,
527
+ "review_text": "Interesting content, though the course could benefit from more practical exercises."
528
+ },
529
+ {
530
+ "rating": 4.5,
531
+ "review_text": "Excellent for understanding bioinformatics with practical insights and applications."
532
+ }
533
+ ]
534
+ },
535
+ {
536
+ "professor_id": "I4J5K6",
537
+ "name": "Dr. S. Patel",
538
+ "course": "Human-Robot Interaction",
539
+ "reviews": [
540
+ {
541
+ "rating": 4.5,
542
+ "review_text": "Dr. Patel’s course is engaging with a lot of hands-on projects and case studies."
543
+ },
544
+ {
545
+ "rating": 4.2,
546
+ "review_text": "Good theoretical content but could use more interactive sessions."
547
+ },
548
+ {
549
+ "rating": 4.7,
550
+ "review_text": "Highly recommended for those interested in robotics and human-robot interaction."
551
+ }
552
+ ]
553
+ },
554
+ {
555
+ "professor_id": "J5K6L7",
556
+ "name": "Dr. N. Choudhury",
557
+ "course": "Advanced Databases",
558
+ "reviews": [
559
+ {
560
+ "rating": 4.6,
561
+ "review_text": "Dr. Choudhury offers a deep dive into advanced database systems with practical examples."
562
+ },
563
+ {
564
+ "rating": 4.3,
565
+ "review_text": "Theoretical aspects are well-covered but more real-world projects would be beneficial."
566
+ },
567
+ {
568
+ "rating": 4.8,
569
+ "review_text": "Excellent teaching with complex concepts made accessible through practical exercises."
570
+ }
571
+ ]
572
+ },
573
+ {
574
+ "professor_id": "K6L7M8",
575
+ "name": "Dr. R. Bhatt",
576
+ "course": "Software Development Lifecycle",
577
+ "reviews": [
578
+ {
579
+ "rating": 4.4,
580
+ "review_text": "Dr. Bhatt provides a solid understanding of the software development lifecycle with clear explanations."
581
+ },
582
+ {
583
+ "rating": 4.1,
584
+ "review_text": "Good course content but could use more interactive discussions and case studies."
585
+ },
586
+ {
587
+ "rating": 4.6,
588
+ "review_text": "Highly practical with useful insights into each phase of software development."
589
+ }
590
+ ]
591
+ },
592
+ {
593
+ "professor_id": "L7M8N9",
594
+ "name": "Dr. A. Kapoor",
595
+ "course": "Data Mining",
596
+ "reviews": [
597
+ {
598
+ "rating": 4.3,
599
+ "review_text": "Dr. Kapoor’s course is comprehensive with practical data mining techniques and tools."
600
+ },
601
+ {
602
+ "rating": 4.0,
603
+ "review_text": "Content is relevant but the pace could be adjusted for better learning."
604
+ },
605
+ {
606
+ "rating": 4.7,
607
+ "review_text": "Excellent for practical data mining applications with lots of hands-on exercises."
608
+ }
609
+ ]
610
+ },
611
+ {
612
+ "professor_id": "M8N9O1",
613
+ "name": "Dr. T. Reddy",
614
+ "course": "Reinforcement Learning",
615
+ "reviews": [
616
+ {
617
+ "rating": 4.5,
618
+ "review_text": "Dr. Reddy’s course offers a deep understanding of reinforcement learning with practical examples."
619
+ },
620
+ {
621
+ "rating": 4.2,
622
+ "review_text": "Good coverage of reinforcement learning concepts but could benefit from more interactive labs."
623
+ },
624
+ {
625
+ "rating": 4.8,
626
+ "review_text": "Highly engaging with excellent practical exercises and real-world applications."
627
+ }
628
+ ]
629
+ },
630
+ {
631
+ "professor_id": "N9O1P2",
632
+ "name": "Dr. V. Sharma",
633
+ "course": "Augmented Reality",
634
+ "reviews": [
635
+ {
636
+ "rating": 4.4,
637
+ "review_text": "Dr. Sharma’s course is insightful with practical projects in augmented reality."
638
+ },
639
+ {
640
+ "rating": 4.1,
641
+ "review_text": "Interesting course but could use more hands-on exercises."
642
+ },
643
+ {
644
+ "rating": 4.6,
645
+ "review_text": "Excellent for learning about augmented reality with a lot of practical applications."
646
+ }
647
+ ]
648
+ },
649
+ {
650
+ "professor_id": "O1P2Q3",
651
+ "name": "Dr. K. Mehta",
652
+ "course": "Blockchain Technology",
653
+ "reviews": [
654
+ {
655
+ "rating": 4.5,
656
+ "review_text": "Dr. Mehta provides a thorough understanding of blockchain technology with practical examples."
657
+ },
658
+ {
659
+ "rating": 4.2,
660
+ "review_text": "Good content but could benefit from more interactive labs."
661
+ },
662
+ {
663
+ "rating": 4.7,
664
+ "review_text": "Highly engaging with real-world applications and hands-on projects."
665
+ }
666
+ ]
667
+ },
668
+ {
669
+ "professor_id": "P2Q3R4",
670
+ "name": "Dr. N. Patel",
671
+ "course": "Speech Processing",
672
+ "reviews": [
673
+ {
674
+ "rating": 4.3,
675
+ "review_text": "Dr. Patel’s course on speech processing is well-structured with practical examples."
676
+ },
677
+ {
678
+ "rating": 4.0,
679
+ "review_text": "Good theoretical coverage but could use more real-world applications."
680
+ },
681
+ {
682
+ "rating": 4.6,
683
+ "review_text": "Excellent course with a lot of practical exercises and applications in speech technology."
684
+ }
685
+ ]
686
+ }
687
+ ]
688
+ }
689
+
util.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
4
+ from langchain_community.vectorstores.faiss import FAISS
5
+ from langchain.chains.question_answering import load_qa_chain
6
+ from langchain.prompts import PromptTemplate
7
+ from langchain_google_genai import GoogleGenerativeAIEmbeddings
8
+ from langchain_google_genai import ChatGoogleGenerativeAI
9
+ import google.generativeai as genai
10
+ from dotenv import load_dotenv
11
+ load_dotenv()
12
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
13
+
14
+ def extract_text(json_path):
15
+ with open(json_path, 'r') as file:
16
+ data = json.load(file)
17
+
18
+ text = ""
19
+ for professor in data['professors']:
20
+ professor_id = professor.get('professor_id')
21
+ name = professor.get('name')
22
+ course = professor.get('course')
23
+ reviews = professor.get('reviews', [])
24
+
25
+ text += f'\nProfessor ID: {professor_id}, Professor Name: {name}, Course: {course}\n '
26
+ if reviews:
27
+ for review in reviews:
28
+ rating = review.get('rating')
29
+ review_text = review.get('review_text')
30
+ text += f"Rating: {rating}, Review: {review_text}\n"
31
+ else:
32
+ print("No reviews available.")
33
+ return text
34
+
35
+ def split_text_into_chunks(text):
36
+ splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
37
+ text_chunks = splitter.split_text(text)
38
+ return text_chunks
39
+
40
+ def create_vector_store(chunks):
41
+ embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
42
+ vector_store = FAISS.from_texts(chunks, embedding=embeddings)
43
+ vector_store.save_local("reviews_index")
44
+
45
+ def main(json_path):
46
+ text = extract_text(json_path)
47
+ chunks = split_text_into_chunks(text)
48
+ create_vector_store(chunks)
49
+
50
+ json_path = 'reviews.json'
51
+ main(json_path)