AnnNaser commited on
Commit
900ce79
·
verified ·
1 Parent(s): 18a6316

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -1,7 +1,8 @@
1
  import streamlit as st
2
  import requests
3
- import pandas as pd
4
  from bs4 import BeautifulSoup
 
 
5
 
6
  # Predefined list of top 100 subjects (you can expand or modify this list)
7
  top_subjects = [
@@ -76,6 +77,16 @@ def fetch_books(subjects, time_frame):
76
 
77
  return books_data
78
 
 
 
 
 
 
 
 
 
 
 
79
  # Streamlit UI
80
  def main():
81
  st.title('Book Finder Based on Subject and Time Frame')
@@ -99,7 +110,9 @@ def main():
99
 
100
  with col1:
101
  if book['Book Cover'] != 'N/A':
102
- st.image(book['Book Cover'], caption=book['Title'], width=150)
 
 
103
  else:
104
  st.write("No cover image available")
105
 
@@ -110,7 +123,9 @@ def main():
110
  st.markdown(f"**Description:** {book['Description']}")
111
 
112
  if book['Author Image'] != 'N/A':
113
- st.image(book['Author Image'], caption=f"Author: {book['Authors']}", width=100)
 
 
114
  else:
115
  st.write("No author image available")
116
 
 
1
  import streamlit as st
2
  import requests
 
3
  from bs4 import BeautifulSoup
4
+ from PIL import Image
5
+ from io import BytesIO
6
 
7
  # Predefined list of top 100 subjects (you can expand or modify this list)
8
  top_subjects = [
 
77
 
78
  return books_data
79
 
80
+ # Function to download an image from a URL
81
+ def download_image(url):
82
+ try:
83
+ response = requests.get(url)
84
+ response.raise_for_status()
85
+ return Image.open(BytesIO(response.content))
86
+ except Exception as e:
87
+ st.error(f"Error downloading image from {url}: {e}")
88
+ return None
89
+
90
  # Streamlit UI
91
  def main():
92
  st.title('Book Finder Based on Subject and Time Frame')
 
110
 
111
  with col1:
112
  if book['Book Cover'] != 'N/A':
113
+ book_cover_image = download_image(book['Book Cover'])
114
+ if book_cover_image:
115
+ st.image(book_cover_image, caption=book['Title'], width=150)
116
  else:
117
  st.write("No cover image available")
118
 
 
123
  st.markdown(f"**Description:** {book['Description']}")
124
 
125
  if book['Author Image'] != 'N/A':
126
+ author_image = download_image(book['Author Image'])
127
+ if author_image:
128
+ st.image(author_image, caption=f"Author: {book['Authors']}", width=100)
129
  else:
130
  st.write("No author image available")
131