Spaces:
Sleeping
Sleeping
Update app.py
Browse files3 unmodified lines4567891011121314151617181920212223242526272829302 unmodified lines33343536373839404142434445464748495051525354555657585960616263646566676869702 unmodified lines737475763 unmodified linesfrom phi.tools.duckduckgo import DuckDuckGofrom phi.tools.newspaper4k import Newspaper4kimport osimport randomfrom dotenv import load_dotenv# Load environment variablesload_dotenv()# Set up the AI agent to generate more natural, human-like writingagent = Agent(model=Groq(id="llama-3.3-70b-specdec", api_key=os.getenv("GROQ_API_KEY")),tools=[DuckDuckGo(), Newspaper4k()],description="Write in a way that sounds like a real person. No robotic structures, just natural and engaging storytelling.",instructions=["Keep it simple and conversational, like you're talking to a friend.","No fancy words or robotic phrasing—just natural language.","Vary sentence lengths, throw in a casual phrase, and keep it real.","If something surprises you, react to it. If it's boring, say so.","Don't force perfect grammar—if a sentence feels better as a fragment, go with it.","Make it fun. A little humor, a tiny rant, or a personal touch goes a long way.","Talk to the reader. Use 'you' and 'we' to make it feel more personal.","If a fact sounds weird, acknowledge it. If a statement is bold, justify it.","Bottom line: Make it sound like something a real person actually wrote.",],markdown=True,show_tool_calls=True,2 unmodified lines# Streamlit appdef main():st.title("📝 Human-Like Article Generator")st.markdown("Get articles that actually sound like a person wrote them—natural, engaging, and fun.")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... (Making it sound as real as possible)"):# Human-like prompt variationsprompt_variations = [f"Write an article on {topic} like you're explaining it to a friend over coffee.",f"Tell a story about {topic}. Keep it casual, engaging, and easy to read.",f"Write a fun, natural article on {topic}—no robotic tone, just real talk.",]prompt = random.choice(prompt_variations)response = agent.run(prompt)st.markdown("## 📝 Your Naturally Written Article")st.markdown(response.content)# Provide a regeneration optionif st.button("Regenerate Article"):st.experimental_rerun()# Download optionst.download_button(label="📥 Download Article (Markdown)",data=response.content,file_name=f"{topic.lower().replace(' ', '-')}-article.md",mime="text/markdown"2 unmodified linesst.warning("Please enter a topic.")if __name__ == "__main__":main()3 unmodified lines45678910111213141516171819202122232425262728293031323334352 unmodified lines38394041424344454647484950515253545556575859606162636465666768697071722 unmodified lines757677783 unmodified linesfrom phi.tools.duckduckgo import DuckDuckGofrom phi.tools.newspaper4k import Newspaper4kimport osfrom dotenv import load_dotenv# Load environment variablesload_dotenv()# Create the Agent with enhanced instructions for more natural writingagent = 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=["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,2 unmodified lines# Streamlit appdef 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 buttonst.download_button(label="Download Article (Markdown)",data=response.content,file_name=f"{topic.lower().replace(' ', '-')}-article.md",mime="text/markdown"2 unmodified linesst.warning("Please enter a topic.")if __name__ == "__main__":main()
app.py+43-41