Neurolingua commited on
Commit
7b79cc2
1 Parent(s): bdbdd9d

Upload 7 files

Browse files
Files changed (7) hide show
  1. DOCKER_README.md +10 -0
  2. Dockerfile +10 -0
  3. app.py +555 -0
  4. database.pkl +3 -0
  5. requirements.txt +15 -0
  6. student_functions.py +362 -0
  7. teacher_function.py +158 -0
DOCKER_README.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Flask App
3
+ emoji: 🚀
4
+ colorFrom: blue
5
+ colorTo: red
6
+ sdk: docker
7
+ pinned: false
8
+ ---
9
+
10
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
Dockerfile ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
7
+
8
+ COPY . /code
9
+
10
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,555 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ from flask import Flask, render_template, request, jsonify,session
3
+ from werkzeug.utils import secure_filename
4
+ import os
5
+ from student_functions import extract_text_from_pdf_s,generate_ai_response,generate_project_idea,generate_project_idea_questions,generate_quiz,generate_response_from_pdf,generate_step_by_step_explanation,perform_ocr,study_plan,ConversationBufferMemory,get_first_youtube_video_link,content_translate,summarise_text,content_translate
6
+ from teacher_function import evaluate,extract_text_from_image,extract_text_from_pdf,generate_questions_from_text,generate_student_report,generate_timetable_module,cluster_topics,generate_timetable_weak
7
+ import shutil
8
+ from ai71 import AI71
9
+ import re
10
+ from flask import Flask, render_template, request, jsonify,session,current_app,send_from_directory
11
+
12
+ AI71_API_KEY = "api71-api-df260d58-62e0-46c9-b549-62daa9c409be"
13
+ UPLOAD_FOLDER = 'uploads'
14
+ ALLOWED_EXTENSIONS = {'pdf', 'jpg', 'jpeg' , 'png'}
15
+
16
+ app = Flask(__name__)
17
+ app.secret_key = 'your_unique_secret_key' # Add this line
18
+ if os.path.exists('uploads'):
19
+ shutil.rmtree('uploads')
20
+ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
21
+ memory = ConversationBufferMemory()
22
+ database=joblib.load('database.pkl')
23
+ teacher_data=database[0]
24
+ student_data=database[1]
25
+ def allowed_file(filename):
26
+ return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
27
+
28
+
29
+ @app.route('/')
30
+ def index():
31
+ return render_template('index.html')
32
+
33
+ @app.route('/student')
34
+ def student():
35
+ student = {
36
+ 'name': session.get('student_name'),
37
+ 'id': session.get('student_id'),
38
+ 'school': session.get('student_school'),
39
+ 'dob': session.get('student_dob'),
40
+ 'email': session.get('student_email'),
41
+ 'subjects_interested': session.get('student_subjects_interested', []),
42
+ 'subjects_needing_improvement': session.get('student_subjects_needing_improvement', [])
43
+ }
44
+ return render_template('student.html', student=student)
45
+
46
+ @app.route('/student_login', methods=['POST'])
47
+ def student_login():
48
+ data = request.json
49
+ name = data.get('name')
50
+ password = data.get('password')
51
+
52
+ # Verify credentials
53
+ for student in student_data:
54
+ if student['name'] == name and student['password'] == password:
55
+ # Set session data
56
+ session['student_name'] = student['name']
57
+ session['student_id'] = student.get('id', 'N/A') # If ID is not in data, default to 'N/A'
58
+ session['student_school'] = student['school']
59
+ session['student_dob'] = student['dob']
60
+ session['student_email'] = student['email']
61
+ session['student_subjects_interested'] = student['interests']
62
+ session['student_subjects_needing_improvement'] = [student['areas_to_improve']]
63
+ return jsonify({'success': True})
64
+
65
+ return jsonify({'success': False})
66
+
67
+
68
+ @app.route('/teacher_login', methods=['POST'])
69
+ def teacher_login():
70
+ data = request.json
71
+ name = data.get('name')
72
+ password = data.get('password')
73
+
74
+ # Verify credentials
75
+ for teacher in teacher_data:
76
+ if teacher['name'] == name and teacher['password'] == password:
77
+ # Set session data
78
+ session['teacher_name'] = teacher['name']
79
+ session['teacher_id'] = teacher['teacher_id']
80
+ session['teacher_school'] = teacher['school']
81
+ session['teacher_dob'] = teacher['date_of_birth']
82
+ session['teacher_email'] = teacher['email']
83
+ session['teacher_subjects_taught'] = teacher['subjects_taught']
84
+ session['teacher_classes'] = teacher['classes']
85
+ session['teacher_performance'] = teacher['teaching_performance']
86
+ session['teacher_qualifications'] = teacher['qualifications']
87
+ session['teacher_years_of_experience'] = teacher['years_of_experience']
88
+ session['weekly_class_performance']= teacher['weekly_class_performance']
89
+ return jsonify({'success': True})
90
+
91
+ return jsonify({'success': False})
92
+
93
+ @app.route('/teacher')
94
+ def teacher():
95
+ teacher = {
96
+ 'name': session.get('teacher_name'),
97
+ 'id': session.get('teacher_id'),
98
+ 'school': session.get('teacher_school'),
99
+ 'dob': session.get('teacher_dob'),
100
+ 'email': session.get('teacher_email'),
101
+ 'subjects_taught': session.get('teacher_subjects_taught', []),
102
+ 'classes': session.get('teacher_classes', []),
103
+ 'performance': session.get('teacher_performance', {}),
104
+ 'qualifications': session.get('teacher_qualifications', []),
105
+ 'years_of_experience': session.get('teacher_years_of_experience', 0),
106
+ 'weekly_class_performance': session.get('teacher_weekly_class_performance', {})
107
+ }
108
+ return render_template('teacher.html', teacher=teacher)
109
+
110
+ @app.route('/student_pdfqa', methods=['GET', 'POST'])
111
+ def student_pdfqa():
112
+ if request.method == 'POST':
113
+ file = request.files.get('pdf-file')
114
+ if file and allowed_file(file.filename):
115
+ filename = secure_filename(file.filename)
116
+ file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
117
+ file.save(file_path)
118
+
119
+ pdf_text = extract_text_from_pdf_s(file_path)
120
+ return jsonify({'message': f'PDF uploaded and processed. You can now ask questions.', 'pdf_text': pdf_text})
121
+ else:
122
+ return jsonify({'message': 'Invalid file type. Please upload a PDF.'}), 400
123
+
124
+ return render_template('student_pdfqa.html')
125
+
126
+ @app.route('/ask_pdf_question', methods=['POST'])
127
+ def ask_pdf_question():
128
+ data = request.json
129
+ query = data['query']
130
+ pdf_text = data['pdf_text']
131
+
132
+ response = generate_response_from_pdf(query, pdf_text)[:-6]
133
+ return jsonify({'response': response})
134
+
135
+ @app.route('/student_aitutor')
136
+ def student_aitutor():
137
+ return render_template('student_aitutor.html')
138
+
139
+ @app.route('/chat', methods=['POST'])
140
+ def chat():
141
+ data = request.json
142
+ query = data['message']
143
+ response = generate_ai_response(query)
144
+ return jsonify({'response': response})
145
+
146
+ @app.route('/upload_image_for_ocr', methods=['POST'])
147
+ def upload_image_for_ocr():
148
+ if 'image-file' not in request.files:
149
+ return jsonify({'error': 'No file part'}), 400
150
+ file = request.files['image-file']
151
+ if file.filename == '':
152
+ return jsonify({'error': 'No selected file'}), 400
153
+ if file and allowed_file(file.filename):
154
+ filename = secure_filename(file.filename)
155
+ file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
156
+ file.save(file_path)
157
+
158
+ extracted_text = perform_ocr(file_path)
159
+ ai_response = generate_ai_response(extracted_text)
160
+
161
+ return jsonify({'ai_response': ai_response})
162
+ return jsonify({'error': 'Invalid file type'}), 400
163
+
164
+
165
+ @app.route('/student_projectideas')
166
+ def student_projectideas():
167
+ return render_template('student_projectideas.html')
168
+
169
+ @app.route('/student_quiz')
170
+ def student_quiz():
171
+ return render_template('student_quiz.html')
172
+
173
+ @app.route('/update_student_areas', methods=['POST'])
174
+ def update_student_areas():
175
+ data = request.json
176
+ student_id = data.get('student_id')
177
+ areas_to_improve = data.get('areas_to_improve')
178
+
179
+ # Find the student in the database
180
+ student = next((s for s in student_data if s['email'] == student_id), None)
181
+
182
+ if student:
183
+ # Update the student's areas to improve
184
+ student['areas_to_improve'] = areas_to_improve
185
+ return jsonify({'status': 'success'})
186
+ else:
187
+ return jsonify({'status': 'error', 'message': 'Student not found'}), 404
188
+ @app.route('/get_student_profile', methods=['GET'])
189
+ def get_student_profile():
190
+ # For demonstration, assume `student_id` is passed in query parameters
191
+ student_id = request.args.get('student_id')
192
+ student = next((s for s in student_data if s['email'] == student_id), None)
193
+
194
+ if student:
195
+ return jsonify({
196
+ 'status': 'success',
197
+ 'areas_to_improve': student.get('areas_to_improve', [])
198
+ })
199
+ else:
200
+ return jsonify({'status': 'error', 'message': 'Student not found'}), 404
201
+
202
+
203
+ def calculate_score_and_grade(llm_response):
204
+ pattern = r'Assigned marks: (\d+)/(\d+)'
205
+ matches = re.findall(pattern, llm_response)
206
+
207
+ total_score = sum(int(score) for score, max_score in matches)
208
+ max_possible_score = sum(int(max_score) for score, max_score in matches)
209
+
210
+ percentage = (total_score / max_possible_score) * 100 if max_possible_score > 0 else 0
211
+
212
+ if percentage > 90:
213
+ grade = 'O'
214
+ elif 80 <= percentage <= 90:
215
+ grade = 'A'
216
+ elif 70 <= percentage < 80:
217
+ grade = 'B'
218
+ elif 60 <= percentage < 70:
219
+ grade = 'C'
220
+ elif 50 <= percentage < 60:
221
+ grade = 'D'
222
+ else:
223
+ grade = 'Fail'
224
+
225
+ return total_score, max_possible_score, percentage, grade
226
+ @app.route('/student_reward_points')
227
+ def student_reward_points():
228
+ return render_template('student_reward_points.html')
229
+
230
+ @app.route('/generate_quiz', methods=['POST'])
231
+ def generate_quiz_route():
232
+ data = request.json
233
+ subject = data['subject']
234
+ topic = data['topic']
235
+ count = int(data['num-questions'])
236
+ difficulty = data['difficulty']
237
+
238
+ quiz = generate_quiz(subject, topic, count, difficulty)
239
+ return jsonify({'quiz': quiz})
240
+
241
+ @app.route('/generate_project_idea', methods=['POST'])
242
+ def generate_project_idea_route():
243
+ data = request.json
244
+ subject = data['subject']
245
+ topic = data['topic']
246
+ plan = data['plan']
247
+
248
+ project_idea = generate_project_idea(subject, topic, plan)
249
+ return jsonify({'project_idea': project_idea})
250
+
251
+ @app.route('/homework')
252
+ def homework():
253
+ return render_template('homework.html')
254
+
255
+ @app.route('/student_courses')
256
+ def student_courses():
257
+ return render_template('student_courses.html')
258
+
259
+ @app.route('/search_youtube', methods=['POST'])
260
+ def search_youtube():
261
+ data = request.json
262
+ query = data['query']
263
+
264
+ try:
265
+ video_link, video_title = get_first_youtube_video_link(query)
266
+ video_id = video_link.split('v=')[1]
267
+ return jsonify({
268
+ 'videoId': video_id,
269
+ 'videoTitle': video_title
270
+ })
271
+ except Exception as e:
272
+ return jsonify({'error': f'An error occurred: {str(e)}'}), 500
273
+
274
+ @app.route('/ask_followup', methods=['POST'])
275
+ def ask_followup_route():
276
+ data = request.json
277
+ project_idea = data['project_idea']
278
+ query = data['query']
279
+
280
+ response = generate_project_idea_questions(project_idea, query)
281
+ return jsonify({'response': response})
282
+
283
+ @app.route('/student_studyplans')
284
+ def student_studyplans():
285
+ return render_template('student_studyplans.html')
286
+
287
+ @app.route('/generate_study_plan', methods=['POST'])
288
+ def generate_study_plan_route():
289
+ data = request.json
290
+ subjects = data['subjects']
291
+ hours = data['hours']
292
+ area_lag = data['areaLag'] # Ensure the key matches
293
+ goal = data['goal']
294
+ learning_style = data['learningStyle']
295
+
296
+ study_plan_text = study_plan(subjects, hours, area_lag, goal)
297
+ return jsonify({'study_plan': study_plan_text})
298
+
299
+
300
+ @app.route('/student_stepexplanation')
301
+ def student_stepexplanation():
302
+ return render_template('student_stepexplanation.html')
303
+
304
+
305
+ @app.route('/evaluate-answers', methods=['POST'])
306
+ def evaluate_answers():
307
+ data = request.json
308
+ questions = data['questions']
309
+ answers = data['answers']
310
+ max_marks = 5 # As per your requirement
311
+
312
+ evaluations = []
313
+ for question, answer in zip(questions, answers):
314
+ if answer.strip() == "":
315
+ evaluation = "Description: No answer provided.\nAssigned marks: 0\nTotal marks: 5"
316
+ else:
317
+ evaluation = evaluate(question, answer, max_marks)
318
+ evaluations.append(evaluation)
319
+
320
+ return jsonify({"evaluations": evaluations})
321
+
322
+ @app.route('/translate', methods=['POST'])
323
+ def translate():
324
+ data = request.json
325
+ text = data.get('text', '')
326
+ # Mock translation function
327
+ translated_text = content_translate(text)
328
+ return jsonify({"translated_text": translated_text})
329
+
330
+ @app.route('/generate_step_by_step_explanation', methods=['POST'])
331
+ def generate_step_by_step_explanation_route():
332
+ data = request.get_json()
333
+ question = data['question']
334
+ answer = generate_step_by_step_explanation(question)
335
+ return jsonify({'answer': answer})
336
+
337
+ @app.route('/speak')
338
+ def speak():
339
+ return render_template('student_speakai.html')
340
+
341
+ @app.route('/generate_ai_timetable', methods=['POST'])
342
+ def generate_ai_timetable():
343
+ academic_topics = request.form['academic_topics'].split(',')
344
+ hours_per_day = request.form['hours_per_day']
345
+
346
+ clustered_topics = cluster_topics(academic_topics)
347
+ special_timetable = generate_timetable_weak(clustered_topics, hours_per_day)
348
+
349
+ return jsonify({
350
+ 'clustered_topics': clustered_topics,
351
+ 'special_timetable': special_timetable
352
+ })
353
+
354
+
355
+ @app.route('/ai_timetable')
356
+ def ai_timetable():
357
+ return render_template('ai_timetable.html')
358
+
359
+ @app.route('/summarise_video')
360
+ def summarise_video():
361
+ return render_template('student_summarise_video.html')
362
+
363
+ @app.route('/summarize_video', methods=['POST'])
364
+ def summarize_video_route():
365
+ data = request.json
366
+ url = data.get('url')
367
+ if url:
368
+ try:
369
+ summary = summarise_text(url)
370
+ return jsonify({'summary': summary})
371
+ except Exception as e:
372
+ return jsonify({'error': str(e)}), 500
373
+ else:
374
+ return jsonify({'error': 'No URL provided'}), 400
375
+
376
+
377
+ @app.route('/generate-questions-hw', methods=['GET'])
378
+ def generate_questions():
379
+ messages = [
380
+ {"role": "system", "content": "You are a helpful assistant."},
381
+ {"role": "user", "content": (
382
+ "Generate 5 questions for a Math Assignment on 'trigonometry Basics'. "
383
+ "Include a mix of both theoretical and numerical questions."
384
+ )}
385
+ ]
386
+
387
+ questions = []
388
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
389
+ model="tiiuae/falcon-180b-chat",
390
+ messages=messages,
391
+ stream=True,
392
+ ):
393
+ if chunk.choices[0].delta.content:
394
+ questions.append(chunk.choices[0].delta.content)
395
+
396
+ # Join all chunks to create the complete list of questions
397
+ complete_questions = ''.join(questions).split('\n')
398
+
399
+ return jsonify({'questions': complete_questions})
400
+
401
+ @app.route('/assign_grade', methods=['POST'])
402
+ def assign_grade():
403
+ data = request.json
404
+ result = data['result']
405
+ total_score, max_possible_score, percentage, grade = calculate_score_and_grade(result)
406
+ return jsonify({
407
+ 'total_score': total_score,
408
+ 'max_possible_score': max_possible_score,
409
+ 'percentage': percentage,
410
+ 'grade': grade
411
+ })
412
+
413
+ @app.route('/generate_timetable', methods=['POST'])
414
+ def generate_timetable():
415
+ data = request.json
416
+ hours_per_day = data.get('hours_per_day')
417
+ days_per_week = data.get('days_per_week')
418
+ semester_end_date = data.get('semester_end_date')
419
+ subjects = data.get('subjects', [])
420
+
421
+ # Input validation
422
+ if not hours_per_day or not days_per_week or not semester_end_date or not subjects:
423
+ return jsonify({"error": "Missing required parameters"}), 400
424
+
425
+ try:
426
+ timetable=generate_timetable_module(data,hours_per_day,days_per_week,semester_end_date,subjects)
427
+
428
+ return jsonify({"timetable": timetable})
429
+
430
+ except Exception as e:
431
+ return jsonify({"error": str(e)}), 500
432
+
433
+
434
+ @app.route('/generate-paper', methods=['GET', 'POST'])
435
+ def generate_paper():
436
+ if request.method == 'POST':
437
+ no_of_questions = int(request.form['no_of_questions'])
438
+ total_marks = int(request.form['total_marks'])
439
+ no_of_parts = int(request.form['no_of_parts'])
440
+ marks_per_part = int(request.form['marks_per_part'])
441
+ test_duration = request.form['test_duration']
442
+ pdf_file = request.files['pdf_file']
443
+
444
+ if pdf_file:
445
+ # Secure the file name and save the file to the upload folder
446
+ filename = secure_filename(pdf_file.filename)
447
+ file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
448
+ pdf_file.save(file_path)
449
+
450
+ # Extract text from the curriculum PDF
451
+ curriculum_text = extract_text_from_pdf(file_path)
452
+
453
+ # Generate questions
454
+ questions = generate_questions_from_text(curriculum_text, no_of_questions, marks_per_part, no_of_parts)
455
+
456
+ # Optionally, remove the saved file after use
457
+ os.remove(file_path)
458
+
459
+ return render_template('teacher_paper_gen.html', questions=questions)
460
+
461
+ return render_template('teacher_paper_gen.html')
462
+
463
+
464
+ @app.route('/eval', methods=['GET', 'POST'])
465
+ def eval():
466
+ if request.method == 'POST':
467
+ input_type = request.form['input_type']
468
+ question_text = ""
469
+ answer_text = ""
470
+ max_marks = request.form['max_marks']
471
+
472
+ if input_type == 'file':
473
+ question_file = request.files['question_file']
474
+ answer_file = request.files['answer_file']
475
+
476
+ if question_file and answer_file:
477
+ question_path = os.path.join(app.config['UPLOAD_FOLDER'], question_file.filename)
478
+ answer_path = os.path.join(app.config['UPLOAD_FOLDER'], answer_file.filename)
479
+
480
+ question_file.save(question_path)
481
+ answer_file.save(answer_path)
482
+
483
+ if question_path.endswith('.pdf'):
484
+ question_text = extract_text_from_pdf(question_path)
485
+ else:
486
+ question_text = extract_text_from_image(question_path)
487
+
488
+ if answer_path.endswith('.pdf'):
489
+ answer_text = extract_text_from_pdf(answer_path)
490
+ else:
491
+ answer_text = extract_text_from_image(answer_path)
492
+
493
+ elif input_type == 'text':
494
+ question_text = request.form['question_text']
495
+ answer_text = request.form['answer_text']
496
+
497
+ evaluation_result = evaluate(question_text, answer_text, max_marks)
498
+ print(f"Question Text: {question_text}") # Debugging line
499
+ print(f"Answer Text: {answer_text}") # Debugging line
500
+ print(f"Evaluation Result: {evaluation_result}") # Debugging line
501
+
502
+ return render_template('teacher_result.html', result=evaluation_result)
503
+
504
+ return render_template('teacher_eval.html')
505
+
506
+ @app.route('/get_students')
507
+ def get_students():
508
+
509
+ return jsonify(student_data)
510
+
511
+
512
+ @app.route('/get_audio_files', methods=['GET'])
513
+ def get_audio_files():
514
+ audio_folder = os.path.join(app.root_path, 'speech')
515
+ audio_files = [{'name': file, 'url': f'/speech/{file}'} for file in os.listdir(audio_folder) if
516
+ file.endswith('.mp3')]
517
+
518
+ current_app.logger.info(f"Found audio files: {audio_files}")
519
+
520
+ return jsonify({'audio_files': audio_files})
521
+
522
+
523
+ @app.route('/speech/<path:filename>')
524
+ def serve_audio(filename):
525
+ return send_from_directory(os.path.join(app.root_path, 'speech'), filename)
526
+
527
+
528
+
529
+ @app.route('/generate_report', methods=['POST'])
530
+ def generate_report():
531
+ student_data = request.json
532
+ report = generate_student_report(
533
+ student_data['name'],
534
+ student_data['age'],
535
+ student_data['cgpa'],
536
+ student_data['course_pursuing'],
537
+ student_data['assigned_test_score'],
538
+ student_data['ai_test_score'],
539
+ student_data['interests'],
540
+ student_data['areas_to_improve'],
541
+ student_data['courses_taken']
542
+ )
543
+ return jsonify({'report': report})
544
+
545
+
546
+
547
+
548
+ if __name__ == '__main__':
549
+ if os.path.exists('uploads'):
550
+ shutil.rmtree('uploads')
551
+ os.makedirs('uploads')
552
+ else:
553
+ os.makedirs('uploads')
554
+ app.run( port=5000, debug=True)
555
+
database.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c31f0fc600fc2250c17e3e1424bcf4d3af772b8a0ca32bd95661771dd213354
3
+ size 3124
requirements.txt ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Flask
2
+ Werkzeug
3
+ selenium
4
+ easyocr
5
+ youtube-transcript-api
6
+ pypdf
7
+ PyPDF2
8
+ pdf2image
9
+ opencv-python-headless
10
+ numpy
11
+ pytesseract
12
+ joblib
13
+ requests
14
+ ai71
15
+ setuptools
student_functions.py ADDED
@@ -0,0 +1,362 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gtts import gTTS
2
+ import shutil
3
+ from selenium import webdriver
4
+ from selenium.webdriver.common.by import By
5
+ from selenium.webdriver.common.keys import Keys
6
+ from selenium.webdriver.support.ui import WebDriverWait
7
+ from selenium.webdriver.support import expected_conditions as EC
8
+ import easyocr
9
+ import json
10
+ from youtube_transcript_api import YouTubeTranscriptApi
11
+ from youtube_transcript_api.formatters import JSONFormatter
12
+ from urllib.parse import urlparse, parse_qs
13
+ from pypdf import PdfReader
14
+ from ai71 import AI71
15
+ import os
16
+
17
+ AI71_API_KEY = "api71-api-df260d58-62e0-46c9-b549-62daa9c409be"
18
+
19
+
20
+ def extract_text_from_pdf_s(pdf_path):
21
+ text = ""
22
+ reader = PdfReader(pdf_path)
23
+ for page in reader.pages:
24
+ text += page.extract_text() + "\n"
25
+ generate_speech_from_pdf(text[:len(text) // 2])
26
+ return text
27
+
28
+
29
+ def generate_response_from_pdf(query, pdf_text):
30
+ response = ''
31
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
32
+ model="tiiuae/falcon-180b-chat",
33
+ messages=[
34
+ {"role": "system", "content": "You are a pdf questioning assistant."},
35
+ {"role": "user",
36
+ "content": f'''Answer the querry based on the given content.Content:{pdf_text},query:{query}'''},
37
+ ],
38
+ stream=True,
39
+ ):
40
+ if chunk.choices[0].delta.content:
41
+ response += chunk.choices[0].delta.content
42
+ return response[:-6].replace("###", '')
43
+
44
+
45
+ def generate_quiz(subject, topic, count, difficult):
46
+ quiz_output = ""
47
+
48
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
49
+ model="tiiuae/falcon-180b-chat",
50
+ messages=[
51
+ {"role": "system", "content": "You are a teaching assistant."},
52
+ {"role": "user",
53
+ "content": f'''Generate {count} multiple-choice questions in the subject of {subject} for the topic {topic} for students at a {difficult} level. Ensure the questions are well-diversified and cover various aspects of the topic. Format the questions as follows:
54
+ Question: [Question text] [specific concept in a question]
55
+ <<o>> [Option1]
56
+ <<o>> [Option2]
57
+ <<o>> [Option3]
58
+ <<o>> [Option4],
59
+ Answer: [Option number]'''},
60
+ ],
61
+ stream=True,
62
+ ):
63
+ if chunk.choices[0].delta.content:
64
+ quiz_output += chunk.choices[0].delta.content
65
+ print("Quiz generated")
66
+ return quiz_output
67
+
68
+
69
+ def perform_ocr(image_path):
70
+ reader = easyocr.Reader(['en'])
71
+ try:
72
+ result = reader.readtext(image_path)
73
+ extracted_text = ''
74
+ for (bbox, text, prob) in result:
75
+ extracted_text += text + ' '
76
+ return extracted_text.strip()
77
+ except Exception as e:
78
+ print(f"Error during OCR: {e}")
79
+ return ''
80
+
81
+
82
+ def generate_ai_response(query):
83
+ ai_response = ''
84
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
85
+ model="tiiuae/falcon-180b-chat",
86
+ messages=[
87
+ {"role": "system", "content": "You are a teaching assistant."},
88
+ {"role": "user", "content": f'Assist the user clearly for his questions: {query}.'},
89
+ ],
90
+ stream=True,
91
+ ):
92
+ if chunk.choices[0].delta.content:
93
+ ai_response += chunk.choices[0].delta.content
94
+ return ai_response.replace('###', '')[:-6]
95
+
96
+
97
+ def generate_project_idea(subject, topic, overview):
98
+ string = ''
99
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
100
+ model="tiiuae/falcon-180b-chat",
101
+ messages=[
102
+ {"role": "system", "content": "You are a project building assistant."},
103
+ {"role": "user",
104
+ "content": f'''Give the different project ideas to build project in {subject} specifically in {topic} for school students. {overview}.'''},
105
+ ],
106
+ stream=True,
107
+ ):
108
+ if chunk.choices[0].delta.content:
109
+ string += chunk.choices[0].delta.content
110
+ return string
111
+
112
+
113
+ def generate_project_idea_questions(project_idea, query):
114
+ project_idea_answer = ''
115
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
116
+ model="tiiuae/falcon-180b-chat",
117
+ messages=[
118
+ {"role": "system", "content": "You are a project building assistant."},
119
+ {"role": "user",
120
+ "content": f'''Assist me clearly for the following question for the given idea. Idea: {project_idea}. Question: {query}'''},
121
+ ],
122
+ stream=True,
123
+ ):
124
+ if chunk.choices[0].delta.content:
125
+ project_idea_answer += chunk.choices[0].delta.content
126
+ return project_idea_answer
127
+
128
+
129
+ def generate_step_by_step_explanation(query):
130
+ explanation = ''
131
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
132
+ model="tiiuae/falcon-180b-chat",
133
+ messages=[
134
+ {"role": "system", "content": "You are the best teaching assistant."},
135
+ {"role": "user",
136
+ "content": f'''Provide me the clear step by step explanation answer for the following question. Question: {query}'''},
137
+ ],
138
+ stream=True,
139
+ ):
140
+ if chunk.choices[0].delta.content:
141
+ explanation += chunk.choices[0].delta.content
142
+ return explanation.replace('###', '')
143
+
144
+
145
+ def study_plan(subjects, hours, arealag, goal):
146
+ plan = ''
147
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
148
+ model="tiiuae/falcon-180b-chat",
149
+ messages=[
150
+ {"role": "system", "content": "You are the best teaching assistant."},
151
+ {"role": "user",
152
+ "content": f'''Provide me the clear personalised study plan for the subjects {subjects} i lag in areas like {arealag}, im available for {hours} hours per day and my study goal is to {goal}.Provide me like a timetable like day1,day2 for 5 days with concepts,also suggest some books'''},
153
+ ],
154
+ stream=True,
155
+ ):
156
+ if chunk.choices[0].delta.content:
157
+ plan += chunk.choices[0].delta.content
158
+ return plan.replace('\n', '<br>')
159
+
160
+
161
+ class ConversationBufferMemory:
162
+ def __init__(self, memory_key="chat_history"):
163
+ self.memory_key = memory_key
164
+ self.buffer = []
165
+
166
+ def add_to_memory(self, interaction):
167
+ self.buffer.append(interaction)
168
+
169
+ def get_memory(self):
170
+ return "\n".join([f"Human: {entry['user']}\nAssistant: {entry['assistant']}" for entry in self.buffer])
171
+
172
+
173
+ def spk_msg(user_input, memory):
174
+ chat_history = memory.get_memory()
175
+ msg = ''
176
+
177
+ # Construct the message for the API request
178
+ messages = [
179
+ {"role": "system",
180
+ "content": "You are a nice speaker having a conversation with a human.You ask the question the user choose the topic and let user answer.Provide the response only within 2 sentence"},
181
+ {"role": "user",
182
+ "content": f"Previous conversation:\n{chat_history}\n\nNew human question: {user_input}\nResponse:"}
183
+ ]
184
+
185
+ try:
186
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
187
+ model="tiiuae/falcon-180b-chat",
188
+ messages=messages,
189
+ stream=True,
190
+ ):
191
+ if chunk.choices[0].delta.content:
192
+ msg += chunk.choices[0].delta.content
193
+ except Exception as e:
194
+ print(f"An error occurred: {e}")
195
+
196
+ return msg
197
+
198
+
199
+ def get_first_youtube_video_link(query):
200
+ chrome_options = webdriver.ChromeOptions()
201
+ chrome_options.add_argument("--headless")
202
+ chrome_options.add_argument("--disable-gpu")
203
+ chrome_options.add_argument("--disable-extensions")
204
+ chrome_options.add_argument("--no-sandbox")
205
+ chrome_options.add_argument("--disable-dev-shm-usage")
206
+ driver = webdriver.Chrome(options=chrome_options)
207
+ try:
208
+ driver.get('https://www.youtube.com')
209
+ search_box = driver.find_element(By.NAME, 'search_query')
210
+ search_box.send_keys(query)
211
+ search_box.send_keys(Keys.RETURN)
212
+ WebDriverWait(driver, 10).until(
213
+ EC.presence_of_element_located((By.CSS_SELECTOR, 'a#video-title')))
214
+ first_video = driver.find_element(By.CSS_SELECTOR, 'a#video-title')
215
+ first_video_link = first_video.get_attribute('href')
216
+ video_title = first_video.get_attribute('title')
217
+ return first_video_link, video_title
218
+ finally:
219
+ driver.quit()
220
+ return
221
+
222
+
223
+ def content_translate(text):
224
+ translated_content = ''
225
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
226
+ model="tiiuae/falcon-180b-chat",
227
+ messages=[
228
+ {"role": "system", "content": "You are the best teaching assistant."},
229
+ {"role": "user", "content": f'''Translate the text to hindi. Text: {text}'''},
230
+ ],
231
+ stream=True,
232
+ ):
233
+ if chunk.choices[0].delta.content:
234
+ translated_content += chunk.choices[0].delta.content
235
+ return translated_content
236
+
237
+
238
+ def get_video_id(url):
239
+ """
240
+ Extract the video ID from a YouTube URL.
241
+ """
242
+ parsed_url = urlparse(url)
243
+ if parsed_url.hostname == 'www.youtube.com' or parsed_url.hostname == 'youtube.com':
244
+ video_id = parse_qs(parsed_url.query).get('v')
245
+ if video_id:
246
+ return video_id[0]
247
+ elif parsed_url.hostname == 'youtu.be':
248
+ return parsed_url.path[1:]
249
+ return None
250
+
251
+
252
+ def extract_captions(video_url):
253
+ """
254
+ Extract captions from a YouTube video URL.
255
+ """
256
+ video_id = get_video_id(video_url)
257
+ if not video_id:
258
+ print("Invalid YouTube URL.")
259
+ return
260
+
261
+ try:
262
+ transcript = YouTubeTranscriptApi.get_transcript(video_id)
263
+ formatter = JSONFormatter()
264
+ formatted_transcript = formatter.format_transcript(transcript)
265
+
266
+ # Save captions to a file
267
+ with open(f'youtube_captions.json', 'w') as file:
268
+ file.write(formatted_transcript)
269
+
270
+ print("Captions have been extracted and saved as JSON.")
271
+
272
+ except Exception as e:
273
+ print(f"An error occurred: {e}")
274
+
275
+
276
+ def extract_text_from_json(filename):
277
+ # Open and read the JSON file
278
+ with open(filename, 'r') as file:
279
+ data = json.load(file)
280
+
281
+ # Extract and print the text fields
282
+ texts = [entry['text'] for entry in data]
283
+ return texts
284
+
285
+
286
+ def get_simplified_explanation(text):
287
+ prompt = (
288
+ f"The following is a transcript of a video: \n\n{text}\n\n"
289
+ "Please provide a simplified explanation of the video for easy understanding."
290
+ )
291
+
292
+ response = ""
293
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
294
+ model="tiiuae/falcon-180b-chat",
295
+ messages=[
296
+ {"role": "system", "content": "You are a helpful assistant."},
297
+ {"role": "user", "content": prompt},
298
+ ],
299
+ stream=True,
300
+ ):
301
+ if chunk.choices[0].delta.content:
302
+ response += chunk.choices[0].delta.content
303
+
304
+ return response
305
+
306
+
307
+ def summarise_text(url):
308
+ extract_captions(url)
309
+ texts = extract_text_from_json(r'youtube_captions.json')
310
+ os.remove('youtube_captions.json')
311
+
312
+ first_half = (get_simplified_explanation(texts[:len(texts) // 2]))[:-6]
313
+ second_half = (get_simplified_explanation(texts[len(texts) // 2:]))[:-6]
314
+ return (first_half + second_half)
315
+
316
+
317
+ def generate_speech_from_pdf(content):
318
+ if os.path.exists('speech'):
319
+ shutil.rmtree('speech')
320
+ os.makedirs('speech', exist_ok=True)
321
+ else:
322
+ os.makedirs('speech', exist_ok=True)
323
+
324
+ speech = ''
325
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
326
+ model="tiiuae/falcon-180b-chat",
327
+ messages=[
328
+ {"role": "system", "content": "You are a summarising assistant."},
329
+ {"role": "user",
330
+ "content": f'''Summarise the given content for each chapter for 1 sentence.Content={content}'''},
331
+ ],
332
+ stream=True,
333
+ ):
334
+ if chunk.choices[0].delta.content:
335
+ speech += chunk.choices[0].delta.content
336
+ speech = speech[:-6].replace("###", '')
337
+ chapters = speech.split('\n\n')
338
+ pdf_audio(chapters[:4])
339
+ return
340
+
341
+
342
+ def pdf_audio(chapters):
343
+ for i in range(len(chapters)):
344
+ tts = gTTS(text=chapters[i], lang='en', slow=False)
345
+ tts.save(f'speech/chapter {i + 1}.mp3')
346
+ return
347
+
348
+ def content_translate(text):
349
+
350
+
351
+ translated_content = ''
352
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
353
+ model="tiiuae/falcon-180b-chat",
354
+ messages=[
355
+ {"role": "system", "content": "You are the best teaching assistant."},
356
+ {"role": "user", "content": f'''Translate the text to hindi. Text: {text}'''},
357
+ ],
358
+ stream=True,
359
+ ):
360
+ if chunk.choices[0].delta.content:
361
+ translated_content += chunk.choices[0].delta.content
362
+ return translated_content
teacher_function.py ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ai71 import AI71
2
+ from PyPDF2 import PdfReader
3
+ from pdf2image import convert_from_path
4
+ import cv2
5
+ import numpy as np
6
+ import pytesseract
7
+ AI71_API_KEY = "api71-api-20725a9d-46d6-4baf-9e26-abfca35ab242"
8
+
9
+ def extract_text_from_pdf(pdf_file):
10
+ text = ""
11
+ reader = PdfReader(pdf_file)
12
+ for page in reader.pages:
13
+ text += page.extract_text()
14
+ return text
15
+
16
+ def generate_questions_from_text(text, no_of_questions, marks_per_part, no_parts):
17
+ ai71 = AI71(AI71_API_KEY)
18
+ messages = [
19
+ {"role": "system", "content": "You are a teaching assistant"},
20
+ {"role": "user",
21
+ "content": f"Give your own {no_of_questions} questions under each part for {no_parts} parts with {marks_per_part} marks for each part. Note that all questions must be from the topics of {text}"}
22
+ ]
23
+
24
+ questions = []
25
+ for chunk in ai71.chat.completions.create(
26
+ model="tiiuae/falcon-180b-chat",
27
+ messages=messages,
28
+ stream=True,
29
+ ):
30
+ if chunk.choices[0].delta.content:
31
+ questions.append(chunk.choices[0].delta.content)
32
+
33
+ return "".join(questions)
34
+
35
+ def extract_text_from_image(image_path):
36
+ img = cv2.imread(image_path)
37
+ text = pytesseract.image_to_string(img)
38
+ return text
39
+
40
+
41
+ def extract_text_from_pdf(pdf_path):
42
+ images = convert_from_path(pdf_path)
43
+ final_text = ""
44
+ for image in images:
45
+ image_cv = np.array(image)
46
+ image_cv = cv2.cvtColor(image_cv, cv2.COLOR_RGB2BGR)
47
+ text = pytesseract.image_to_string(image_cv)
48
+ final_text += text
49
+ return final_text
50
+
51
+
52
+ def evaluate(question, answer, max_marks):
53
+ prompt = f"""Questions: {question}
54
+ Answer: {answer}.
55
+
56
+
57
+ Evaluate above questions one by one(if there are multiple) by provided answers and assign marks out of {max_marks}. No need overall score. Note that as maximum mark increases, the size of the answer must be large enough to get good marks. Give ouput in format below:
58
+ description:
59
+ assigned marks:
60
+ total marks:
61
+ Note that you should not display total marks"""
62
+
63
+ messages = [
64
+ {"role": "system", "content": "You are an answer evaluator"},
65
+ {"role": "user", "content": prompt}
66
+ ]
67
+
68
+ response_content = ""
69
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
70
+ model="tiiuae/falcon-180b-chat",
71
+ messages=messages,
72
+ stream=True
73
+ ):
74
+ if chunk.choices[0].delta.content:
75
+ response_content += chunk.choices[0].delta.content
76
+
77
+ return response_content
78
+
79
+ def generate_student_report(name, age, cgpa, course, assigned_test, ai_test, interests, difficulty, courses_taken):
80
+ prompt = f"""
81
+ Name: {name}
82
+ Age: {age}
83
+ CGPA: {cgpa}
84
+ Course: {course}
85
+ Assigned Test Score: {assigned_test}
86
+ AI generated Test Score: {ai_test}
87
+ Interests: {interests}
88
+ Difficulty in: {difficulty}
89
+ Courses Taken: {courses_taken}
90
+ Use the above student data to generate a neat personalized report and suggested teaching methods."""
91
+
92
+ client = AI71(AI71_API_KEY)
93
+
94
+ response = client.chat.completions.create(
95
+ model="tiiuae/falcon-180B-chat",
96
+ messages=[
97
+ {"role": "system", "content": "You are a student report generator."},
98
+ {"role": "user", "content": prompt}
99
+ ]
100
+ )
101
+
102
+ report = response.choices[0].message.content if response.choices and response.choices[
103
+ 0].message else "No report generated."
104
+ print(report)
105
+
106
+ return report.replace('\n','<br>')
107
+ def generate_timetable_module(data,hours_per_day,days_per_week,semester_end_date,subjects):
108
+ response = AI71(AI71_API_KEY).chat.completions.create(
109
+ model="tiiuae/falcon-180B-chat",
110
+ messages=[
111
+ {"role": "system", "content": "You are a helpful assistant."},
112
+ {"role": "user", "content": f"Create a timetable starting from Monday based on the following inputs:\n"
113
+ f"- Number of hours per day: {hours_per_day}\n"
114
+ f"- Number of days per week: {days_per_week}\n"
115
+ f"- Semester end date: {semester_end_date}\n"
116
+ f"- Subjects: {', '.join(subjects)}\n"}
117
+ ]
118
+ )
119
+
120
+ # Access the response content correctly
121
+ return( response.choices[0].message.content if response.choices and response.choices[0].message else "No timetable generated.")
122
+
123
+ def cluster_topics(academic_topics):
124
+ prompt = (
125
+ "Please cluster the following academic topics into their respective subjects such as Mathematics, Physics, etc.: "
126
+ + ", ".join(academic_topics))
127
+ response = ""
128
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
129
+ model="tiiuae/falcon-180b-chat",
130
+ messages=[
131
+ {"role": "system", "content": "You are a helpful assistant."},
132
+ {"role": "user", "content": prompt},
133
+ ],
134
+ stream=True,
135
+ ):
136
+ if chunk.choices[0].delta.content:
137
+ response += chunk.choices[0].delta.content
138
+ return response
139
+
140
+ def generate_timetable_weak(clustered_subjects, hours_per_day):
141
+ prompt = (
142
+ f"Using the following subjects and topics:\n{clustered_subjects}\n"
143
+ f"Generate a special class timetable for {hours_per_day} hours per day.\n"
144
+ f"Also provide reference books and methods to teach the slow learners for each subject"
145
+ )
146
+ response = ""
147
+ for chunk in AI71(AI71_API_KEY).chat.completions.create(
148
+ model="tiiuae/falcon-180b-chat",
149
+ messages=[
150
+ {"role": "system", "content": "You are a helpful assistant."},
151
+ {"role": "user", "content": prompt},
152
+ ],
153
+ stream=True,
154
+ ):
155
+ if chunk.choices[0].delta.content:
156
+ response += chunk.choices[0].delta.content
157
+ return response
158
+