Skip to content

Commit

Permalink
Add one-time heading on first page
Browse files Browse the repository at this point in the history
  • Loading branch information
Soumya Snigdha Kundu authored and Soumya Snigdha Kundu committed Oct 6, 2024
1 parent 2e75638 commit ae22807
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 57 deletions.
Binary file modified __pycache__/calls.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/front.cpython-310.pyc
Binary file not shown.
Binary file modified __pycache__/utils.cpython-310.pyc
Binary file not shown.
20 changes: 17 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import streamlit as st

from utils import display_image, replace_current_url, navigation_controls, display_responses
from utils import apply_styles, initialize_state
from utils import display_image, replace_current_url, initialize_state, display_responses
from front import apply_styles, navigation_controls
from calls import generate_poem_workflow

def main():

apply_styles()
initialize_state()

page_index = st.session_state.get('page_index', 0)

# Initialize heading_shown in session state if not present
if 'heading_shown' not in st.session_state:
st.session_state.heading_shown = False

# Display heading only on the first page and if it hasn't been shown yet
if page_index == 0 and not st.session_state.heading_shown:
st.markdown("<h1 class='heading'>Co-author: The multi-modal copilot for novelists</h1>", unsafe_allow_html=True)
st.session_state.heading_shown = True

# Move the Replace URL button and functionality to the top
replace_current_url()

Expand All @@ -22,5 +30,11 @@ def main():
display_responses()
navigation_controls(page_index)

# Add a refresh button to reset the heading
if st.button('Refresh'):
st.session_state.heading_shown = False
st.session_state.page_index = 0
st.rerun()

if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def _generate_poem(concept, theme, url):
f"""
Write a haiku about this image using the
<concept> and common <theme> below. Do NOT use
explicit words related to the <theme>.
explicit words related to the <theme>. Try not to
use the concept and theme word but convey them.
Previous context:
{previous_context}
Expand Down
68 changes: 68 additions & 0 deletions front.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import streamlit as st

from utils import URLS

def apply_styles():
st.markdown(
"""
<style>
html, body, [class*="css"] {
margin: 0;
padding: 0;
overflow-y: hidden !important;
}
.stApp {
max-width: 350px;
margin: 0 auto;
text-align: center;
}
.stImage {
display: block;
margin-left: auto;
margin-right: auto;
max-height: 30vh;
width: auto;
}
.stButton > button {
display: inline-block;
margin: 0 15px; /* Add some margin between buttons */
}
.main .block-container {
padding-top: 1rem;
padding-bottom: 1rem;
}
/* Style for the dropdown */
.stSelectbox {
max-width: 200px;
margin: 0 auto 10px;
}
/* Container for buttons */
.button-container {
display: flex;
justify-content: center;
align-items: center;
margin-top: 10px;
}
/* Style for the heading */
.heading {
font-size: 24px;
font-weight: bold;
color: #4A4A4A;
margin-bottom: 20px;
}
</style>
""", unsafe_allow_html=True
)

def navigation_controls(page_index):
col1, col2, col3 = st.columns([1, 1, 1])
with col1:
if st.button('Back') and page_index > 0:
st.session_state.page_index = page_index - 1
st.rerun()
with col2:
st.write(f'Page {page_index + 1} of {len(URLS)}')
with col3:
if st.button('Next') and page_index < len(URLS) - 1:
st.session_state.page_index = page_index + 1
st.rerun()
59 changes: 6 additions & 53 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ def display_responses():
for i, response in enumerate(st.session_state.responses):
st.write(f"Page {i + 1}: {response if response else 'No response generated yet.'}")

def navigation_controls(page_index):
col1, col2, col3 = st.columns([1, 1, 1])
with col1:
if st.button('Previous') and page_index > 0:
st.session_state.page_index = page_index - 1
st.rerun()
with col2:
st.write(f'Page {page_index + 1} of {len(URLS)}')
with col3:
if st.button('Next') and page_index < len(URLS) - 1:
st.session_state.page_index = page_index + 1
st.rerun()
def initialize_state():
if 'responses' not in st.session_state:
st.session_state.responses = [None] * len(URLS)
if 'is_first_global_generation' not in st.session_state:
st.session_state.is_first_global_generation = True

def _load_image_as_base64(file_path):
with open(file_path, "rb") as image_file:
Expand Down Expand Up @@ -55,44 +48,4 @@ def replace_current_url():
]

if 'responses' not in st.session_state:
st.session_state.responses = [None] * len(URLS)

def apply_styles():

st.markdown(
"""
<style>
html, body, [class*="css"] {
margin: 0;
padding: 0;
overflow-y: hidden !important;
}
.stApp {
max-width: 350px;
margin: 0 auto;
text-align: center;
}
.stImage {
display: block;
margin-left: auto;
margin-right: auto;
max-height: 30vh;
width: auto;
}
.stButton > button {
display: inline-block;
}
.main .block-container {
padding-top: 1rem;
padding-bottom: 1rem;
}
</style>
""", unsafe_allow_html=True
)

def initialize_state():

if 'responses' not in st.session_state:
st.session_state.responses = [None] * len(URLS)
if 'is_first_global_generation' not in st.session_state:
st.session_state.is_first_global_generation = True
st.session_state.responses = [None] * len(URLS)

0 comments on commit ae22807

Please sign in to comment.