Spaces:
Sleeping
Sleeping
File size: 4,677 Bytes
97f86de 8dcd1e2 97f86de 8dcd1e2 97f86de 52f4fac 97f86de 8dcd1e2 97f86de 8dcd1e2 d44fa6f 8dcd1e2 32cd9dd 8dcd1e2 32cd9dd 8dcd1e2 32cd9dd 8dcd1e2 d7d4694 8dcd1e2 97f86de 8dcd1e2 97f86de 8dcd1e2 97f86de 8dcd1e2 d44fa6f 8dcd1e2 d44fa6f 8dcd1e2 97f86de 8dcd1e2 bc3d95e 8dcd1e2 bc3d95e d44fa6f 8dcd1e2 8ae2ba2 d44fa6f 8dcd1e2 d44fa6f 8dcd1e2 d44fa6f 8dcd1e2 d44fa6f 97f86de 8dcd1e2 97f86de bf41528 |
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 |
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="mixtral-8x7b-32768", 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",
"Most importantly: Don't be perfect. Be human. Be yourself."
],
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"
)
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() |