Manasa1 commited on
Commit
f9645ac
·
verified ·
1 Parent(s): f1e2308

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -41
app.py CHANGED
@@ -4,27 +4,32 @@ from phi.model.groq import Groq
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
- # Set up the AI agent to generate more natural, human-like writing
14
  agent = Agent(
15
- model=Groq(id="llama-3.3-70b-specdec", api_key=os.getenv("GROQ_API_KEY")),
16
  tools=[DuckDuckGo(), Newspaper4k()],
17
- description="Write in a way that sounds like a real person. No robotic structures, just natural and engaging storytelling.",
18
  instructions=[
19
- "Keep it simple and conversational, like you're talking to a friend.",
20
- "No fancy words or robotic phrasing—just natural language.",
21
- "Vary sentence lengths, throw in a casual phrase, and keep it real.",
22
- "If something surprises you, react to it. If it's boring, say so.",
23
- "Don't force perfect grammar—if a sentence feels better as a fragment, go with it.",
24
- "Make it fun. A little humor, a tiny rant, or a personal touch goes a long way.",
25
- "Talk to the reader. Use 'you' and 'we' to make it feel more personal.",
26
- "If a fact sounds weird, acknowledge it. If a statement is bold, justify it.",
27
- "Bottom line: Make it sound like something a real person actually wrote.",
 
 
 
 
 
 
28
  ],
29
  markdown=True,
30
  show_tool_calls=True,
@@ -33,38 +38,35 @@ agent = Agent(
33
 
34
  # Streamlit app
35
  def main():
36
- st.title("📝 Human-Like Article Generator")
37
- st.markdown("Get articles that actually sound like a person wrote them—natural, engaging, and fun.")
38
-
39
- topic = st.text_input(
40
- "Enter your article topic:",
41
- placeholder="e.g., Why do we all hate the sound of our own voice?"
42
- )
43
-
44
  if st.button("Generate Article"):
45
  if topic:
46
- with st.spinner("Writing your article... (Making it sound as real as possible)"):
 
 
 
 
 
 
 
 
 
 
 
47
 
48
- # Human-like prompt variations
49
- prompt_variations = [
50
- f"Write an article on {topic} like you're explaining it to a friend over coffee.",
51
- f"Tell a story about {topic}. Keep it casual, engaging, and easy to read.",
52
- f"Write a fun, natural article on {topic}—no robotic tone, just real talk.",
53
- ]
54
- prompt = random.choice(prompt_variations)
55
-
56
- response = agent.run(prompt)
57
-
58
- st.markdown("## 📝 Your Naturally Written Article")
59
  st.markdown(response.content)
60
-
61
- # Provide a regeneration option
62
- if st.button("Regenerate Article"):
63
- st.experimental_rerun()
64
-
65
- # Download option
66
  st.download_button(
67
- label="📥 Download Article (Markdown)",
68
  data=response.content,
69
  file_name=f"{topic.lower().replace(' ', '-')}-article.md",
70
  mime="text/markdown"
@@ -73,4 +75,4 @@ def main():
73
  st.warning("Please enter a topic.")
74
 
75
  if __name__ == "__main__":
76
- main()
 
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 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
 
 
 
 
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
  st.warning("Please enter a topic.")
76
 
77
  if __name__ == "__main__":
78
+ main()