Update app.py
Browse files
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
|
16 |
-
the course name and
|
17 |
|
18 |
-
You're tasked to use the description of each course and compare it with the user input
|
19 |
-
description matches the user requirement.
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Database
|
24 |
{database_str}
|
@@ -26,11 +29,12 @@ def generate_response(query):
|
|
26 |
# User Input
|
27 |
{query}
|
28 |
|
29 |
-
# Output
|
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
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")
|