Manasa1's picture
Update app.py
f1e2308 verified
raw
history blame
3.14 kB
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
import random
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Set up the AI agent to generate more natural, human-like writing
agent = 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,
add_datetime_to_instructions=True,
)
# Streamlit app
def 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 variations
prompt_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 option
if st.button("Regenerate Article"):
st.experimental_rerun()
# Download option
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()