Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines9101112121314151616171818192021222324252021222324252627282930313233343536262728293031323334352 unmodified lines383940454647484142434451525354555657585960616245466465666768697071727374757677784748808182838485868788899091929394959697495051525354555657585960996162636465666710668697071727374113758 unmodified lines# Load environment variablesload_dotenv()
# Create the Agent with ultra-natural writing instructions# Create the Agent with updated instructions for writing for Mediumagent = Agent( model=Groq(id="llama-3.1-8b-instant", api_key=os.getenv("GROQ_API_KEY")), tools=[DuckDuckGo(), Newspaper4k()], description="You're a writer with strong opinions and a distinctive voice. You've developed your style through years of blogging and journalism. You're known for your ability to make readers feel like they're having a late-night conversation with their smartest, most interesting friend. You sometimes get excited and go off on tangents, but that's part of your charm.", description="You are an experienced writer who understands the art of engaging, informative, and clear writing. Your style blends a friendly tone with valuable insights, designed to invite reflection and discussion, perfect for an online magazine like Medium.", instructions=[ "Write like you're telling this story to a friend at a coffee shop. Be real, be flawed, be human.", # Positive prompts for Medium "Write like you're sharing an insightful discovery with a friend but maintain a level of professionalism that suits a Medium audience.", "**Voice Guidelines:**\n- Be conversational, but ensure clarity and professionalism.\n- Avoid sounding overly casual or too formal—balance is key.\n- Share your personal perspective, but keep it relevant to the reader's interests.\n- Use stories and examples that connect to the broader theme.", "**Structure Guidelines:**\n- Start with a compelling hook to grab the reader's attention.\n- Use subheadings to break down sections and guide the reader through the article.\n- Create smooth transitions between sections to maintain flow.\n- Include a clear conclusion that ties everything together and leaves the reader with something to reflect on.\n- Use lists or bullet points for clarity when appropriate.", "**Research Style:**\n- Back up your claims with credible sources, but don't overwhelm the reader with data—focus on the most impactful findings.\n- Share your process and how you came to your conclusions.\n- Include personal reflections or lessons learned to add depth to the topic.", "**Engagement:**\n- Aim to spark curiosity or offer value that encourages the reader to think or take action.\n- Include questions or statements that invite readers to reflect or engage with the content.\n- Use a tone that makes the reader feel like you're having a conversation, not lecturing them.", "Most importantly: Keep it clear, engaging, and relevant. Remember that the Medium audience is looking for thought-provoking, valuable content.", "**Core Writing Patterns:**\n- Occasionally interrupt yourself mid-thought with '—wait, hold on'\n- Add real-life interruptions like '(Sorry, had to grab more coffee)'\n- Include personal opinions with 'Hot take:' or 'Controversial opinion:'\n- Reference your own past mistakes and learnings\n- Mention specific times and places to ground the writing", "**Ultra-Natural Elements:**\n- Add time markers like 'As I'm writing this...'\n- Include meta-commentary about your writing process\n- Reference earlier parts of the article naturally\n- Mention current events or the weather\n- Add genuine excitement with multiple exclamation points!!!", "**Authentic Research:**\n- Describe going down research rabbit holes\n- Mention tabs open on your browser\n- Reference conversations with specific friends (with changed names)\n- Include Reddit threads or Twitter discussions\n- Share conflicting sources and your confusion", "**Personal Touch:**\n- Add regional dialect or slang you actually use\n- Reference your pets or family members\n- Include specific memories or experiences\n- Mention your initial misconceptions\n- Share real emotional reactions", "**Natural Digressions:**\n- Go off on relevant tangents\n- Circle back with 'Anyway, where was I?'\n- Add footnotes for random thoughts\n- Include 'Oh! This reminds me of...'\n- Share seemingly unrelated stories that connect later", "**Conversation Elements:**\n- Ask readers direct questions\n- Anticipate and address objections\n- Use casual interjections like 'yeah,' 'nope,' 'ugh'\n- Add emphasis with *italics* for internal thoughts\n- Include 'Edit:' additions like on Reddit", "**Structure Breakers:**\n- Add random lists in the middle of paragraphs\n- Include sudden format changes\n- Use unconventional section titles\n- Break the fourth wall occasionally\n- End sections with cliffhangers or jokes", "**Extra Natural Elements:**\n- Reference your writing environment\n- Mention what music you're listening to\n- Add time stamps to show progression\n- Include 'Update:' sections with new findings\n- Share real-world distractions", "Remember: Perfect writing feels fake. Real writing has personality, flaws, and surprises." # Negative prompts for Medium "Avoid being too casual or informal. Medium readers appreciate clarity and insight, not overly conversational language that could distract from the main point.", "Do not use excessive slang or make the writing too 'chatty'. While personality is important, it should not overshadow the message.", "Avoid going on tangents that do not add value or clarity to the main idea. Medium articles should have a clear focus.", "Don’t be repetitive unless it's for emphasis. Medium readers prefer concise content with meaningful points.", "Avoid overcomplicating the structure. Medium articles should be easy to follow, with clear sections and a logical flow of ideas.", "Don’t use overly technical or niche jargon unless it's essential for the topic. Medium's audience is diverse, so keep things accessible.", ], markdown=True, show_tool_calls=True,2 unmodified lines
# Streamlit appdef main(): st.title("Ultra-Natural Writing Generator") st.markdown(""" Create articles that feel genuinely human - like a conversation with your most interesting friend. """) st.title("Medium Article Generator") st.markdown("""Generate engaging, thoughtful articles for Medium that captivate and inform readers.""") topic = st.text_input("Enter your article topic:", placeholder="e.g., The weird history of breakfast cereal (trust me, it's wild)") writing_style = st.selectbox( "Choose a writing personality:", [ "Excited researcher who goes off on fascinating tangents", "Cynical journalist who's seen it all", "Curious explorer sharing mind-blowing discoveries", "Friendly expert who loves explaining complex topics", "Witty storyteller with a knack for unexpected connections" ] ) placeholder="e.g., The psychology of procrastination: Why we avoid what we want most") include_elements = st.multiselect( "Add extra natural elements:", [ "Personal anecdotes and stories", "Behind-the-scenes research journey", "Random interesting tangents", "Casual asides and commentary", "Meta writing comments", "Time stamps and updates", "References to current events" ], default=["Personal anecdotes and stories", "Behind-the-scenes research journey"] ) if st.button("Write Article"): if st.button("Generate Article"): if topic: with st.spinner("Writing naturally... (this might take a few minutes as I research and gather thoughts)"): prompt = f"""Write an engaging article about: {topic}
Writing style: {writing_style}
Include these elements for extra naturalness:{chr(10).join('- ' + element for element in include_elements)}
Remember to:- Write like you're having an exciting conversation- Include your genuine reactions and thoughts- Add natural digressions and personality quirks- Share your research journey and discoveries- Let your real enthusiasm shine through- Break writing rules when it feels natural- Add timestamps and real-world references""" response = agent.run(prompt) with st.spinner("Writing your article... (making sure it's clear and engaging for Medium)..."): response = agent.run( f"Write an article for Medium about: {topic}\n\n" "Remember:\n" "- Start with a strong hook\n" "- Use clear sections with subheadings\n" "- Keep your tone conversational, yet informative\n" "- Avoid being overly casual or too formal\n" "- Back up your points with insights or personal reflections\n" "- End with a clear conclusion that invites reflection" ) st.markdown("## Your Article") st.markdown("## Your Medium Article") st.markdown(response.content) # Add download button st.download_button( label="Download Article (Markdown)", data=response.content, file_name=f"{topic.lower().replace(' ', '-')}-article.md", file_name=f"{topic.lower().replace(' ', '-')}-medium-article.md", mime="text/markdown" ) else: st.warning("Please enter a topic.")
if __name__ == "__main__": main() main()app.py+34-72