liamgh commited on
Commit
e38f98d
·
verified ·
1 Parent(s): 538ddcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -5,6 +5,7 @@ import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  from urllib.parse import quote
 
8
 
9
  from Gradio_UI import GradioUI
10
 
@@ -16,7 +17,19 @@ def get_books_for_subject(subject:str, published_in:str)-> str:
16
  published_in: A date range for the publication of the book (e.g. "1500-1600", "1980-1989", "")
17
  """
18
  r = requests.get("https://openlibrary.org/subjects/%s.json?published_in=%s" % (quote(subject), quote(published_in)))
19
- return r.json()
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  from urllib.parse import quote
8
+ import json
9
 
10
  from Gradio_UI import GradioUI
11
 
 
17
  published_in: A date range for the publication of the book (e.g. "1500-1600", "1980-1989", "")
18
  """
19
  r = requests.get("https://openlibrary.org/subjects/%s.json?published_in=%s" % (quote(subject), quote(published_in)))
20
+ results = r.json()
21
+ books = []
22
+ for work in results["works"]:
23
+ book = {}
24
+ book["title"] = work["title"]
25
+ book["year"] = work["first_publish_year"]
26
+ authors = []
27
+ for author in work["authors"]:
28
+ authors.append(author["name"])
29
+ book["authors"] = authors
30
+ book["link"] = "https://openlibrary.org" + work["key"]
31
+ books.append(book)
32
+ return json.dumps(books)
33
 
34
  @tool
35
  def get_current_time_in_timezone(timezone: str) -> str: