Update main.py
Browse files
main.py
CHANGED
|
@@ -3,9 +3,10 @@ from flask import Flask, request, jsonify
|
|
| 3 |
|
| 4 |
device = "cuda" # the device to load the model onto
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
|
| 8 |
-
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
|
| 9 |
|
| 10 |
|
| 11 |
|
|
@@ -15,8 +16,7 @@ def recommendation():
|
|
| 15 |
user_degree = content.get('degree')
|
| 16 |
user_stream = content.get('stream')
|
| 17 |
user_semester = content.get('semester')
|
| 18 |
-
|
| 19 |
-
{"role": "user", "content": f"""
|
| 20 |
You need to act like as recommendataion engine for course recommendation based on below details.
|
| 21 |
|
| 22 |
Degree: {user_degree}
|
|
@@ -28,18 +28,11 @@ def recommendation():
|
|
| 28 |
Note: Output should bevalid json format in below format:
|
| 29 |
{{"course1:ABC,course2:DEF,course3:XYZ,...}}
|
| 30 |
|
| 31 |
-
"""
|
| 32 |
-
|
| 33 |
-
]
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
model_inputs = encodeds.to(device)
|
| 38 |
-
model.to(device)
|
| 39 |
-
|
| 40 |
-
generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True)
|
| 41 |
-
decoded = tokenizer.batch_decode(generated_ids)
|
| 42 |
-
return jsonify({"res":decoded[0]})
|
| 43 |
|
| 44 |
if __name__ == '__main__':
|
| 45 |
app.run(debug=True)
|
|
|
|
| 3 |
|
| 4 |
device = "cuda" # the device to load the model onto
|
| 5 |
|
| 6 |
+
from ctransformers import AutoModelForCausalLM
|
| 7 |
+
|
| 8 |
+
llm = AutoModelForCausalLM.from_pretrained("TheBloke/Llama-2-7b-Chat-GGUF", model_file="llama-2-7b-chat.q4_K_M.gguf", model_type="llama", gpu_layers=0)
|
| 9 |
|
|
|
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
|
|
|
|
| 16 |
user_degree = content.get('degree')
|
| 17 |
user_stream = content.get('stream')
|
| 18 |
user_semester = content.get('semester')
|
| 19 |
+
prompt = """
|
|
|
|
| 20 |
You need to act like as recommendataion engine for course recommendation based on below details.
|
| 21 |
|
| 22 |
Degree: {user_degree}
|
|
|
|
| 28 |
Note: Output should bevalid json format in below format:
|
| 29 |
{{"course1:ABC,course2:DEF,course3:XYZ,...}}
|
| 30 |
|
| 31 |
+
"""
|
| 32 |
+
suffix="[/INST]"
|
| 33 |
+
prefix="[INST] <<SYS>> You are a helpful assistant <</SYS>>"
|
| 34 |
+
prompt = f"{prefix}{user.replace('{prompt}', prompt)}{suffix}"
|
| 35 |
+
return jsonify({"ans":llm(prompt)})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
if __name__ == '__main__':
|
| 38 |
app.run(debug=True)
|