Spaces:
Sleeping
Sleeping
Commit
·
fff9411
1
Parent(s):
12bc706
Added logic to not include chatgpt results in case of a rate limit.
Browse files
app.py
CHANGED
|
@@ -138,17 +138,23 @@ def search(query, similarity=False):
|
|
| 138 |
ordered_keys = ["Title", "Author", "Publisher", "Summary"]
|
| 139 |
|
| 140 |
for result in chatgpt_results:
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
### Prediction ###
|
| 154 |
from transformers import (
|
|
|
|
| 138 |
ordered_keys = ["Title", "Author", "Publisher", "Summary"]
|
| 139 |
|
| 140 |
for result in chatgpt_results:
|
| 141 |
+
try:
|
| 142 |
+
# Parse the result
|
| 143 |
+
parsed_result = parse_result(result, ordered_keys=ordered_keys)
|
| 144 |
+
|
| 145 |
+
# Append the parsed result to the lists
|
| 146 |
+
titles.append(parsed_result["Title"])
|
| 147 |
+
authors.append(parsed_result["Author"])
|
| 148 |
+
publishers.append(parsed_result["Publisher"])
|
| 149 |
+
descriptions.append(parsed_result["Summary"])
|
| 150 |
+
images.append(
|
| 151 |
+
"https://bookstoreromanceday.org/wp-content/uploads/2020/08/book-cover-placeholder.png"
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
# In case the OpenAI API hits the limit
|
| 155 |
+
except IndexError:
|
| 156 |
+
break
|
| 157 |
+
|
| 158 |
|
| 159 |
### Prediction ###
|
| 160 |
from transformers import (
|