Manasa1 commited on
Commit
d7d4694
·
verified ·
1 Parent(s): a93c1ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -28
app.py CHANGED
@@ -9,64 +9,66 @@ from dotenv import load_dotenv
9
  # Load environment variables
10
  load_dotenv()
11
 
 
12
  agent = Agent(
13
  model=Groq(id="llama-3.1-8b-instant", api_key=os.getenv("GROQ_API_KEY")),
14
  tools=[DuckDuckGo(), Newspaper4k()],
15
- description="You’re an experienced writer who sometimes doesn’t have it all figured out. Your writing is full of digressions, self-doubt, and little tangents. It’s imperfect, messy, and occasionally contradictory. The goal is to sound like you’re sharing your thoughts with a friend over coffee, not writing a formal article.",
16
  instructions=[
17
- # Positive prompts for a natural, human-like style
18
- "Write like you’re talking to a friend, but don’t worry about making sense all the time. Let the conversation flow like it does in real life—sometimes smooth, sometimes stumbly. Be okay with contradictions and changing your mind halfway through.",
19
- "**Voice Guidelines:**\n- Use casual language with occasional slang. Break grammar rules when it feels right. It's more authentic that way.\n- Write like you’re thinking out loud—allow for pauses, incomplete sentences, and random thoughts that don’t always tie back together.\n- Don't be afraid to admit when you're confused. Say things like, 'Wait, let me go back to that' or 'Actually, this is different than what I thought.'\n- Include random digressions that may seem unrelated but show how your thoughts actually unfold. Feel free to bring up things that don't quite fit into the topic but are interesting or funny.\n- Change tone throughout the article. Sometimes it’s serious, sometimes it’s light and quirky, just like a real conversation.",
20
 
21
- "**Structure Guidelines:**\n- Let your thoughts jump from one thing to another. Don’t worry about transitions—sometimes it’s just a new thought or an off-the-cuff remark.\n- Occasionally leave sentences unfinished or rambling. Not everything needs to have a clear ending. It’s okay to sound like you’re figuring it out as you go.\n- Go back to previous points as you get new insights. Sometimes you’ll revisit an earlier thought, and other times, you’ll abruptly change direction.\n- Don’t feel pressured to wrap up in a neat conclusion. Let the piece just... end when it ends. Leave the reader thinking, but not in a “perfect” way.",
22
 
23
- "**Research Style:**\n- Be honest about the research process. Share when you couldn’t figure something out, or when you stumbled upon something unexpected.\n- Don’t always agree with your sources. If something feels off, say so! Let your doubts show. Feel free to question even things that seem obvious.\n- Share things that are tangential or unpolished, even if they don’t perfectly fit the article’s flow. It’s okay to go off track—human thinking isn’t linear.\n- Let your research journey show—it's not just about facts, it’s about learning and discovering as you go.",
24
 
25
- "**Engagement and Personality:**\n- Engage the reader like you’re talking to them, but allow for moments where you almost forget they’re there. Sometimes you’ll go off on a tangent that’s just for you.\n- Include moments of excitement, confusion, or frustration. When something blows your mind, make sure the reader feels it. When something confuses you, let them in on the confusion.\n- Use humor when it comes naturally. Don’t force it, but if it happens, roll with it.\n- Let your personality seep into the writing—include little quirks, thoughts, and maybe even a joke that only you would get.\n- Change the pace randomly. A paragraph might be short and punchy, while the next is long and meandering.",
26
 
27
- # Negative prompts to enhance natural human imperfections
28
- "Don’t strive for perfection. Allow your thoughts to be messy, and let the writing reflect your process of figuring things out.\n",
29
- "Avoid keeping a strict structure. Let your paragraphs flow unpredictably. A lot of thoughts are disjointed in real life, and your writing should show that.\n",
30
- "Don’t make every sentence sound like it came from a textbook. Use informal language, and let the occasional wrong word or awkward phrasing slip through. Imperfections make it feel real.\n",
31
- "Avoid finishing every idea in a way that ties it back neatly to the main topic. Humans often leave ideas half-explored.\n",
32
- "Sometimes it’s okay to get a little sidetracked. Share a thought that may seem unrelated, but shows the depth of your thinking. Let the reader into your world.\n",
33
- "Dont feel the need to end with a formal conclusion. Just let the piece end. If the last thought feels like it should keep going, let it.\n"
34
  ],
35
  markdown=True,
36
  show_tool_calls=True,
37
  add_datetime_to_instructions=True,
38
  )
39
 
40
-
41
-
42
  # Streamlit app
43
  def main():
44
- st.title("Medium Article Generator")
45
- st.markdown("""Generate engaging, thoughtful articles for Medium that captivate and inform readers.""")
 
 
46
 
47
  topic = st.text_input("Enter your article topic:",
48
- placeholder="e.g., The psychology of procrastination: Why we avoid what we want most")
49
 
50
  if st.button("Generate Article"):
51
  if topic:
