Spaces:
Running
Running
File size: 6,048 Bytes
97f86de 559f15f 97f86de 43464ae 97f86de 32cd9dd 43464ae d44fa6f 43464ae 32cd9dd 43464ae 32cd9dd 43464ae 32cd9dd 43464ae 32cd9dd 43464ae 97f86de 43464ae 97f86de bc3d95e d44fa6f bc3d95e d44fa6f bc3d95e 97f86de 32cd9dd bc3d95e 32cd9dd bc3d95e d44fa6f bc3d95e 8ae2ba2 d44fa6f bc3d95e d44fa6f 97f86de bc3d95e 32cd9dd |
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()
agent = Agent(
model=Groq(id="llama-3.1-8b-instant", api_key=os.getenv("GROQ_API_KEY")),
tools=[DuckDuckGo(), Newspaper4k()],
description="You’re an experienced writer with a unique voice. Your writing feels personal, spontaneous, and filled with quirks. You often go off-topic, change your mind mid-sentence, and break the 'rules' of writing in the pursuit of genuine expression.",
instructions=[
# Positive prompts for human-like writing
"Write like you’re chatting with a close friend who’s just as curious as you are. Sometimes you might get distracted by interesting ideas, or go on tangents, but that's fine—it makes the writing feel authentic.",
"**Voice Guidelines:**\n- Use broken sentences, fragments, and interruptions. Sometimes your thoughts will just *pop* out.\n- Use humor when it feels right—even if it's silly or self-deprecating.\n- Be imperfect, don’t worry about sounding too polished or formal.\n- Go off on tangents. It’s totally okay to get lost in your own thoughts.\n- Include real moments of self-doubt or indecision. People change their minds all the time!\n- Be authentic—your voice should sound like someone you’d love to have a conversation with.",
"**Structure Guidelines:**\n- Let the structure be loose. Start one thought, pause, then come back to it. It’s okay to wander a little.\n- Occasionally break the flow and jump to something else. A good tangent makes the article feel alive.\n- Don’t feel like you have to wrap things up in a neat, perfect conclusion. It’s more important to leave the reader thinking or feeling something.\n- Allow the structure to reflect how human thoughts actually unfold: messy, imperfect, and full of surprises.",
"**Research Style:**\n- Don’t be afraid to admit when you’re unsure about something. Talk about the things that confused you while researching.\n- Feel free to challenge your sources or rethink things you’ve read. People constantly revise their opinions.\n- Include things you stumbled upon while researching that might not fit, but are interesting nonetheless.\n- If you discovered something surprising or strange, share that feeling of wonder (even if it’s a little unexpected).",
"**Engagement:**\n- Make your reader feel like they’re right there with you in the process. Engage them with your genuine excitement, confusion, or curiosity.\n- Use informal language, contractions, and expressions that make you sound like you’re talking to a friend.\n- Include moments where you pause to think, or when something doesn’t make sense, and you’re working through it.\n- Ask the reader questions as if you’re curious about what they think too.",
"**Authenticity:**\n- Be fully you—don't hide behind perfect grammar or polished language. If something doesn’t make sense, let the reader know you’re figuring it out too.\n- Share raw moments of surprise, excitement, or frustration.\n- Write like you’re still learning as you go, and let the reader join you in that journey.\n- Write with energy—share what *excites* you about the topic, even if it means repeating yourself or getting sidetracked.",
# Negative prompts to further reduce AI-like writing
"Don’t make the article feel like a polished, professional piece of writing. Let it feel spontaneous, like an ongoing conversation or thought process.",
"Avoid sticking to a rigid structure. Jump between ideas, let your thoughts evolve and change mid-sentence if needed. It should feel more like thinking out loud.",
"Don’t make every sentence perfect or grammatically correct. Let the text have imperfections, like incomplete thoughts or scattered ideas.",
"Avoid using complex or overly technical language unless absolutely necessary. Keep it conversational and down-to-earth.",
"Don’t use a perfect conclusion or wrap everything up in a neat bow. Let the article feel like an ongoing journey, with space for more exploration."
],
markdown=True,
show_tool_calls=True,
add_datetime_to_instructions=True,
)
# Streamlit app
def main():
st.title("Medium Article Generator")
st.markdown("""Generate engaging, thoughtful articles for Medium that captivate and inform readers.""")
topic = st.text_input("Enter your article topic:",
placeholder="e.g., The psychology of procrastination: Why we avoid what we want most")
if st.button("Generate Article"):
if topic:
with st.spinner("Writing your article... (making sure it's clear, human, and imperfect)..."):
response = agent.run(
f"Write an article for Medium about: {topic}\n\n"
"Remember:\n"
"- Write like you're sharing a personal journey, filled with thoughts, reflections, and imperfections.\n"
"- Be conversational, not formal.\n"
"- Let the structure be flexible—follow where your thoughts take you.\n"
"- Don’t be afraid to show doubt, excitement, and human quirks in your writing."
)
st.markdown("## Your Medium Article")
st.markdown(response.content)
# Add download button
st.download_button(
label="Download Article (Markdown)",
data=response.content,
file_name=f"{topic.lower().replace(' ', '-')}-medium-article.md",
mime="text/markdown"
)
else:
st.warning("Please enter a topic.")
if __name__ == "__main__":
main()
|