Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,6 @@ from crewai_tools import PDFSearchTool, FileReadTool, DOCXSearchTool, CSVSearchT
|
|
7 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
8 |
from langchain.agents.agent_types import AgentType
|
9 |
from langchain_experimental.agents.agent_toolkits import create_csv_agent
|
10 |
-
import asyncio
|
11 |
|
12 |
# API keys-----------------move them to ENV
|
13 |
os.environ["OPENAI_API_KEY"] = "NA"
|
@@ -91,7 +90,7 @@ class tools:
|
|
91 |
|
92 |
class AgentLoader:
|
93 |
|
94 |
-
|
95 |
agent = create_csv_agent(
|
96 |
ChatGoogleGenerativeAI(temperature=0.6, model="gemini-1.5-flash-latest"),
|
97 |
path,
|
@@ -100,7 +99,7 @@ class AgentLoader:
|
|
100 |
)
|
101 |
return agent
|
102 |
|
103 |
-
|
104 |
FileReader = Agent(
|
105 |
role='File searcher',
|
106 |
goal='To analyse and generate optimal and reliable results',
|
@@ -114,7 +113,7 @@ class AgentLoader:
|
|
114 |
)
|
115 |
return FileReader
|
116 |
|
117 |
-
|
118 |
PdfReader = Agent(
|
119 |
role='PDF searcher',
|
120 |
goal='To analyse and generate optimal and reliable results',
|
@@ -128,7 +127,7 @@ class AgentLoader:
|
|
128 |
)
|
129 |
return PdfReader
|
130 |
|
131 |
-
|
132 |
DocsReader = Agent(
|
133 |
role='Docs searcher',
|
134 |
goal='To analyse and generate optimal and reliable results',
|
@@ -142,11 +141,11 @@ class AgentLoader:
|
|
142 |
)
|
143 |
return DocsReader
|
144 |
|
145 |
-
|
146 |
-
writer
|
147 |
role='Content Writer',
|
148 |
goal='To produce higly accurate and easy to understand information',
|
149 |
-
backstory="""You are
|
150 |
You should provide indetail results on the summary data.""",
|
151 |
verbose=True,
|
152 |
llm=llm
|
@@ -156,18 +155,16 @@ class AgentLoader:
|
|
156 |
#<------------------------------Agents END------------------------->
|
157 |
|
158 |
#<-------------------------------Tasks---------------------------->
|
159 |
-
|
160 |
-
task_read
|
161 |
description=f'{query}',
|
162 |
agent=agent,
|
163 |
expected_output=f'A detailed information on {query}'
|
164 |
)
|
165 |
|
166 |
-
|
167 |
-
|
168 |
-
task_write = Task(
|
169 |
description=f'{query}',
|
170 |
-
agent=
|
171 |
expected_output=exp
|
172 |
)
|
173 |
|
@@ -176,32 +173,29 @@ async def getTasks(query, agent, exp):
|
|
176 |
# Gradio interface function
|
177 |
def process_file(file, query, expected_output):
|
178 |
path = file.name
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
tasks = await getTasks(query, agent, expected_output)
|
195 |
mycrew = Crew(
|
196 |
-
agents=[agent,
|
197 |
-
tasks=
|
198 |
verbose=True
|
199 |
)
|
200 |
results = mycrew.kickoff()
|
201 |
-
|
202 |
-
|
203 |
-
loop = asyncio.get_event_loop()
|
204 |
-
return loop.run_until_complete(process_async())
|
205 |
|
206 |
# Create the Gradio interface
|
207 |
interface = gr.Interface(
|
|
|
7 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
8 |
from langchain.agents.agent_types import AgentType
|
9 |
from langchain_experimental.agents.agent_toolkits import create_csv_agent
|
|
|
10 |
|
11 |
# API keys-----------------move them to ENV
|
12 |
os.environ["OPENAI_API_KEY"] = "NA"
|
|
|
90 |
|
91 |
class AgentLoader:
|
92 |
|
93 |
+
def csvReaderAgent(path):
|
94 |
agent = create_csv_agent(
|
95 |
ChatGoogleGenerativeAI(temperature=0.6, model="gemini-1.5-flash-latest"),
|
96 |
path,
|
|
|
99 |
)
|
100 |
return agent
|
101 |
|
102 |
+
def fileReaderAgent(path):
|
103 |
FileReader = Agent(
|
104 |
role='File searcher',
|
105 |
goal='To analyse and generate optimal and reliable results',
|
|
|
113 |
)
|
114 |
return FileReader
|
115 |
|
116 |
+
def PdfReaderAgent(path):
|
117 |
PdfReader = Agent(
|
118 |
role='PDF searcher',
|
119 |
goal='To analyse and generate optimal and reliable results',
|
|
|
127 |
)
|
128 |
return PdfReader
|
129 |
|
130 |
+
def DocsReaderAgent(path):
|
131 |
DocsReader = Agent(
|
132 |
role='Docs searcher',
|
133 |
goal='To analyse and generate optimal and reliable results',
|
|
|
141 |
)
|
142 |
return DocsReader
|
143 |
|
144 |
+
def writerAgent():
|
145 |
+
writer=Agent(
|
146 |
role='Content Writer',
|
147 |
goal='To produce higly accurate and easy to understand information',
|
148 |
+
backstory="""You are an content specialist and are respinsible to generate reliable and easy to understand content or information based on the summary of data.
|
149 |
You should provide indetail results on the summary data.""",
|
150 |
verbose=True,
|
151 |
llm=llm
|
|
|
155 |
#<------------------------------Agents END------------------------->
|
156 |
|
157 |
#<-------------------------------Tasks---------------------------->
|
158 |
+
def getTasks(query, agent, exp):
|
159 |
+
task_read=Task(
|
160 |
description=f'{query}',
|
161 |
agent=agent,
|
162 |
expected_output=f'A detailed information on {query}'
|
163 |
)
|
164 |
|
165 |
+
task_write=Task(
|
|
|
|
|
166 |
description=f'{query}',
|
167 |
+
agent=AgentLoader.writerAgent(),
|
168 |
expected_output=exp
|
169 |
)
|
170 |
|
|
|
173 |
# Gradio interface function
|
174 |
def process_file(file, query, expected_output):
|
175 |
path = file.name
|
176 |
+
|
177 |
+
if path.endswith(".pdf"):
|
178 |
+
agent = AgentLoader.PdfReaderAgent(path)
|
179 |
+
elif path.endswith(".docx"):
|
180 |
+
agent = AgentLoader.DocsReaderAgent(path)
|
181 |
+
elif path.endswith(".json") or path.endswith(".txt"):
|
182 |
+
agent = AgentLoader.fileReaderAgent(path)
|
183 |
+
elif path.endswith(".csv"):
|
184 |
+
agent = AgentLoader.csvReaderAgent(path)
|
185 |
+
results = agent.run(query)
|
186 |
+
else:
|
187 |
+
return 'File NOT supported'
|
188 |
+
|
189 |
+
if not path.endswith(".csv"):
|
190 |
+
task1 = getTasks(query, agent, expected_output)
|
|
|
191 |
mycrew = Crew(
|
192 |
+
agents=[agent, AgentLoader.writerAgent()],
|
193 |
+
tasks=task1,
|
194 |
verbose=True
|
195 |
)
|
196 |
results = mycrew.kickoff()
|
197 |
+
|
198 |
+
return results
|
|
|
|
|
199 |
|
200 |
# Create the Gradio interface
|
201 |
interface = gr.Interface(
|