Update aAzel.py
Browse files
aAzel.py
CHANGED
@@ -39,66 +39,77 @@ Embrace your persona as a masterful storyteller, capable of crafting captivating
|
|
39 |
def generate_book_component(prompt, previous_output=None):
|
40 |
"""Generates a book component using prompt chaining based on previous output."""
|
41 |
if previous_output:
|
42 |
-
prompt = prompt + "\n\n" + previous_output
|
43 |
response = model.generate_content([author_persona, author_guidelines, prompt])
|
44 |
return response.text
|
45 |
|
|
|
46 |
def main():
|
47 |
st.title("AI Author")
|
48 |
st.header("Write your next bestseller!")
|
49 |
|
50 |
-
#
|
51 |
-
|
|
|
|
|
|
|
52 |
genre = st.selectbox("Choose a Genre:", genres)
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
if st.
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
74 |
for i, chapter in enumerate(chapters):
|
75 |
-
if chapter:
|
76 |
-
st.
|
77 |
|
78 |
# Generate Chapter Format
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
if
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
98 |
st.download_button(
|
99 |
label="Download Book",
|
100 |
-
data=book_content,
|
101 |
-
file_name=f"{
|
102 |
mime="text/plain"
|
103 |
)
|
104 |
|
|
|
39 |
def generate_book_component(prompt, previous_output=None):
|
40 |
"""Generates a book component using prompt chaining based on previous output."""
|
41 |
if previous_output:
|
42 |
+
prompt = prompt + "\n\n" + previous_output
|
43 |
response = model.generate_content([author_persona, author_guidelines, prompt])
|
44 |
return response.text
|
45 |
|
46 |
+
|
47 |
def main():
|
48 |
st.title("AI Author")
|
49 |
st.header("Write your next bestseller!")
|
50 |
|
51 |
+
# Book Information Input
|
52 |
+
book_title = st.text_input("Enter your book title:")
|
53 |
+
genres = ["Science Fiction", "Fantasy", "Mystery", "Thriller", "Romance",
|
54 |
+
"Historical Fiction", "Horror", "Literary Fiction", "Young Adult",
|
55 |
+
"Children's Literature", "Non-Fiction"]
|
56 |
genre = st.selectbox("Choose a Genre:", genres)
|
57 |
+
book_description = st.text_area("Describe your book:",
|
58 |
+
"Enter a detailed description of your book here...")
|
59 |
+
|
60 |
+
# Store book components in session state
|
61 |
+
if 'toc' not in st.session_state:
|
62 |
+
st.session_state.toc = None
|
63 |
+
if 'chapter_formats' not in st.session_state:
|
64 |
+
st.session_state.chapter_formats = {}
|
65 |
+
if 'book_content' not in st.session_state:
|
66 |
+
st.session_state.book_content = ""
|
67 |
+
|
68 |
+
# Generate Table of Contents
|
69 |
+
if st.button("Generate Table of Contents"):
|
70 |
+
if not book_title or not book_description:
|
71 |
+
st.warning("Please enter both the book title and description.")
|
72 |
+
else:
|
73 |
+
prompt = f"Create a detailed Table of Contents for a {genre} book titled '{book_title}' about: {book_description}"
|
74 |
+
st.session_state.toc = generate_book_component(prompt, book_title)
|
75 |
+
st.subheader("Table of Contents:")
|
76 |
+
st.write(st.session_state.toc)
|
77 |
+
|
78 |
+
# Generate Chapter Format and Chapter Content
|
79 |
+
if st.session_state.toc:
|
80 |
+
chapters = st.session_state.toc.split("\n")
|
81 |
for i, chapter in enumerate(chapters):
|
82 |
+
if chapter:
|
83 |
+
st.markdown(f"## Chapter {i+1}: {chapter}")
|
84 |
|
85 |
# Generate Chapter Format
|
86 |
+
if chapter not in st.session_state.chapter_formats:
|
87 |
+
if st.button(f"Generate Format for Chapter {i+1}"):
|
88 |
+
format_prompt = f"Suggest a detailed format for writing chapter '{chapter}' of the {genre} book '{book_title}'. Consider the narrative flow and genre conventions."
|
89 |
+
st.session_state.chapter_formats[chapter] = generate_book_component(format_prompt, st.session_state.toc)
|
90 |
+
if chapter in st.session_state.chapter_formats:
|
91 |
+
st.write("**Chapter Format:**")
|
92 |
+
st.write(st.session_state.chapter_formats[chapter])
|
93 |
+
|
94 |
+
# Generate Chapter Content
|
95 |
+
if st.button(f"Generate Chapter {i+1}"):
|
96 |
+
chapter_content = ""
|
97 |
+
format_sections = st.session_state.chapter_formats[chapter].split("\n")
|
98 |
+
for section in format_sections:
|
99 |
+
if section:
|
100 |
+
section_prompt = f"Write the '{section.strip()}' section of chapter '{chapter}' for the {genre} book '{book_title}', ensuring it fits into the overall narrative and follows the previous content."
|
101 |
+
section_content = generate_book_component(section_prompt, chapter_content)
|
102 |
+
chapter_content += f"{section.strip()}:\n{section_content}\n\n"
|
103 |
+
st.session_state.book_content += f"## Chapter {i+1}: {chapter}\n\n{st.session_state.chapter_formats[chapter]}\n\n{chapter_content}\n\n"
|
104 |
+
st.write("**Chapter Content:**")
|
105 |
+
st.write(chapter_content)
|
106 |
+
|
107 |
+
# Download Button
|
108 |
+
if st.session_state.book_content:
|
109 |
st.download_button(
|
110 |
label="Download Book",
|
111 |
+
data=st.session_state.book_content,
|
112 |
+
file_name=f"{book_title.replace(' ', '_')}.txt",
|
113 |
mime="text/plain"
|
114 |
)
|
115 |
|