Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import json
|
|
5 |
import markdown
|
6 |
from bardapi import BardAsync
|
7 |
from telegraph import Telegraph
|
8 |
-
|
9 |
# Set up the Telegraph client
|
10 |
telegraph = Telegraph()
|
11 |
telegraph.create_account(short_name='BookGPT')
|
@@ -62,13 +62,25 @@ async def generate_predictions(book_name, author, language_choice, detail_option
|
|
62 |
details = ""
|
63 |
for option in detail_options:
|
64 |
query_template = detail_queries.get(option).format(book_name=book_name, author=author) + ' Rule 1: Output answer in in {language_choice} language.'
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
summary = await fetch_summary(book_name, author, language_choice)
|
69 |
combined_summary = summary["content"] + details
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
72 |
|
73 |
return image_links, combined_summary, telegraph_url
|
74 |
|
|
|
5 |
import markdown
|
6 |
from bardapi import BardAsync
|
7 |
from telegraph import Telegraph
|
8 |
+
import time
|
9 |
# Set up the Telegraph client
|
10 |
telegraph = Telegraph()
|
11 |
telegraph.create_account(short_name='BookGPT')
|
|
|
62 |
details = ""
|
63 |
for option in detail_options:
|
64 |
query_template = detail_queries.get(option).format(book_name=book_name, author=author) + ' Rule 1: Output answer in in {language_choice} language.'
|
65 |
+
try:
|
66 |
+
response = await bard.get_answer(query_template)
|
67 |
+
details += f"\n\n**{option}**:\n{response['content']}"
|
68 |
+
except:
|
69 |
+
time.sleep(20)
|
70 |
+
try:
|
71 |
+
response = await bard.get_answer(query_template)
|
72 |
+
details += f"\n\n**{option}**:\n{response['content']}"
|
73 |
+
except:
|
74 |
+
pass
|
75 |
+
|
76 |
|
77 |
summary = await fetch_summary(book_name, author, language_choice)
|
78 |
combined_summary = summary["content"] + details
|
79 |
+
try:
|
80 |
+
telegraph_url = post_to_telegraph(f"Summary of {book_name} by {author}", combined_summary)
|
81 |
+
except requests.exceptions.ConnectionError:
|
82 |
+
telegraph_url = "Error connecting to Telegraph API"
|
83 |
+
|
84 |
|
85 |
return image_links, combined_summary, telegraph_url
|
86 |
|