bertugmirasyedi commited on
Commit
fff9411
1 Parent(s): 12bc706

Added logic to not include chatgpt results in case of a rate limit.

Browse files
Files changed (1) hide show
  1. app.py +17 -11
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
- # Parse the result
142
- parsed_result = parse_result(result, ordered_keys=ordered_keys)
143
-
144
- # Append the parsed result to the lists
145
- titles.append(parsed_result["Title"])
146
- authors.append(parsed_result["Author"])
147
- publishers.append(parsed_result["Publisher"])
148
- descriptions.append(parsed_result["Summary"])
149
- images.append(
150
- "https://bookstoreromanceday.org/wp-content/uploads/2020/08/book-cover-placeholder.png"
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 (