Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,9 +84,41 @@ def word_lookup(text, query, exceptions=exceptions):
|
|
| 84 |
# Return the count of matching sequences
|
| 85 |
return len(matching_sequences)
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
|
|
|
| 90 |
query = query.lower()
|
| 91 |
max_score = 0
|
| 92 |
best_match = None
|
|
@@ -100,30 +132,15 @@ def answer_lecturer_query(query):
|
|
| 100 |
max_score = score
|
| 101 |
best_match = row
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
# Process specific requests for phone number or office
|
| 109 |
-
if "phone number" in query or "number" in query:
|
| 110 |
-
if best_match['phone_number']:
|
| 111 |
-
return f"Sure! {best_match['name']} the {best_match['course']} ({best_match['course_code']}) lecturer's phone number is {best_match['phone_number']}."
|
| 112 |
else:
|
| 113 |
-
return
|
| 114 |
-
elif "office" in query:
|
| 115 |
-
if best_match['office'] == "No longer in Babcock":
|
| 116 |
-
return f"Oops! {best_match['name']} the {best_match['course']} ({best_match['course_code']}) lecturer is {best_match['office']}."
|
| 117 |
-
elif best_match['office']:
|
| 118 |
-
return f"Sure thing! {best_match['name']} the {best_match['course']} ({best_match['course_code']}) lecturer's office is at {best_match['office']}."
|
| 119 |
-
else:
|
| 120 |
-
return f"Sorry, I seem to have forgotten the office of that lecturer."
|
| 121 |
-
elif "lecturer" in query or "who" in query:
|
| 122 |
-
return f"{best_match['name']} is the {best_match['course']} ({best_match['course_code']}) lecturer."
|
| 123 |
-
elif "code" in query:
|
| 124 |
-
return f"The course code for {best_match['course']} is {best_match['course_code']}"
|
| 125 |
else:
|
| 126 |
-
return
|
| 127 |
else:
|
| 128 |
return answer_general_query(query)
|
| 129 |
|
|
@@ -132,7 +149,7 @@ def answer_doc_link_query(query):
|
|
| 132 |
max_score = 0
|
| 133 |
best_match = None
|
| 134 |
|
| 135 |
-
school_files = ["past questions", "pq", "pstq", "slides for"]
|
| 136 |
study_smarter = ["flashcards", "study set", "study", "study app", "study link", "slides", "today", "class", "lecturer"]
|
| 137 |
|
| 138 |
for index, row in doc_link_data.iterrows():
|
|
@@ -171,7 +188,7 @@ def answer_doc_link_query(query):
|
|
| 171 |
def get_intent(query):
|
| 172 |
# Define keywords or phrases associated with each intent
|
| 173 |
lecturer_keywords = ["lecturer", "lecturer's" "phone number", "number", "office", "who", "code", "course", "name"]
|
| 174 |
-
doc_link_keywords = ["past questions", "pstq", "study materials", "flashcards", "studysmarter",
|
| 175 |
"study smarter", "slides", "slide", "pdf"]
|
| 176 |
unknown_keywords = ["email", "missed", "write"]
|
| 177 |
|
|
@@ -186,10 +203,6 @@ def get_intent(query):
|
|
| 186 |
else:
|
| 187 |
return "general"
|
| 188 |
|
| 189 |
-
# Define variables to track the previous query and response
|
| 190 |
-
previous_query = ""
|
| 191 |
-
previous_response = ""
|
| 192 |
-
|
| 193 |
|
| 194 |
def get_response(query):
|
| 195 |
|
|
|
|
| 84 |
# Return the count of matching sequences
|
| 85 |
return len(matching_sequences)
|
| 86 |
|
| 87 |
+
def get_phone_number_response(best_match):
|
| 88 |
+
if best_match['phone_number']:
|
| 89 |
+
return f"Sure! {best_match['name']} the {best_match['course']} ({best_match['course_code']}) lecturer's phone number is {best_match['phone_number']}."
|
| 90 |
+
else:
|
| 91 |
+
return "Sorry, the phone number is not available."
|
| 92 |
+
|
| 93 |
+
def get_office_response(best_match):
|
| 94 |
+
if best_match['office'] == "No longer in Babcock":
|
| 95 |
+
return f"Oops! {best_match['name']} the {best_match['course']} ({best_match['course_code']}) lecturer is {best_match['office']}."
|
| 96 |
+
elif best_match['office']:
|
| 97 |
+
return f"Sure thing! {best_match['name']} the {best_match['course']} ({best_match['course_code']}) lecturer's office is at {best_match['office']}."
|
| 98 |
+
else:
|
| 99 |
+
return "Sorry, the office location is not available."
|
| 100 |
+
|
| 101 |
+
def get_basic_info_response(query, best_match):
|
| 102 |
+
if "code" in query:
|
| 103 |
+
return f"The course code for {best_match['course']} is {best_match['course_code']}"
|
| 104 |
+
else:
|
| 105 |
+
return f"{best_match['name']} is the {best_match['course']} ({best_match['course_code']}) lecturer."
|
| 106 |
+
|
| 107 |
+
def get_default_response(best_match):
|
| 108 |
+
return f"{best_match['course']} has the course code: {best_match['course_code']}"
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def process_query(query, best_match):
|
| 112 |
+
if "phone number" in query or "number" in query:
|
| 113 |
+
return get_phone_number_response(best_match)
|
| 114 |
+
elif "office" in query:
|
| 115 |
+
return get_office_response(best_match)
|
| 116 |
+
elif any(word in query for word in ["lecturer", "who", "code"]):
|
| 117 |
+
return get_basic_info_response(query, best_match)
|
| 118 |
+
else:
|
| 119 |
+
return get_default_response(best_match)
|
| 120 |
|
| 121 |
+
def answer_lecturer_query(query):
|
| 122 |
query = query.lower()
|
| 123 |
max_score = 0
|
| 124 |
best_match = None
|
|
|
|
| 132 |
max_score = score
|
| 133 |
best_match = row
|
| 134 |
|
| 135 |
+
if max_score >= 1:
|
| 136 |
+
if any(word in query for word in ["cosc", "geds", "ged"]):
|
| 137 |
+
query_course_code = next((word for word in query.split() if word.startswith("cosc") or word.startswith("geds") or word.startswith("ged")), None)
|
| 138 |
+
if query_course_code and query_course_code.upper() in best_match['course_code']:
|
| 139 |
+
return process_query(query, best_match)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
else:
|
| 141 |
+
return "Sorry, I couldn't find info about the course you've mentioned."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
else:
|
| 143 |
+
return process_query(query, best_match)
|
| 144 |
else:
|
| 145 |
return answer_general_query(query)
|
| 146 |
|
|
|
|
| 149 |
max_score = 0
|
| 150 |
best_match = None
|
| 151 |
|
| 152 |
+
school_files = ["past questions", "pst questions", "pq", "pstq", "slides for"]
|
| 153 |
study_smarter = ["flashcards", "study set", "study", "study app", "study link", "slides", "today", "class", "lecturer"]
|
| 154 |
|
| 155 |
for index, row in doc_link_data.iterrows():
|
|
|
|
| 188 |
def get_intent(query):
|
| 189 |
# Define keywords or phrases associated with each intent
|
| 190 |
lecturer_keywords = ["lecturer", "lecturer's" "phone number", "number", "office", "who", "code", "course", "name"]
|
| 191 |
+
doc_link_keywords = ["past questions", "pstq", "pq", "pst", "study materials", "flashcards", "studysmarter",
|
| 192 |
"study smarter", "slides", "slide", "pdf"]
|
| 193 |
unknown_keywords = ["email", "missed", "write"]
|
| 194 |
|
|
|
|
| 203 |
else:
|
| 204 |
return "general"
|
| 205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
def get_response(query):
|
| 208 |
|