typesdigital commited on
Commit
142690e
·
verified ·
1 Parent(s): 40fbbdd

Create app.py

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