Johan713 commited on
Commit
e679e20
1 Parent(s): 4bc7278

Update aAzel.py

Browse files
Files changed (1) hide show
  1. aAzel.py +58 -47
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
- # Genre Selection
51
- genres = ["Science Fiction", "Fantasy", "Mystery", "Thriller", "Romance", "Historical Fiction", "Horror", "Literary Fiction", "Young Adult", "Children's Literature", "Non-Fiction"]
 
 
 
52
  genre = st.selectbox("Choose a Genre:", genres)
53
-
54
- # Book Description
55
- book_description = st.text_area("Describe your book:", "Enter a detailed description of your book here...")
56
-
57
- if st.button("Start Writing"):
58
- if not book_description:
59
- st.warning("Please provide a description for your book.")
60
- return
61
-
62
- # Prompt Chaining for Book Creation
63
- title = generate_book_component(f"Generate a compelling title for a {genre} book about: {book_description}")
64
- st.subheader("Title:")
65
- st.write(title)
66
-
67
- toc = generate_book_component(f"Create a detailed Table of Contents for a {genre} book titled '{title}' about: {book_description}", title)
68
- st.subheader("Table of Contents:")
69
- st.write(toc)
70
-
71
- book_content = ""
72
- chapters = toc.split("\n")
73
-
 
 
 
74
  for i, chapter in enumerate(chapters):
75
- if chapter:
76
- st.write(f"## Chapter {i+1}: {chapter}")
77
 
78
  # Generate Chapter Format
79
- format_prompt = f"Suggest a detailed format for writing chapter '{chapter}' of the {genre} book '{title}'. Consider the narrative flow and genre conventions."
80
- chapter_format = generate_book_component(format_prompt, toc)
81
- st.write("**Chapter Format:**")
82
- st.write(chapter_format)
83
-
84
- # Generate Chapter Content Following the Format
85
- chapter_content = ""
86
- format_sections = chapter_format.split("\n")
87
- for section in format_sections:
88
- if section:
89
- section_prompt = f"Write the '{section.strip()}' section of chapter '{chapter}' for the {genre} book '{title}', ensuring it fits into the overall narrative and follows the previous content."
90
- section_content = generate_book_component(section_prompt, chapter_content) # Pass previous sections as context
91
- chapter_content += f"{section.strip()}:\n{section_content}\n\n"
92
-
93
- st.write("**Chapter Content:**")
94
- st.write(chapter_content)
95
-
96
- book_content += f"## Chapter {i+1}: {chapter}\n\n{chapter_format}\n\n{chapter_content}\n\n"
97
-
 
 
 
 
98
  st.download_button(
99
  label="Download Book",
100
- data=book_content,
101
- file_name=f"{title.replace(' ', '_')}.txt",
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