edithram23 commited on
Commit
b9e11c1
·
verified ·
1 Parent(s): 4b41cf9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -14
app.py CHANGED
@@ -9,16 +9,19 @@ database_str=''
9
  with open('data_base.txt', 'r',encoding='utf-8') as f:
10
  database_str = f.read()
11
 
12
-
13
  def generate_response(query):
14
  prompt = f'''
15
- You are a Course suggestor based on the user requirement and the from the given database which consist of
16
- the course name and description of the course.
17
 
18
- You're tasked to use the description of each course and compare it with the user input and output which course's
19
- description matches the user requirement.
20
- Output the course name & Course Link alone which matches the user requirement.
21
- you may output a max of 3 courses if you find that are good matches. name of the course should be exactly same as the database provided to you along with its link provided
 
 
 
 
22
 
23
  # Database
24
  {database_str}
@@ -26,11 +29,12 @@ def generate_response(query):
26
  # User Input
27
  {query}
28
 
29
- # Output : Course Name||Coure LINK \ Course Name||Course LINK \....
30
  '''
31
  model = genai.GenerativeModel("gemini-1.5-flash")
32
  response = model.generate_content(prompt)
33
- return response.text.split("\\")
 
34
 
35
 
36
  # Define session state variables
@@ -63,9 +67,21 @@ for message in st.session_state.messages:
63
  st.write(message['content'])
64
  else:
65
  with st.chat_message("ai"):
66
- for i in message['content']:
67
- name = i.split('||')[0]
68
- link = i.split("||")[1]
69
- st.markdown(f"[{name}]({link})", unsafe_allow_html=True)
 
 
 
 
 
 
 
70
 
71
-
 
 
 
 
 
 
9
  with open('data_base.txt', 'r',encoding='utf-8') as f:
10
  database_str = f.read()
11
 
 
12
  def generate_response(query):
13
  prompt = f'''
14
+ You are a Course suggestor based on the user requirement and the given database, which consists of
15
+ the course name, description, and link to each course.
16
 
17
+ You're tasked to use the description of each course and compare it with the user input, then output the courses
18
+ whose description matches the user requirement.
19
+
20
+ Strictly output the course name and its corresponding link, following the exact format below:
21
+ - Output a maximum of 3 courses if they match well.
22
+ - The format should be exactly: Course Name || Course Link
23
+ - Each course should be on a new line.
24
+ - No extra text or commentary, only the exact output format specified.
25
 
26
  # Database
27
  {database_str}
 
29
  # User Input
30
  {query}
31
 
32
+ # Output (maximum of 3 courses):
33
  '''
34
  model = genai.GenerativeModel("gemini-1.5-flash")
35
  response = model.generate_content(prompt)
36
+ return response.text.strip().split("\n")
37
+
38
 
39
 
40
  # Define session state variables
 
67
  st.write(message['content'])
68
  else:
69
  with st.chat_message("ai"):
70
+ for item in message['content']:
71
+ # Skip if the item is empty
72
+ if not item.strip():
73
+ continue
74
+
75
+ # Attempt to split the item by '||'
76
+ try:
77
+ name, link = item.split('||')
78
+ # Strip any extra whitespace
79
+ name = name.strip()
80
+ link = link.strip()
81
 
82
+ # Display as markdown with link
83
+ st.markdown(f"[{name}]({link})", unsafe_allow_html=True)
84
+ except ValueError:
85
+ # If the item does not match the expected format, provide a warning message
86
+ # st.write("Warning: Unable to parse the course recommendation properly.")
87
+ print("Warning")