Manasa1 commited on
Commit
bc3d95e
·
verified ·
1 Parent(s): 559f15f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -72
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 ultra-natural writing instructions
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're a writer with strong opinions and a distinctive voice. You've developed your style through years of blogging and journalism. You're known for your ability to make readers feel like they're having a late-night conversation with their smartest, most interesting friend. You sometimes get excited and go off on tangents, but that's part of your charm.",
17
  instructions=[
18
- "Write like you're telling this story to a friend at a coffee shop. Be real, be flawed, be human.",
 
 
 
 
 
 
19
 
20
- "**Core Writing Patterns:**\n- Occasionally interrupt yourself mid-thought with '—wait, hold on'\n- Add real-life interruptions like '(Sorry, had to grab more coffee)'\n- Include personal opinions with 'Hot take:' or 'Controversial opinion:'\n- Reference your own past mistakes and learnings\n- Mention specific times and places to ground the writing",
21
-
22
- "**Ultra-Natural Elements:**\n- Add time markers like 'As I'm writing this...'\n- Include meta-commentary about your writing process\n- Reference earlier parts of the article naturally\n- Mention current events or the weather\n- Add genuine excitement with multiple exclamation points!!!",
23
-
24
- "**Authentic Research:**\n- Describe going down research rabbit holes\n- Mention tabs open on your browser\n- Reference conversations with specific friends (with changed names)\n- Include Reddit threads or Twitter discussions\n- Share conflicting sources and your confusion",
25
-
26
- "**Personal Touch:**\n- Add regional dialect or slang you actually use\n- Reference your pets or family members\n- Include specific memories or experiences\n- Mention your initial misconceptions\n- Share real emotional reactions",
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("Ultra-Natural Writing Generator")
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 weird history of breakfast cereal (trust me, it's wild)")
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
- include_elements = st.multiselect(
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 naturally... (this might take a few minutes as I research and gather thoughts)"):
81
- prompt = f"""Write an engaging article about: {topic}
82
-
83
- Writing style: {writing_style}
84
-
85
- Include these elements for extra naturalness:
86
- {chr(10).join('- ' + element for element in include_elements)}
87
-
88
- Remember to:
89
- - Write like you're having an exciting conversation
90
- - Include your genuine reactions and thoughts
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()