Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,31 +9,27 @@ from dotenv import load_dotenv
|
|
9 |
# Load environment variables
|
10 |
load_dotenv()
|
11 |
|
12 |
-
# Create the Agent with
|
13 |
agent = Agent(
|
14 |
model=Groq(id="llama-3.1-8b-instant", api_key=os.getenv("GROQ_API_KEY")),
|
15 |
tools=[DuckDuckGo(), Newspaper4k()],
|
16 |
-
description="You
|
17 |
instructions=[
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
"
|
23 |
-
|
24 |
-
"
|
25 |
-
|
26 |
-
"
|
27 |
-
|
28 |
-
"**Natural Digressions:**\n- Go off on relevant tangents\n- Circle back with 'Anyway, where was I?'\n- Add footnotes for random thoughts\n- Include 'Oh! This reminds me of...'\n- Share seemingly unrelated stories that connect later",
|
29 |
-
|
30 |
-
"**Conversation Elements:**\n- Ask readers direct questions\n- Anticipate and address objections\n- Use casual interjections like 'yeah,' 'nope,' 'ugh'\n- Add emphasis with *italics* for internal thoughts\n- Include 'Edit:' additions like on Reddit",
|
31 |
-
|
32 |
-
"**Structure Breakers:**\n- Add random lists in the middle of paragraphs\n- Include sudden format changes\n- Use unconventional section titles\n- Break the fourth wall occasionally\n- End sections with cliffhangers or jokes",
|
33 |
-
|
34 |
-
"**Extra Natural Elements:**\n- Reference your writing environment\n- Mention what music you're listening to\n- Add time stamps to show progression\n- Include 'Update:' sections with new findings\n- Share real-world distractions",
|
35 |
-
|
36 |
-
"Remember: Perfect writing feels fake. Real writing has personality, flaws, and surprises."
|
37 |
],
|
38 |
markdown=True,
|
39 |
show_tool_calls=True,
|
@@ -42,72 +38,38 @@ agent = Agent(
|
|
42 |
|
43 |
# Streamlit app
|
44 |
def main():
|
45 |
-
st.title("
|
46 |
-
st.markdown("""
|
47 |
-
Create articles that feel genuinely human - like a conversation with your most interesting friend.
|
48 |
-
""")
|
49 |
|
50 |
topic = st.text_input("Enter your article topic:",
|
51 |
-
placeholder="e.g., The
|
52 |
-
|
53 |
-
writing_style = st.selectbox(
|
54 |
-
"Choose a writing personality:",
|
55 |
-
[
|
56 |
-
"Excited researcher who goes off on fascinating tangents",
|
57 |
-
"Cynical journalist who's seen it all",
|
58 |
-
"Curious explorer sharing mind-blowing discoveries",
|
59 |
-
"Friendly expert who loves explaining complex topics",
|
60 |
-
"Witty storyteller with a knack for unexpected connections"
|
61 |
-
]
|
62 |
-
)
|
63 |
|
64 |
-
|
65 |
-
"Add extra natural elements:",
|
66 |
-
[
|
67 |
-
"Personal anecdotes and stories",
|
68 |
-
"Behind-the-scenes research journey",
|
69 |
-
"Random interesting tangents",
|
70 |
-
"Casual asides and commentary",
|
71 |
-
"Meta writing comments",
|
72 |
-
"Time stamps and updates",
|
73 |
-
"References to current events"
|
74 |
-
],
|
75 |
-
default=["Personal anecdotes and stories", "Behind-the-scenes research journey"]
|
76 |
-
)
|
77 |
-
|
78 |
-
if st.button("Write Article"):
|
79 |
if topic:
|
80 |
-
with st.spinner("Writing
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
-
|
90 |
-
|
91 |
-
- Add natural digressions and personality quirks
|
92 |
-
- Share your research journey and discoveries
|
93 |
-
- Let your real enthusiasm shine through
|
94 |
-
- Break writing rules when it feels natural
|
95 |
-
- Add timestamps and real-world references
|
96 |
-
"""
|
97 |
-
response = agent.run(prompt)
|
98 |
|
99 |
-
st.markdown("## Your Article")
|
100 |
st.markdown(response.content)
|
101 |
|
102 |
# Add download button
|
103 |
st.download_button(
|
104 |
label="Download Article (Markdown)",
|
105 |
data=response.content,
|
106 |
-
file_name=f"{topic.lower().replace(' ', '-')}-article.md",
|
107 |
mime="text/markdown"
|
108 |
)
|
109 |
else:
|
110 |
st.warning("Please enter a topic.")
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
-
main()
|
|
|
9 |
# Load environment variables
|
10 |
load_dotenv()
|
11 |
|
12 |
+
# Create the Agent with updated instructions for writing for Medium
|
13 |
agent = Agent(
|
14 |
model=Groq(id="llama-3.1-8b-instant", api_key=os.getenv("GROQ_API_KEY")),
|
15 |
tools=[DuckDuckGo(), Newspaper4k()],
|
16 |
+
description="You are an experienced writer who understands the art of engaging, informative, and clear writing. Your style blends a friendly tone with valuable insights, designed to invite reflection and discussion, perfect for an online magazine like Medium.",
|
17 |
instructions=[
|
18 |
+
# Positive prompts for Medium
|
19 |
+
"Write like you're sharing an insightful discovery with a friend but maintain a level of professionalism that suits a Medium audience.",
|
20 |
+
"**Voice Guidelines:**\n- Be conversational, but ensure clarity and professionalism.\n- Avoid sounding overly casual or too formal—balance is key.\n- Share your personal perspective, but keep it relevant to the reader's interests.\n- Use stories and examples that connect to the broader theme.",
|
21 |
+
"**Structure Guidelines:**\n- Start with a compelling hook to grab the reader's attention.\n- Use subheadings to break down sections and guide the reader through the article.\n- Create smooth transitions between sections to maintain flow.\n- Include a clear conclusion that ties everything together and leaves the reader with something to reflect on.\n- Use lists or bullet points for clarity when appropriate.",
|
22 |
+
"**Research Style:**\n- Back up your claims with credible sources, but don't overwhelm the reader with data—focus on the most impactful findings.\n- Share your process and how you came to your conclusions.\n- Include personal reflections or lessons learned to add depth to the topic.",
|
23 |
+
"**Engagement:**\n- Aim to spark curiosity or offer value that encourages the reader to think or take action.\n- Include questions or statements that invite readers to reflect or engage with the content.\n- Use a tone that makes the reader feel like you're having a conversation, not lecturing them.",
|
24 |
+
"Most importantly: Keep it clear, engaging, and relevant. Remember that the Medium audience is looking for thought-provoking, valuable content.",
|
25 |
|
26 |
+
# Negative prompts for Medium
|
27 |
+
"Avoid being too casual or informal. Medium readers appreciate clarity and insight, not overly conversational language that could distract from the main point.",
|
28 |
+
"Do not use excessive slang or make the writing too 'chatty'. While personality is important, it should not overshadow the message.",
|
29 |
+
"Avoid going on tangents that do not add value or clarity to the main idea. Medium articles should have a clear focus.",
|
30 |
+
"Don’t be repetitive unless it's for emphasis. Medium readers prefer concise content with meaningful points.",
|
31 |
+
"Avoid overcomplicating the structure. Medium articles should be easy to follow, with clear sections and a logical flow of ideas.",
|
32 |
+
"Don’t use overly technical or niche jargon unless it's essential for the topic. Medium's audience is diverse, so keep things accessible.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
],
|
34 |
markdown=True,
|
35 |
show_tool_calls=True,
|
|
|
38 |
|
39 |
# Streamlit app
|
40 |
def main():
|
41 |
+
st.title("Medium Article Generator")
|
42 |
+
st.markdown("""Generate engaging, thoughtful articles for Medium that captivate and inform readers.""")
|
|
|
|
|
43 |
|
44 |
topic = st.text_input("Enter your article topic:",
|
45 |
+
placeholder="e.g., The psychology of procrastination: Why we avoid what we want most")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
+
if st.button("Generate Article"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
if topic:
|
49 |
+
with st.spinner("Writing your article... (making sure it's clear and engaging for Medium)..."):
|
50 |
+
response = agent.run(
|
51 |
+
f"Write an article for Medium about: {topic}\n\n"
|
52 |
+
"Remember:\n"
|
53 |
+
"- Start with a strong hook\n"
|
54 |
+
"- Use clear sections with subheadings\n"
|
55 |
+
"- Keep your tone conversational, yet informative\n"
|
56 |
+
"- Avoid being overly casual or too formal\n"
|
57 |
+
"- Back up your points with insights or personal reflections\n"
|
58 |
+
"- End with a clear conclusion that invites reflection"
|
59 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
+
st.markdown("## Your Medium Article")
|
62 |
st.markdown(response.content)
|
63 |
|
64 |
# Add download button
|
65 |
st.download_button(
|
66 |
label="Download Article (Markdown)",
|
67 |
data=response.content,
|
68 |
+
file_name=f"{topic.lower().replace(' ', '-')}-medium-article.md",
|
69 |
mime="text/markdown"
|
70 |
)
|
71 |
else:
|
72 |
st.warning("Please enter a topic.")
|
73 |
|
74 |
if __name__ == "__main__":
|
75 |
+
main()
|