Skip to content

Commit

Permalink
summarize and start chatting buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
RadCod3 committed Aug 29, 2023
1 parent 1d15142 commit b5ec0f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
39 changes: 35 additions & 4 deletions streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import requests
from utils import search_book
from summarize import get_summary


# App title
Expand All @@ -20,19 +21,40 @@
st.sidebar.title("Babbler 🤖")
st.sidebar.text_input("Search Book", key="book_name_search")

m = st.markdown(
"""
<style>
div.stButton > button:first-child {
color: #ffffff;
background-color: #373a3d;
}
</style>""",
unsafe_allow_html=True,
)

if st.session_state.book_name_search:
book_name = st.session_state.book_name_search
error, book = search_book(book_name)
print(book)
if error:
st.sidebar.error(error)
else:
st.session_state.book = book
st.sidebar.success("Book found: %s" % book["title"])
st.title(book["title"])
language_code = book["languages"][0]
st.write(f"By {book['authors'][0]['name']}")
st.write(f"Language: {language_code}")
if len(book["authors"]) > 0:
st.write(f"By {book['authors'][0]['name']}")
if len(book["languages"]) > 0:
language_code = book["languages"][0]
st.write(f"Language: {language_code}")
st.write(f"Subjects: {', '.join(book['subjects'])}")
col1, col2 = st.columns(2)
with col1:
st.button("Summarize", key="summarize")
with col2:
st.button("Start Chatting", key="start_chatting")


if "message" not in st.session_state:
Expand All @@ -46,7 +68,7 @@

def render_chat():
# Create a layout with columns
col1, col2 = st.columns([1, 5])
col1, col2 = st.columns([1, 8])

# Display chat history in the main column
with col2:
Expand All @@ -67,3 +89,12 @@ def render_chat():
output = "Error: %s" % response.text
st.session_state.message.append({"role": "assistant", "content": output})
st.chat_message("assistant").write(output)


if st.session_state.summarize:
summary = get_summary(st.session_state.book["id"])
st.write(summary)
render_chat()

if st.session_state.start_chatting:
render_chat()
3 changes: 3 additions & 0 deletions summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
import difflib
from bs4 import BeautifulSoup


# code to get summary from summarize model
def get_summary(book_id):
return f"{book_id} lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est laborum"

0 comments on commit b5ec0f0

Please sign in to comment.