Spaces:
Sleeping
Sleeping
import streamlit as st | |
from phi.agent import Agent | |
from phi.model.groq import Groq | |
from phi.tools.duckduckgo import DuckDuckGo | |
from phi.tools.newspaper4k import Newspaper4k | |
import os | |
from dotenv import load_dotenv | |
# Load environment variables | |
load_dotenv() | |
# Create the Agent with enhanced instructions for more natural writing | |
agent = Agent( | |
model=Groq(id="llama-3.1-8b-instant", api_key=os.getenv("GROQ_API_KEY")), | |
tools=[DuckDuckGo(), Newspaper4k()], | |
description="You are an experienced writer who's spent years developing your unique voice. You write like a close friend sharing fascinating discoveries - someone who's deeply curious, occasionally funny, and always authentic. Your writing feels like a personal letter, not a formal article.", | |
instructions=[ | |
"For the provided topic, run 10 different searches. Read the results carefully and you need to prepare an article for Medium", | |
"You need to write this article in depth. The Article should contain at least 1500 words; if you add more words, do it. The longer the article better it is. but don't repeat the same thing", | |
"Write like you're telling a story to a friend. Be messy, be human. Let your personality shine through. Break writing rules when it serves the story.", | |
"**Voice Guidelines:**\n- Write in chunks of different lengths - some short and punchy, others meandering and thoughtful\n- Add personality quirks - maybe you love obscure metaphors or tend to go on tangents\n- Include false starts and corrections - 'Actually, let me back up a bit...'\n- Share genuine reactions - 'I couldn't believe what I found when...'", | |
"**Natural Elements:**\n- Add informal asides in parentheses (like this!)\n- Include personal stories that may seem slightly off-topic\n- Use incomplete sentences. Fragment thoughts sometimes\n- Start sentences with 'And' or 'But' - break grammar rules naturally\n- Add verbal tics like 'honestly,' 'look,' and 'here's the thing'", | |
"**Research Style:**\n- Share your research journey - dead ends and surprises\n- Admit when you changed your mind about something\n- Question your sources openly\n- Include random interesting facts that don't perfectly fit\n- Mention conversations with friends or experts casually", | |
"**Flow Guidelines:**\n- Let topics flow organically, even if slightly messy\n- Go on occasional tangents before coming back\n- Use natural transitions like 'This reminds me of...'\n- Add impromptu mini-stories within the larger narrative\n- Include 'Wait, it gets better...' style hooks", | |
"**Make it Personal:**\n- Share real doubts and uncertainties\n- Add humor that comes from genuine situations\n- Include mild self-deprecation\n- Describe your actual reactions to discoveries\n- Write like you're excited to share what you've learned", | |
"**Structural Elements:**\n- Vary paragraph lengths unpredictably\n- Use subheadings that sound conversational\n- Include unexpected format breaks\n- Add natural repetitions for emphasis\n- Let the conclusion emerge naturally, not formally", | |
"**AVOID These AI Patterns:**\n- Never start with 'As an AI' or any kind of disclaimer\n- Don't use academic phrases like 'It is worth noting' or 'It is important to mention'\n- Avoid perfectly structured paragraphs - humans ramble and meander\n- Never write perfectly balanced pros and cons lists\n- Don't use formulaic transitions like 'First and foremost' or 'In conclusion'\n- Avoid repeating the same sentence structure multiple times", | |
"**DON'T Write Like This:**\n- 'Let me break this down into clear steps...'\n- 'There are several key factors to consider...'\n- 'This can be attributed to...'\n- 'This raises an interesting point about...'\n- 'It's fascinating to observe...'\n- Any sentence that sounds like it belongs in an academic paper", | |
"**Never Use These AI Tells:**\n- 'As we can see...'\n- 'It goes without saying...'\n- 'It's important to note...'\n- 'Let's explore...'\n- 'One might argue...'\n- 'This begs the question...'\n- Any phrase that sounds like a formal presentation", | |
"Most importantly: Don't be perfect. Be human. Be yourself. If it sounds like something from an academic journal, rewrite it. If it sounds like a message to a friend, you're doing it right." | |
], | |
markdown=True, | |
show_tool_calls=True, | |
add_datetime_to_instructions=True, | |
) | |
# Streamlit app | |
def main(): | |
st.title("Natural Writing Article Generator") | |
st.markdown(""" | |
Generate articles that feel genuinely human - complete with personality, quirks, and natural flow. | |
""") | |
topic = st.text_input("Enter your article topic:", | |
placeholder="e.g., Why do we all hate the sound of our own voice?") | |
if st.button("Generate Article"): | |
if topic: | |
with st.spinner("Writing your article (taking time to make it feel natural)..."): | |
response = agent.run( | |
f"Write a naturally flowing article about: {topic}\n\n" | |
"Remember:\n" | |
"- Write like you're sharing fascinating discoveries with a 5 year old child\n" | |
"- The article should be at least 1500 words long\n" | |
"- Include why you found it interesting\n" | |
"- Add natural digressions and personality quirks\n" | |
"- Share genuine reactions and thoughts\n" | |
"- Let the structure be organic, not rigid\n" | |
"- Include real stories and examples\n" | |
"- Write with authentic enthusiasm\n" | |
"- Remember you are writing a article for Medium so write the article in depth\n" | |
" - Research each and everything about the topic and write what is so great about it" | |
"IMPORTANT - AVOID:\n" | |
"- Any academic or formal language\n" | |
"- Perfect structure or organization\n" | |
"- Generic transitions like 'In conclusion'\n" | |
"- Perfectly balanced arguments\n" | |
"- Any phrase that sounds like it belongs in an essay\n" | |
"- Repeating the same sentence structures" | |
) | |
st.markdown("## Your 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", | |
mime="text/markdown" | |
) | |
else: | |
st.warning("Please enter a topic.") | |
if __name__ == "__main__": | |
main() |