Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,28 +9,58 @@ from dotenv import load_dotenv
|
|
9 |
# Load environment variables
|
10 |
load_dotenv()
|
11 |
|
12 |
-
#
|
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=
|
18 |
tools=[DuckDuckGo(), Newspaper4k()],
|
19 |
-
description="You are
|
|
|
|
|
20 |
instructions=[
|
21 |
-
"**Write
|
22 |
-
|
23 |
-
|
24 |
-
"**
|
25 |
-
"
|
26 |
-
"
|
27 |
-
"
|
28 |
-
|
29 |
-
"**
|
30 |
-
"
|
31 |
-
"
|
32 |
-
"
|
33 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
if st.button("Generate Article"):
|
46 |
if topic:
|
47 |
-
with st.spinner("
|
48 |
-
response = agent.run(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|