minor changes

This commit is contained in:
isaac hershenson
2024-06-16 09:49:13 -07:00
parent 248c75411c
commit 06cecfac0e
3 changed files with 52 additions and 22 deletions
-22
View File
@@ -29,26 +29,6 @@ class Chapter(TypedDict):
number: int
content: str
title: str
'''
def update_chapters(left, right):
# coerce to list
if not isinstance(left, list):
left = [left]
if not isinstance(right, list):
right = [right]
if len(right) != 1:
raise ValueError
if len(left) == 0:
return right
chapter = right[0]
merged = left.copy()
if left[-1]['number'] == chapter['number']:
merged[-1] = chapter
else:
merged.append(chapter)
return merged
'''
def update_all_chapters(previous_chapters, new_chapter):
new_chapter = new_chapter[list(new_chapter.keys())[0]][0]
@@ -179,7 +159,6 @@ def summarize_current_story(state):
return summary_chain.invoke({"chapters_str": chapters_str})
def edit_chapter(state):
print(f"CURRENT_CHAPTER: {state['currently_selected_chapter']}")
chapters_summary = summarize_current_story(state)
user_message = edit_prompt.format(
chapters_summary=chapters_summary,
@@ -204,7 +183,6 @@ def continue_chapter(state):
prompt = instructions.format(summary=state['summary'], details=state['details'], style=state['style'])
response = llm.invoke([{"role": "system", "content": prompt}, {"role": "user", "content": user_message}])
chapter, chapter_title = parse(response.content)
print(int(state['currently_selected_chapter']) + 1)
len_of_chapters_num_n = len(state['all_chapters'][str(int(state['currently_selected_chapter'])+1)]) if str(int(state['currently_selected_chapter'])+1) in state['all_chapters'] else 0
return {"all_chapters": {str(int(state['currently_selected_chapter']) + 1):[{"number": int(state['currently_selected_chapter']) + 1, "content": chapter, "title": chapter_title}]}, \
"current_chapter_indices":{str(int(state['currently_selected_chapter']) + 1):len_of_chapters_num_n} , "currently_selected_chapter": str(int(state['currently_selected_chapter'])+1), \
+19
View File
@@ -0,0 +1,19 @@
def transform_titles_into_options(titles):
name_counts = {}
for name in set(titles):
name_counts[name] = titles.count(name)
# Transform names with numbered suffixes
transformed_titles = []
for name in titles[::-1]:
count = name_counts[name]
if count > 1 or titles.count(name) > 1:
transformed_titles.append(f"{name} #{count}")
else:
transformed_titles.append(name)
name_counts[name] -= 1
return transformed_titles[::-1]
print(transform_titles_into_options(['a','b','a','c']))
+33
View File
@@ -0,0 +1,33 @@
import streamlit as st
from streamlit import components
def main():
# Define your options
options = ['Option 1', 'Option 2', 'Option 3']
# Initialize session state variable
if 'selected_option' not in st.session_state:
st.session_state.selected_option = None
st.session_state.num_selected = 0
# Create a selectbox with a placeholder
st.session_state.selected_option = st.selectbox("", \
options=options, index=None,placeholder="Choose an option", \
key=f"selectbox-{st.session_state.num_selected}")
# React to option selection
if st.session_state.selected_option is not None:
print(st.session_state.selected_option, st.session_state.num_selected)
st.session_state.num_selected += 1
# Reset the selected option to None
#st.session_state.selected_option = None
st.rerun()
if __name__ == "__main__":
main()