Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,32 +4,26 @@ from phi.model.groq import Groq
|
|
4 |
from phi.tools.duckduckgo import DuckDuckGo
|
5 |
from phi.tools.newspaper4k import Newspaper4k
|
6 |
import os
|
|
|
7 |
from dotenv import load_dotenv
|
8 |
|
9 |
# Load environment variables
|
10 |
load_dotenv()
|
11 |
|
12 |
-
# Create the Agent with
|
13 |
agent = Agent(
|
14 |
-
model=Groq(id="
|
15 |
tools=[DuckDuckGo(), Newspaper4k()],
|
16 |
-
description="
|
17 |
instructions=[
|
18 |
-
"Write
|
19 |
-
|
20 |
-
"
|
21 |
-
|
22 |
-
"
|
23 |
-
|
24 |
-
"
|
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,35 +32,40 @@ agent = Agent(
|
|
38 |
|
39 |
# Streamlit app
|
40 |
def main():
|
41 |
-
st.title("
|
42 |
st.markdown("""
|
43 |
-
Generate articles that
|
44 |
""")
|
45 |
-
|
46 |
-
topic = st.text_input(
|
47 |
-
|
48 |
-
|
|
|
|
|
49 |
if st.button("Generate Article"):
|
50 |
if topic:
|
51 |
-
with st.spinner("Writing your article (
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
st.markdown(response.content)
|
66 |
-
|
67 |
-
#
|
|
|
|
|
|
|
|
|
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"
|
@@ -75,4 +74,4 @@ def main():
|
|
75 |
st.warning("Please enter a topic.")
|
76 |
|
77 |
if __name__ == "__main__":
|
78 |
-
main()
|
|
|
4 |
from phi.tools.duckduckgo import DuckDuckGo
|
5 |
from phi.tools.newspaper4k import Newspaper4k
|
6 |
import os
|
7 |
+
import random
|
8 |
from dotenv import load_dotenv
|
9 |
|
10 |
# Load environment variables
|
11 |
load_dotenv()
|
12 |
|
13 |
+
# Create the Agent with a Medium-optimized writing style
|
14 |
agent = Agent(
|
15 |
+
model=Groq(id="llama-3.1-8b-instant", api_key=os.getenv("GROQ_API_KEY")),
|
16 |
tools=[DuckDuckGo(), Newspaper4k()],
|
17 |
+
description="Write in an engaging, insightful, and well-structured way—like a top Medium writer.",
|
18 |
instructions=[
|
19 |
+
"Write as if you're a professional Medium writer—engaging, insightful, and structured.",
|
20 |
+
"Blend storytelling with analysis. Open with an interesting hook or personal anecdote, then lead into the core insights.",
|
21 |
+
"Use a warm, personal tone but keep the writing polished. Avoid excessive slang or overly casual phrases.",
|
22 |
+
"Make the article skimmable—use subheadings, bullet points, and occasional bold highlights.",
|
23 |
+
"Add thoughtful insights, researched points, and real-world examples to support your arguments.",
|
24 |
+
"Use smooth transitions and natural paragraph breaks. Keep readers engaged without being too rigid.",
|
25 |
+
"Write with a clear introduction, a well-developed body, and a natural conclusion that leaves readers with a takeaway.",
|
26 |
+
"Most importantly, make the reader feel like they’ve gained something valuable—whether a new perspective, useful knowledge, or an interesting story.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
],
|
28 |
markdown=True,
|
29 |
show_tool_calls=True,
|
|
|
32 |
|
33 |
# Streamlit app
|
34 |
def main():
|
35 |
+
st.title("📝 Medium-Optimized Article Generator")
|
36 |
st.markdown("""
|
37 |
+
Generate articles that are engaging, well-structured, and ready for Medium's audience.
|
38 |
""")
|
39 |
+
|
40 |
+
topic = st.text_input(
|
41 |
+
"Enter your article topic:",
|
42 |
+
placeholder="e.g., Why do we all hate the sound of our own voice?"
|
43 |
+
)
|
44 |
+
|
45 |
if st.button("Generate Article"):
|
46 |
if topic:
|
47 |
+
with st.spinner("Writing your article... (Expect a thoughtful, engaging piece)"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
+
# Medium-friendly prompt variations
|
50 |
+
prompt_variations = [
|
51 |
+
f"Write a well-structured Medium article about {topic}. Open with an engaging hook, share insights, and conclude with a strong takeaway.",
|
52 |
+
f"Create a compelling Medium-style article on {topic}. Use storytelling, clear structure, and a warm yet professional tone.",
|
53 |
+
f"Write an insightful and engaging blog post about {topic}, optimized for Medium. Blend personal storytelling with research-backed insights.",
|
54 |
+
]
|
55 |
+
prompt = random.choice(prompt_variations)
|
56 |
+
|
57 |
+
response = agent.run(prompt)
|
58 |
+
|
59 |
+
st.markdown("## 📝 Your Medium-Ready Article")
|
60 |
st.markdown(response.content)
|
61 |
+
|
62 |
+
# Provide a regeneration option
|
63 |
+
if st.button("Regenerate Article"):
|
64 |
+
st.experimental_rerun()
|
65 |
+
|
66 |
+
# Download option
|
67 |
st.download_button(
|
68 |
+
label="📥 Download Article (Markdown)",
|
69 |
data=response.content,
|
70 |
file_name=f"{topic.lower().replace(' ', '-')}-article.md",
|
71 |
mime="text/markdown"
|
|
|
74 |
st.warning("Please enter a topic.")
|
75 |
|
76 |
if __name__ == "__main__":
|
77 |
+
main()
|