darshan8950 commited on
Commit
e60d9fc
·
verified ·
1 Parent(s): 772d03e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +38 -43
main.py CHANGED
@@ -26,49 +26,44 @@ def format_prompt(message):
26
 
27
  @app.route('/get_course', methods=['POST'])
28
  def recommend():
29
- temperature=0.9
30
- max_new_tokens=256
31
- top_p=0.95
32
- repetition_penalty=1.0
33
- content = request.json
34
- user_degree = content.get('degree')
35
- user_stream = content.get('stream')
36
- user_semester = content.get('semester')
37
- temperature = float(temperature)
38
- if temperature < 1e-2:
39
- temperature = 1e-2
40
- top_p = float(top_p)
41
-
42
- generate_kwargs = dict(
43
- temperature=temperature,
44
- max_new_tokens=max_new_tokens,
45
- top_p=top_p,
46
- repetition_penalty=repetition_penalty,
47
- do_sample=True,
48
- seed=42,
49
- )
50
- prompt = f""" prompt:
51
- You need to act like as recommendataion engine for course recommendation for student based on below details.
52
-
53
- Degree: {user_degree}
54
- Stream: {user_stream}
55
- Current Semester: {user_semester}
56
-
57
-
58
- Based on above details recommend the courses that realtes to above details
59
- Note: Output should bevalid json format in below format:
60
- {{"course1:course_name,course2:course_name,course3:course_name,...}}
61
-
62
- """
63
- formatted_prompt = format_prompt(prompt)
64
-
65
- stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
66
- output = ""
67
-
68
- for response in stream:
69
- output += response.token.text
70
- yield output
71
- return jsonify({"ans":output})
72
 
73
  @app.route('/get_mentor', methods=['POST'])
74
  def mentor():
 
26
 
27
  @app.route('/get_course', methods=['POST'])
28
  def recommend():
29
+ temperature = 0.9
30
+ max_new_tokens = 256
31
+ top_p = 0.95
32
+ repetition_penalty = 1.0
33
+
34
+ if request.method == 'POST':
35
+ content = request.json
36
+ user_degree = content.get('degree')
37
+ user_stream = content.get('stream')
38
+ user_semester = content.get('semester')
39
+
40
+ generate_kwargs = dict(
41
+ temperature=temperature,
42
+ max_new_tokens=max_new_tokens,
43
+ top_p=top_p,
44
+ repetition_penalty=repetition_penalty,
45
+ do_sample=True,
46
+ seed=42,
47
+ )
48
+ prompt = f""" prompt:
49
+ You need to act like as recommendation engine for course recommendation for a student based on below details.
50
+ Degree: {user_degree}
51
+ Stream: {user_stream}
52
+ Current Semester: {user_semester}
53
+ Based on above details recommend the courses that relate to the above details
54
+ Note: Output should be valid json format in below format:
55
+ {{"course1:course_name, course2:course_name, course3:course_name,...}}
56
+ """
57
+ formatted_prompt = format_prompt(prompt)
58
+
59
+ stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
60
+ output = ""
61
+
62
+ for response in stream:
63
+ output += response.token.text
64
+ return jsonify({"ans": output})
65
+ else:
66
+ return jsonify({"error": "Invalid request method"})
 
 
 
 
 
67
 
68
  @app.route('/get_mentor', methods=['POST'])
69
  def mentor():