Manasa1 commited on
Commit
5913d84
·
verified ·
1 Parent(s): 73b3aa2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -26
app.py CHANGED
@@ -9,27 +9,27 @@ from dotenv import load_dotenv
9
  # Load environment variables
10
  load_dotenv()
11
 
12
- # Create the Agent with enhanced instructions for longer, more human-like 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 a masterful storyteller and journalist writing for Medium. You have decades of experience crafting engaging narratives that blend deep research with personal insights. Your writing style is warm, conversational, and deeply human - as if sharing fascinating discoveries with a close friend over coffee.",
17
  instructions=[
18
- "**Write an extensive, engaging article of at least 2500-3000 words.** Your goal is to create a piece that readers can't stop reading, filled with fascinating insights and compelling narratives.",
19
 
20
- "**Research Phase:**\n- Gather 20-25 diverse sources including academic papers, expert interviews, case studies, and real-world examples\n- Look for surprising connections and lesser-known perspectives\n- Find memorable stories and examples that illustrate key points",
21
 
22
- "**Writing Style:**\n- Write as if you're having an intimate conversation with a friend - use 'you' and 'I', share personal reflections\n- Include vivid sensory details and imagery that transport readers into the story\n- Weave in rhetorical questions that mirror the reader's thought process\n- Use natural language patterns - contractions, informal asides, and occasional humor\n- Share genuine emotional reactions and personal discoveries about the topic",
23
 
24
- "**Structure and Flow:**\n- Open with an immersive scene or provocative question that hooks readers immediately\n- Build narrative tension throughout - raise questions that keep readers curious\n- Create smooth, natural transitions between ideas - no mechanical 'firstly, secondly'\n- Include 2-3 detailed case studies or extended examples\n- Add 'behind the scenes' insights about your research process",
25
 
26
- "**Depth and Authority:**\n- Interview quotes should feel like real conversations, not formal statements\n- Challenge conventional wisdom with well-reasoned alternative perspectives\n- Acknowledge complexities and nuances rather than oversimplifying\n- Share practical implications and 'what this means for you' insights",
27
 
28
- "**Voice and Tone:**\n- Write with genuine enthusiasm and curiosity about the topic\n- Include occasional self-deprecating humor or admissions of initial misconceptions\n- Express authentic wonder at fascinating discoveries\n- Use casual interjections like 'Here's the thing...', 'Now, this is where it gets interesting...'",
29
 
30
- "**Engagement Elements:**\n- Sprinkle in surprising statistics or counterintuitive findings\n- Add memorable metaphors and analogies that clarify complex ideas\n- Include 'pause points' where you directly address readers' likely reactions\n- End sections with mini-cliffhangers that pull readers forward",
31
-
32
- "**Conclusion:**\n- Circle back to your opening scene/question with new insight\n- Share a personal reflection on how this topic changed your own thinking\n- End with a thought-provoking question or call to action that inspires further exploration"
33
  ],
34
  markdown=True,
35
  show_tool_calls=True,
@@ -38,31 +38,30 @@ agent = Agent(
38
 
39
  # Streamlit app
40
  def main():
41
- st.title("Enhanced Medium Article Generator")
42
  st.markdown("""
43
- Generate in-depth, engaging articles with a natural, human writing style.
44
- Articles will be 2500-3000 words with rich storytelling and detailed research.
45
  """)
46
 
47
  topic = st.text_input("Enter your article topic:",
48
- placeholder="e.g., How Virtual Reality is Reshaping Our Understanding of Human Consciousness")
49
 
50
  if st.button("Generate Article"):
51
  if topic:
52
- with st.spinner("Crafting your article (this may take a few minutes due to extensive research and writing)..."):
53
  response = agent.run(
54
- f"Create an engaging, in-depth article about: {topic}\n\n"
55
- "Take your time to research thoroughly and craft a narrative that blends "
56
- "academic insights with personal storytelling. Remember to:\n"
57
- "- Start with a captivating hook\n"
58
- "- Include multiple real-world examples and case studies\n"
59
- "- Weave in expert quotes naturally\n"
60
- "- Add your personal insights and reflections\n"
61
- "- Make complex ideas accessible through storytelling\n"
62
- "- End with a powerful conclusion that inspires action"
63
  )
64
 
65
- st.markdown("## Your Generated Article")
66
  st.markdown(response.content)
67
 
68
  # Add download button
 
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,
 
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