Update app.py
Browse files
app.py
CHANGED
|
@@ -14,20 +14,23 @@ def search_books(ques, max_givenbooks = 5):
|
|
| 14 |
else:
|
| 15 |
return ""
|
| 16 |
ques = str(ques).lower()
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
if matched_books.empty:
|
| 25 |
return "No exact matches found in the catalog for this description."
|
| 26 |
-
|
| 27 |
for idx, row in matched_books.iterrows():
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
return
|
| 31 |
def respond(message, history):
|
| 32 |
catalog_info = search_books(message)
|
| 33 |
|
|
@@ -46,6 +49,11 @@ def respond(message, history):
|
|
| 46 |
|
| 47 |
return response.choices[0].message.content.strip()
|
| 48 |
|
| 49 |
-
chatbot = gr.ChatInterface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
chatbot.launch()
|
|
|
|
| 14 |
else:
|
| 15 |
return ""
|
| 16 |
ques = str(ques).lower()
|
| 17 |
+
matches = pd.Series(False, index=books.index)
|
| 18 |
|
| 19 |
+
for word in keywords:
|
| 20 |
+
matches = matches | (
|
| 21 |
+
books["Title"].str.lower().str.contains(word, na=False) |
|
| 22 |
+
books["Genre"].str.lower().str.contains(word, na=False) |
|
| 23 |
+
books["Description"].str.lower().str.contains(word, na=False)
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
matched_books = books[matches].head(max_givenbooks)
|
| 27 |
if matched_books.empty:
|
| 28 |
return "No exact matches found in the catalog for this description."
|
| 29 |
+
results_in = "Available books in our catalog matching your request:\n"
|
| 30 |
for idx, row in matched_books.iterrows():
|
| 31 |
+
results_in += f" - **Title** : {row['Title']} | **Author** : {row['Author']} | **Genre** : {row['Genre']} | **Age** : {row['Age_Range']}\n"
|
| 32 |
+
results_in += f" *Description* : {row['Description']}\n\n"
|
| 33 |
+
return results_in
|
| 34 |
def respond(message, history):
|
| 35 |
catalog_info = search_books(message)
|
| 36 |
|
|
|
|
| 49 |
|
| 50 |
return response.choices[0].message.content.strip()
|
| 51 |
|
| 52 |
+
chatbot = gr.ChatInterface(
|
| 53 |
+
fn=respond,
|
| 54 |
+
type="messages",
|
| 55 |
+
title="BookBuddy",
|
| 56 |
+
description="Ask me for book recommendation on genre, age range, or what kind of story you want"
|
| 57 |
+
)
|
| 58 |
|
| 59 |
chatbot.launch()
|