Spaces:
Running
Running
File size: 6,265 Bytes
97f86de 8dcd1e2 97f86de f9645ac 97f86de 67f11bb 97f86de f9645ac 97f86de f9645ac 86703ef 97f86de 8dcd1e2 97f86de 8dcd1e2 97f86de f9645ac 8dcd1e2 97f86de f9645ac 86703ef f9645ac d44fa6f f9645ac 8ae2ba2 f9645ac d44fa6f f9645ac d44fa6f 8dcd1e2 d44fa6f 97f86de 8dcd1e2 97f86de f9645ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
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.3-70b-versatile", 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=[
"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 friend\n"
"- Include your personal journey of researching this topic\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\n"
"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() |