|
|
|
from flask import Flask, request, jsonify |
|
|
|
device = "cuda" |
|
|
|
from ctransformers import AutoModelForCausalLM |
|
|
|
llm = AutoModelForCausalLM.from_pretrained("TheBloke/Mistral-7B-v0.1-GGUF", model_file="mistral-7b-v0.1.Q4_K_M.gguf", model_type="mistral", gpu_layers=00) |
|
|
|
app = Flask(__name__) |
|
|
|
file_path = "mentor.txt" |
|
with open(file_path, "r") as file: |
|
mentors_data = file.read() |
|
|
|
@app.route('/') |
|
def home(): |
|
return jsonify({"message": "Welcome to the Recommendation API!"}) |
|
|
|
@app.route('/recommend', methods=['POST']) |
|
def recommendation(): |
|
content = request.json |
|
user_degree = content.get('degree') |
|
user_stream = content.get('stream') |
|
user_semester = content.get('semester') |
|
prompt = """ |
|
You need to act like as recommendataion engine for course recommendation for student based on below details. |
|
|
|
Degree: {user_degree} |
|
Stream: {user_stream} |
|
Current Semester: {user_semester} |
|
|
|
|
|
Based on above details recommend the courses that realtes to above details |
|
Note: Output should bevalid json format in below format: |
|
{{"course1:ABC,course2:DEF,course3:XYZ,...}} |
|
|
|
""" |
|
suffix="[/INST]" |
|
prefix="[INST] <<SYS>> You are a helpful assistant <</SYS>>" |
|
prompt = f"{prefix}{user.replace('{prompt}', prompt)}{suffix}" |
|
return jsonify({"ans":llm(prompt)}) |
|
|
|
|
|
@app.route('/get_mentor', methods=['POST']) |
|
def mentor(): |
|
content = request.json |
|
user_degree = content.get('degree') |
|
user_stream = content.get('stream') |
|
user_semester = content.get('semester') |
|
courses = content.get('courses') |
|
prompt = f""" |
|
You need to act like as recommendataion engine for mentor recommendation for student based on below details also the list of mentors with their experience is attached. |
|
|
|
Degree: {user_degree} |
|
Stream: {user_stream} |
|
Current Semester: {user_semester} |
|
courses opted:{courses} |
|
|
|
Mentor list= {mentors_data} |
|
Based on above details recommend the mentor that realtes to above details |
|
Note: Output should bevalid json format in below format: |
|
{{"mentor1:ABC,mentor2:DEF,mentor3:XYZ,...}} |
|
|
|
""" |
|
suffix="[/INST]" |
|
prefix="[INST] <<SYS>> You are a helpful assistant <</SYS>>" |
|
prompt = f"{prefix}{user.replace('{prompt}', prompt)}{suffix}" |
|
return jsonify({"ans":llm(prompt)}) |
|
|
|
if __name__ == '__main__': |
|
app.run(debug=True) |