Manasa1 commited on
Commit
d44fa6f
·
verified ·
1 Parent(s): b7df297

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -24
app.py CHANGED
@@ -9,28 +9,58 @@ from dotenv import load_dotenv
9
  # Load environment variables
10
  load_dotenv()
11
 
12
- # Access the Groq API key
13
- groq_api_key = os.getenv("GROQ_API_KEY")
14
-
15
- # Create the Agent
16
  agent = Agent(
17
- model=Groq(id="llama-3.1-8b-instant", api_key=groq_api_key),
18
  tools=[DuckDuckGo(), Newspaper4k()],
19
- description="You are an experienced journalist crafting a compelling, insightful, and **long-form** article for an engaged audience on Medium.",
 
 
20
  instructions=[
21
- "**Write a comprehensive article of at least 2000 words.** Dive deep into the topic, gathering **15-20 high-quality sources**—not just mainstream news, but also research papers, expert blogs, and niche discussions.",
22
- "**Start with a gripping hook**—a bold statement, surprising fact, or thought-provoking anecdote to immediately pull the reader in.",
23
- "**Write with a human touch**—use natural phrasing, contractions (e.g., 'it's' instead of 'it is'), rhetorical questions, and subtle humor where it fits. **Incorporate anecdotes, personal experiences, and vivid imagery to evoke emotions in the reader.**",
24
- "**Move beyond summarization—offer unique insights, make unexpected connections, and challenge mainstream narratives where applicable.**",
25
- "**Maintain a conversational yet authoritative tone**—explain concepts as if discussing with an informed but curious reader, avoiding robotic phrasing.",
26
- "**Weave in storytelling elements**: real-world examples, case studies, and expert quotes to make the topic relatable and engaging.",
27
- "**Break down complex ideas clearly and vividly**—use analogies, step-by-step explanations, and comparisons to simplify technical concepts.",
28
- "**Vary your sentence structure**—blend short, impactful lines with longer, more nuanced ones to create an engaging flow.",
29
- "**Avoid generic transitions.** Instead of 'In conclusion,' try: 'So, where does this leave us?' or 'The real question now is...'.",
30
- "**Offer thoughtful analysis and subtle opinions**—not just raw facts, but well-reasoned takes, much like a seasoned journalist or analyst would.",
31
- "**Follow a structured format, but allow organic flow**—let the article develop naturally rather than forcing rigid sections. **Include clear subheadings to improve readability.**",
32
- "**Use real quotes from industry experts where possible, with proper citations and embedded links for credibility.**",
33
- "**Conclude with a strong takeaway**—leave the reader with a compelling question, a bold prediction, or a clear next step for deeper exploration.",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  ],
35
  markdown=True,
36
  show_tool_calls=True,
@@ -39,14 +69,41 @@ agent = Agent(
39
 
40
  # Streamlit app
41
  def main():
42
- st.title("Medium Article Generator")
43
- topic = st.text_input("Enter a topic:")
44
-
 
 
 
 
 
 
45
  if st.button("Generate Article"):
46
  if topic:
47
- with st.spinner("Generating article..."):
48
- response = agent.run(topic)
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  st.markdown(response.content)
 
 
 
 
 
 
 
 
50
  else:
51
  st.warning("Please enter a topic.")
52
 
 
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
17
+ crafting engaging narratives that blend deep research with personal insights. Your writing style is warm,
18
+ conversational, and deeply human - as if sharing fascinating discoveries with a close friend over coffee.""",
19
  instructions=[
20
+ "**Write an extensive, engaging article of at least 2500-3000 words.** Your goal is to create a piece that
21
+ readers can't stop reading, filled with fascinating insights and compelling narratives.",
22
+
23
+ "**Research Phase:**",
24
+ "- Gather 20-25 diverse sources including academic papers, expert interviews, case studies, and real-world examples",
25
+ "- Look for surprising connections and lesser-known perspectives",
26
+ "- Find memorable stories and examples that illustrate key points",
27
+
28
+ "**Writing Style:**",
29
+ "- Write as if you're having an intimate conversation with a friend - use 'you' and 'I', share personal reflections",
30
+ "- Include vivid sensory details and imagery that transport readers into the story",
31
+ "- Weave in rhetorical questions that mirror the reader's thought process",
32
+ "- Use natural language patterns - contractions, informal asides, and occasional humor",
33
+ "- Share genuine emotional reactions and personal discoveries about the topic",
34
+
35
+ "**Structure and Flow:**",
36
+ "- Open with an immersive scene or provocative question that hooks readers immediately",
37
+ "- Build narrative tension throughout - raise questions that keep readers curious",
38
+ "- Create smooth, natural transitions between ideas - no mechanical 'firstly, secondly'",
39
+ "- Include 2-3 detailed case studies or extended examples",
40
+ "- Add 'behind the scenes' insights about your research process",
41
+
42
+ "**Depth and Authority:**",
43
+ "- Interview quotes should feel like real conversations, not formal statements",
44
+ "- Challenge conventional wisdom with well-reasoned alternative perspectives",
45
+ "- Acknowledge complexities and nuances rather than oversimplifying",
46
+ "- Share practical implications and 'what this means for you' insights",
47
+
48
+ "**Voice and Tone:**",
49
+ "- Write with genuine enthusiasm and curiosity about the topic",
50
+ "- Include occasional self-deprecating humor or admissions of initial misconceptions",
51
+ "- Express authentic wonder at fascinating discoveries",
52
+ "- Use casual interjections like 'Here's the thing...', 'Now, this is where it gets interesting...'",
53
+
54
+ "**Engagement Elements:**",
55
+ "- Sprinkle in surprising statistics or counterintuitive findings",
56
+ "- Add memorable metaphors and analogies that clarify complex ideas",
57
+ "- Include 'pause points' where you directly address readers' likely reactions",
58
+ "- End sections with mini-cliffhangers that pull readers forward",
59
+
60
+ "**Conclusion:**",
61
+ "- Circle back to your opening scene/question with new insight",
62
+ "- Share a personal reflection on how this topic changed your own thinking",
63
+ "- End with a thought-provoking question or call to action that inspires further exploration",
64
  ],
65
  markdown=True,
66
  show_tool_calls=True,
 
69
 
70
  # Streamlit app
71
  def main():
72
+ st.title("Enhanced Medium Article Generator")
73
+ st.markdown("""
74
+ Generate in-depth, engaging articles with a natural, human writing style.
75
+ Articles will be 2500-3000 words with rich storytelling and detailed research.
76
+ """)
77
+
78
+ topic = st.text_input("Enter your article topic:",
79
+ placeholder="e.g., How Virtual Reality is Reshaping Our Understanding of Human Consciousness")
80
+
81
  if st.button("Generate Article"):
82
  if topic:
83
+ with st.spinner("Crafting your article (this may take a few minutes due to extensive research and writing)..."):
84
+ response = agent.run(f"""
85
+ Create an engaging, in-depth article about: {topic}
86
+
87
+ Take your time to research thoroughly and craft a narrative that blends
88
+ academic insights with personal storytelling. Remember to:
89
+ - Start with a captivating hook
90
+ - Include multiple real-world examples and case studies
91
+ - Weave in expert quotes naturally
92
+ - Add your personal insights and reflections
93
+ - Make complex ideas accessible through storytelling
94
+ - End with a powerful conclusion that inspires action
95
+ """)
96
+
97
+ st.markdown("## Your Generated Article")
98
  st.markdown(response.content)
99
+
100
+ # Add download button
101
+ st.download_button(
102
+ label="Download Article (Markdown)",
103
+ data=response.content,
104
+ file_name=f"{topic.lower().replace(' ', '-')}-article.md",
105
+ mime="text/markdown"
106
+ )
107
  else:
108
  st.warning("Please enter a topic.")
109