Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from crewai import Agent, Task, Crew, Process
|
4 |
+
from langchain_groq import ChatGroq
|
5 |
+
from langchain.tools import DuckDuckGoSearchRun
|
6 |
+
|
7 |
+
# Initialize the GROQ language model
|
8 |
+
groq_llm = ChatGroq(
|
9 |
+
groq_api_key=os.environ["GROQ_API_KEY"],
|
10 |
+
model_name="mixtral-8x7b-32768"
|
11 |
+
)
|
12 |
+
|
13 |
+
# Initialize the search tool
|
14 |
+
search_tool = DuckDuckGoSearchRun()
|
15 |
+
|
16 |
+
# Create agents
|
17 |
+
researcher = Agent(
|
18 |
+
role='Senior Researcher',
|
19 |
+
goal='Conduct thorough research on given topics',
|
20 |
+
backstory='You are an experienced researcher with a keen eye for detail and the ability to find relevant information quickly.',
|
21 |
+
verbose=True,
|
22 |
+
allow_delegation=False,
|
23 |
+
llm=groq_llm,
|
24 |
+
tools=[search_tool]
|
25 |
+
)
|
26 |
+
|
27 |
+
writer = Agent(
|
28 |
+
role='Content Writer',
|
29 |
+
goal='Create engaging and informative content based on research',
|
30 |
+
backstory='You are a skilled writer capable of turning complex information into easily understandable and engaging content.',
|
31 |
+
verbose=True,
|
32 |
+
allow_delegation=False,
|
33 |
+
llm=groq_llm
|
34 |
+
)
|
35 |
+
|
36 |
+
editor = Agent(
|
37 |
+
role='Editor',
|
38 |
+
goal='Refine and improve the written content',
|
39 |
+
backstory='You are a meticulous editor with a strong command of language and an eye for clarity and coherence.',
|
40 |
+
verbose=True,
|
41 |
+
allow_delegation=False,
|
42 |
+
llm=groq_llm
|
43 |
+
)
|
44 |
+
|
45 |
+
def create_crew(query):
|
46 |
+
# Create tasks
|
47 |
+
research_task = Task(
|
48 |
+
description=f"Research the following topic thoroughly: {query}",
|
49 |
+
agent=researcher
|
50 |
+
)
|
51 |
+
|
52 |
+
writing_task = Task(
|
53 |
+
description="Write an informative article based on the research conducted",
|
54 |
+
agent=writer
|
55 |
+
)
|
56 |
+
|
57 |
+
editing_task = Task(
|
58 |
+
description="Review and refine the written article, ensuring clarity, coherence, and engagement",
|
59 |
+
agent=editor
|
60 |
+
)
|
61 |
+
|
62 |
+
# Create the crew
|
63 |
+
crew = Crew(
|
64 |
+
agents=[researcher, writer, editor],
|
65 |
+
tasks=[research_task, writing_task, editing_task],
|
66 |
+
verbose=2,
|
67 |
+
process=Process.sequential
|
68 |
+
)
|
69 |
+
|
70 |
+
return crew
|
71 |
+
|
72 |
+
def process_query(query):
|
73 |
+
crew = create_crew(query)
|
74 |
+
result = crew.kickoff()
|
75 |
+
return result
|
76 |
+
|
77 |
+
# Create Gradio interface
|
78 |
+
iface = gr.Interface(
|
79 |
+
fn=process_query,
|
80 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your query here..."),
|
81 |
+
outputs=gr.Textbox(lines=10, label="AI Agent Response"),
|
82 |
+
title="AI Agent Chatbot",
|
83 |
+
description="Ask a question or provide a topic, and our AI agents will research, write, and edit a response for you."
|
84 |
+
)
|
85 |
+
|
86 |
+
iface.launch()
|