Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines91011121314151617181920212223242526272829303132333435362 unmodified lines39404142434445464748495051528 unmodified lines# Load environment variablesload_dotenv()# Access the Groq API keygroq_api_key = os.getenv("GROQ_API_KEY")# Create the Agentagent = Agent(model=Groq(id="llama-3.1-8b-instant", api_key=groq_api_key),tools=[DuckDuckGo(), Newspaper4k()],description="You are an experienced journalist crafting a compelling, insightful, and **long-form** article for an engaged audience on Medium.",instructions=["**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.","**Start with a gripping hook**—a bold statement, surprising fact, or thought-provoking anecdote to immediately pull the reader in.","**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.**","**Move beyond summarization—offer unique insights, make unexpected connections, and challenge mainstream narratives where applicable.**","**Maintain a conversational yet authoritative tone**—explain concepts as if discussing with an informed but curious reader, avoiding robotic phrasing.","**Weave in storytelling elements**: real-world examples, case studies, and expert quotes to make the topic relatable and engaging.","**Break down complex ideas clearly and vividly**—use analogies, step-by-step explanations, and comparisons to simplify technical concepts.","**Vary your sentence structure**—blend short, impactful lines with longer, more nuanced ones to create an engaging flow.","**Avoid generic transitions.** Instead of 'In conclusion,' try: 'So, where does this leave us?' or 'The real question now is...'.","**Offer thoughtful analysis and subtle opinions**—not just raw facts, but well-reasoned takes, much like a seasoned journalist or analyst would.","**Follow a structured format, but allow organic flow**—let the article develop naturally rather than forcing rigid sections. **Include clear subheadings to improve readability.**","**Use real quotes from industry experts where possible, with proper citations and embedded links for credibility.**","**Conclude with a strong takeaway**—leave the reader with a compelling question, a bold prediction, or a clear next step for deeper exploration.",],markdown=True,show_tool_calls=True,2 unmodified lines# Streamlit appdef main():st.title("Medium Article Generator")topic = st.text_input("Enter a topic:")if st.button("Generate Article"):if topic:with st.spinner("Generating article..."):response = agent.run(topic)st.markdown(response.content)else:st.warning("Please enter a topic.")8 unmodified lines91011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465662 unmodified lines697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081098 unmodified lines# Load environment variablesload_dotenv()# Create the Agent with enhanced instructions for longer, more human-like writingagent = Agent(model=Groq(id="llama-3.1-8b-instant", api_key=os.getenv("GROQ_API_KEY")),tools=[DuckDuckGo(), Newspaper4k()],description="""You are a masterful storyteller and journalist writing for Medium. You have decades of experiencecrafting 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.""",instructions=["**Write an extensive, engaging article of at least 2500-3000 words.** Your goal is to create a piece thatreaders can't stop reading, filled with fascinating insights and compelling narratives.","**Research Phase:**","- Gather 20-25 diverse sources including academic papers, expert interviews, case studies, and real-world examples","- Look for surprising connections and lesser-known perspectives","- Find memorable stories and examples that illustrate key points","**Writing Style:**","- Write as if you're having an intimate conversation with a friend - use 'you' and 'I', share personal reflections","- Include vivid sensory details and imagery that transport readers into the story","- Weave in rhetorical questions that mirror the reader's thought process","- Use natural language patterns - contractions, informal asides, and occasional humor","- Share genuine emotional reactions and personal discoveries about the topic","**Structure and Flow:**","- Open with an immersive scene or provocative question that hooks readers immediately","- Build narrative tension throughout - raise questions that keep readers curious","- Create smooth, natural transitions between ideas - no mechanical 'firstly, secondly'","- Include 2-3 detailed case studies or extended examples","- Add 'behind the scenes' insights about your research process","**Depth and Authority:**","- Interview quotes should feel like real conversations, not formal statements","- Challenge conventional wisdom with well-reasoned alternative perspectives","- Acknowledge complexities and nuances rather than oversimplifying","- Share practical implications and 'what this means for you' insights","**Voice and Tone:**","- Write with genuine enthusiasm and curiosity about the topic","- Include occasional self-deprecating humor or admissions of initial misconceptions","- Express authentic wonder at fascinating discoveries","- Use casual interjections like 'Here's the thing...', 'Now, this is where it gets interesting...'","**Engagement Elements:**","- Sprinkle in surprising statistics or counterintuitive findings","- Add memorable metaphors and analogies that clarify complex ideas","- Include 'pause points' where you directly address readers' likely reactions","- End sections with mini-cliffhangers that pull readers forward","**Conclusion:**","- Circle back to your opening scene/question with new insight","- Share a personal reflection on how this topic changed your own thinking","- End with a thought-provoking question or call to action that inspires further exploration",],markdown=True,show_tool_calls=True,2 unmodified lines# Streamlit appdef main():st.title("Enhanced Medium Article Generator")st.markdown("""Generate in-depth, engaging articles with a natural, human writing style.Articles will be 2500-3000 words with rich storytelling and detailed research.""")topic = st.text_input("Enter your article topic:",placeholder="e.g., How Virtual Reality is Reshaping Our Understanding of Human Consciousness")if st.button("Generate Article"):if topic:with st.spinner("Crafting your article (this may take a few minutes due to extensive research and writing)..."):response = agent.run(f"""Create an engaging, in-depth article about: {topic}Take your time to research thoroughly and craft a narrative that blendsacademic insights with personal storytelling. Remember to:- Start with a captivating hook- Include multiple real-world examples and case studies- Weave in expert quotes naturally- Add your personal insights and reflections- Make complex ideas accessible through storytelling- End with a powerful conclusion that inspires action""")st.markdown("## Your Generated Article")st.markdown(response.content)# Add download buttonst.download_button(label="Download Article (Markdown)",data=response.content,file_name=f"{topic.lower().replace(' ', '-')}-article.md",mime="text/markdown")else:st.warning("Please enter a topic.")
app.py+81-24