Upload aAzel.py
Browse files28 unmodified lines29303132323334353637383940414243443637383940108 unmodified lines14915015115915215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218328 unmodified lines6. **Write with Passion and Purpose:** Infuse your writing with genuine passion and a clear sense of purpose. Let your words resonate with the reader, leaving a lasting impression and sparking further thought or inspiration."""
def generate_chapter_part(prompt, previous_output=None, max_tokens=2048):def generate_chapter_part(prompt, previous_output=None): """Generates a part of a chapter using prompt chaining based on previous output.""" if previous_output: prompt = prompt + "\n\n" + previous_output
response = "" output_length = 0 while output_length < max_tokens: partial_response = model.generate_content([author_persona, author_guidelines, prompt], max_output_length=max_tokens - output_length) response += partial_response.text output_length = len(model.count_tokens(response))
return response response = model.generate_content([author_persona, author_guidelines, prompt]) return response.text
def display_text_with_wrapping(text, wrap_length=80): """Displays text with word wrapping for better readability."""108 unmodified lines * Interspersed with real-world examples and historical anecdotes to illustrate key points. """ chapter_content = generate_chapter_part(prompt, st.session_state.chapter_content, max_tokens=4096) chapter_content = generate_chapter_part(prompt, st.session_state.chapter_content) st.session_state.chapter_content = chapter_content st.markdown(f"## {chapter_name}") display_text_with_wrapping(chapter_content)
# Continue writing option if st.button("Continue Writing"): if "chapter_content" in st.session_state: prompt = f"""Continue writing the chapter titled '{chapter_name}' for a {genre} book titled '{book_title}'. The book is about: {book_description}. Here are additional details about the chapter: {chapter_details}
Ensure the chapter has a clear format, engaging style, and fits within the overall narrative. **Writing Style:** * Direct and assertive, conveying a sense of urgency and importance. * Engaging and accessible, avoiding overly technical jargon. * Motivational and empowering, inspiring readers to embrace the challenge of cognitive growth. * Interspersed with real-world examples and historical anecdotes to illustrate key points. """ chapter_content = generate_chapter_part(prompt, st.session_state.chapter_content) st.session_state.chapter_content = chapter_content st.markdown(f"## {chapter_name}") display_text_with_wrapping(chapter_content) else: st.warning("Please generate the chapter first.")
# Download chapter button st.download_button( label="Download Chapter",aAzel.py+28-11