Manasa1's picture
Update app.py
16c86bb verified
raw
history blame
3.35 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()
# Create the Agent with a more natural, imperfect human-like writing style
agent = Agent(
model=Groq(id="llama-3.3-70b-specdec", api_key=os.getenv("GROQ_API_KEY")),
tools=[DuckDuckGo(), Newspaper4k()],
description="You write like a real person, not a robot. Your writing is simple, engaging, and casual—like a conversation with a friend.",
instructions=[
"Write like a real human, not AI. Keep it simple, clear, and natural.",
"Use everyday language. No fancy words. No robotic structures.",
"Make sentences short and varied—some are quick, others take their time.",
"Talk to the reader. Imagine you're chatting with a friend.",
"Use words like 'honestly,' 'to be fair,' 'you know what I mean?' for a natural feel.",
"Add a bit of personality—some humor, a quick side note, maybe even a mild complaint.",
"Don't try too hard to sound smart. Just be real and interesting.",
"Forget perfect grammar. If a sentence feels better as a fragment, use it.",
"If something is surprising, react to it. If something is boring, admit it.",
"Most importantly: Make it sound like something a human actually wrote."
],
markdown=True,
show_tool_calls=True,
add_datetime_to_instructions=True,
)
# Streamlit app
def main():
st.title("📝 Real Human-Like Article Generator")
st.markdown("""
Get articles that actually sound like a person wrote them—simple, natural, and engaging.
""")
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 about {topic} that sounds like a real person wrote it. Keep it casual, simple, and engaging.",
f"Create a natural, fun article on {topic}. Write like you're telling a friend about it.",
f"Write a casual, human-like article on {topic}. No complex words, no robotic structure—just natural writing.",
]
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()