typesdigital commited on
Commit
c16406d
·
verified ·
1 Parent(s): bd32a97

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -0
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from crewai import Agent, Task, Crew, Process
4
+ from crewai_tools import SerperDevTool
5
+ from langchain_groq import ChatGroq
6
+
7
+ # Set up environment variables
8
+ os.environ["GROQ_API_KEY"] = "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"
9
+ os.environ["SERPER_API_KEY"] = "206256c6acfbcd5a46195f3312aaa7e8ed38ae5f"
10
+
11
+ # Set up environment variables
12
+ os.environ["GROQ_API_KEY"] = "YOUR_GROQ_API_KEY"
13
+ os.environ["SERPER_API_KEY"] = "YOUR_SERPER_API_KEY"
14
+
15
+ # Initialize Groq LLM
16
+ groq_llm = ChatGroq(
17
+ model_name="mixtral-8x7b-32768",
18
+ temperature=0.7,
19
+ max_tokens=32768
20
+ )
21
+
22
+ # Initialize search tool
23
+ search_tool = SerperDevTool()
24
+
25
+ # Define agents
26
+ researcher = Agent(
27
+ role='Senior Research Analyst',
28
+ goal='Uncover cutting-edge developments in AI and data science',
29
+ backstory="""You work at a leading tech think tank.
30
+ Your expertise lies in identifying emerging trends.
31
+ You have a knack for dissecting complex data and presenting actionable insights.""",
32
+ verbose=True,
33
+ allow_delegation=False,
34
+ llm=groq_llm,
35
+ tools=[search_tool]
36
+ )
37
+
38
+ writer = Agent(
39
+ role='Tech Content Strategist',
40
+ goal='Craft compelling content on tech advancements',
41
+ backstory="""You are a renowned Content Strategist, known for your insightful and engaging articles.
42
+ You transform complex concepts into compelling narratives.""",
43
+ verbose=True,
44
+ allow_delegation=True,
45
+ llm=groq_llm
46
+ )
47
+
48
+ # Create tasks
49
+ def create_tasks(topic):
50
+ task1 = Task(
51
+ description=f"""Conduct a comprehensive analysis of the latest advancements in {topic} in 2024.
52
+ Identify key trends, breakthrough technologies, and potential industry impacts.""",
53
+ expected_output="Full analysis report in bullet points",
54
+ agent=researcher
55
+ )
56
+
57
+ task2 = Task(
58
+ description=f"""Using the insights provided about {topic}, develop an engaging blog
59
+ post that highlights the most significant advancements.
60
+ Your post should be informative yet accessible, catering to a tech-savvy audience.
61
+ Make it sound cool, avoid complex words so it doesn't sound like AI.""",
62
+ expected_output="Full blog post of at least 4 paragraphs",
63
+ agent=writer
64
+ )
65
+
66
+ return [task1, task2]
67
+
68
+ # Function to run the crew
69
+ def run_crew(topic):
70
+ tasks = create_tasks(topic)
71
+ crew = Crew(
72
+ agents=[researcher, writer],
73
+ tasks=tasks,
74
+ verbose=2,
75
+ process=Process.sequential
76
+ )
77
+ result = crew.kickoff()
78
+ return result
79
+
80
+ # Gradio interface
81
+ def gradio_interface(topic):
82
+ result = run_crew(topic)
83
+ return result
84
+
85
+ # Create Gradio interface
86
+ iface = gr.Interface(
87
+ fn=gradio_interface,
88
+ inputs=gr.Textbox(lines=2, placeholder="Enter a topic for AI research and blog writing..."),
89
+ outputs="text",
90
+ title="AI Research and Blog Writing Assistant",
91
+ description="Enter a topic related to AI or technology, and the AI will research it and write a blog post.",
92
+ )
93
+
94
+ # Launch the interface
95
+ iface.launch(share=True)