|
|
| 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.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 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)}) |
|
|
| if __name__ == '__main__': |
| app.run(debug=True) |