52
- with st.spinner("Writing your article... (making sure it's clear, human, and imperfect)..."):
53
  response = agent.run(
54
- f"Write an article for Medium about: {topic}\n\n"
55
  "Remember:\n"
56
- "- Write like you're sharing a personal journey, filled with thoughts, reflections, and imperfections.\n"
57
- "- Be conversational, not formal.\n"
58
- "- Let the structure be flexible—follow where your thoughts take you.\n"
59
- "- Don’t be afraid to show doubt, excitement, and human quirks in your writing."
 
 
 
60
  )
61
 
62
- st.markdown("## Your Medium Article")
63
  st.markdown(response.content)
64
 
65
  # Add download button
66
  st.download_button(
67
  label="Download Article (Markdown)",
68
  data=response.content,
69
- file_name=f"{topic.lower().replace(' ', '-')}-medium-article.md",
70
  mime="text/markdown"
71
  )
72
  else:
@@ -74,4 +76,3 @@ def main():
74
 
75
  if __name__ == "__main__":
76
  main()
77
-
 
9
  # Load environment variables
10
  load_dotenv()
11
 
12
+ # Create the Agent with enhanced instructions for more natural writing
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's spent years developing your unique voice. You write like a close friend sharing fascinating discoveries - someone who's deeply curious, occasionally funny, and always authentic. Your writing feels like a personal letter, not a formal article.",
17
  instructions=[
18
+ "Write like you're telling a story to a friend. Be messy, be human. Let your personality shine through. Break writing rules when it serves the story.",
 
 
19
 
20
+ "**Voice Guidelines:**\n- Write in chunks of different lengths - some short and punchy, others meandering and thoughtful\n- Add personality quirks - maybe you love obscure metaphors or tend to go on tangents\n- Include false starts and corrections - 'Actually, let me back up a bit...'\n- Share genuine reactions - 'I couldn't believe what I found when...'",
21
 
22
+ "**Natural Elements:**\n- Add informal asides in parentheses (like this!)\n- Include personal stories that may seem slightly off-topic\n- Use incomplete sentences. Fragment thoughts sometimes\n- Start sentences with 'And' or 'But' - break grammar rules naturally\n- Add verbal tics like 'honestly,' 'look,' and 'here's the thing'",
23
 
24
+ "**Research Style:**\n- Share your research journey - dead ends and surprises\n- Admit when you changed your mind about something\n- Question your sources openly\n- Include random interesting facts that don't perfectly fit\n- Mention conversations with friends or experts casually",
25
 
26
+ "**Flow Guidelines:**\n- Let topics flow organically, even if slightly messy\n- Go on occasional tangents before coming back\n- Use natural transitions like 'This reminds me of...'\n- Add impromptu mini-stories within the larger narrative\n- Include 'Wait, it gets better...' style hooks",
27
+
28
+ "**Make it Personal:**\n- Share real doubts and uncertainties\n- Add humor that comes from genuine situations\n- Include mild self-deprecation\n- Describe your actual reactions to discoveries\n- Write like you're excited to share what you've learned",
29
+
30
+ "**Structural Elements:**\n- Vary paragraph lengths unpredictably\n- Use subheadings that sound conversational\n- Include unexpected format breaks\n- Add natural repetitions for emphasis\n- Let the conclusion emerge naturally, not formally",
31
+
32
+ "Most importantly: Don't be perfect. Be human. Be yourself."
33
  ],
34
  markdown=True,
35
  show_tool_calls=True,
36
  add_datetime_to_instructions=True,
37
  )
38
 
 
 
39
  # Streamlit app
40
  def main():
41
+ st.title("Natural Writing Article Generator")
42
+ st.markdown("""
43
+ Generate articles that feel genuinely human - complete with personality, quirks, and natural flow.
44
+ """)
45
 
46
  topic = st.text_input("Enter your article topic:",
47
+ placeholder="e.g., Why do we all hate the sound of our own voice?")
48
 
49
  if st.button("Generate Article"):
50
  if topic:
51
+ with st.spinner("Writing your article (taking time to make it feel natural)..."):
52
  response = agent.run(
53
+ f"Write a naturally flowing article about: {topic}\n\n"
54
  "Remember:\n"
55
+ "- Write like you're sharing fascinating discoveries with a friend\n"
56
+ "- Include your personal journey of researching this topic\n"
57
+ "- Add natural digressions and personality quirks\n"
58
+ "- Share genuine reactions and thoughts\n"
59
+ "- Let the structure be organic, not rigid\n"
60
+ "- Include real stories and examples\n"
61
+ "- Write with authentic enthusiasm"
62
  )
63
 
64
+ st.markdown("## Your Article")
65
  st.markdown(response.content)
66
 
67
  # Add download button
68
  st.download_button(
69
  label="Download Article (Markdown)",
70
  data=response.content,
71
+ file_name=f"{topic.lower().replace(' ', '-')}-article.md",
72
  mime="text/markdown"
73
  )
74
  else:
 
76
 
77
  if __name__ == "__main__":
78
  main()