Ishanpardeshi commited on
Commit
6c7d301
·
verified ·
1 Parent(s): d1f170f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -26
app.py CHANGED
@@ -143,10 +143,10 @@ class AgentLoader:
143
  return DocsReader
144
 
145
  async def writerAgent():
146
- writer=Agent(
147
  role='Content Writer',
148
  goal='To produce higly accurate and easy to understand information',
149
- 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.
150
  You should provide indetail results on the summary data.""",
151
  verbose=True,
152
  llm=llm
@@ -156,16 +156,18 @@ class AgentLoader:
156
  #<------------------------------Agents END------------------------->
157
 
158
  #<-------------------------------Tasks---------------------------->
159
- def getTasks(query, agent, exp):
160
- task_read=Task(
161
  description=f'{query}',
162
  agent=agent,
163
  expected_output=f'A detailed information on {query}'
164
  )
165
 
166
- task_write=Task(
 
 
167
  description=f'{query}',
168
- agent=AgentLoader.writerAgent(),
169
  expected_output=exp
170
  )
171
 
@@ -174,29 +176,32 @@ def getTasks(query, agent, exp):
174
  # Gradio interface function
175
  def process_file(file, query, expected_output):
176
  path = file.name
177
-
178
- if path.endswith(".pdf"):
179
- agent = AgentLoader.PdfReaderAgent(path)
180
- elif path.endswith(".docx"):
181
- agent = AgentLoader.DocsReaderAgent(path)
182
- elif path.endswith(".json") or path.endswith(".txt"):
183
- agent = AgentLoader.fileReaderAgent(path)
184
- elif path.endswith(".csv"):
185
- agent = AgentLoader.csvReaderAgent(path)
186
- results = agent.run(query)
187
- else:
188
- return 'File NOT supported'
189
-
190
- if not path.endswith(".csv"):
191
- task1 = getTasks(query, agent, expected_output)
 
192
  mycrew = Crew(
193
- agents=[agent, AgentLoader.writerAgent()],
194
- tasks=task1,
195
  verbose=True
196
  )
197
  results = mycrew.kickoff()
198
-
199
- return results
 
 
200
 
201
  # Create the Gradio interface
202
  interface = gr.Interface(
@@ -213,4 +218,3 @@ interface = gr.Interface(
213
 
214
  # Launch the Gradio interface
215
  interface.launch()
216
-
 
143
  return DocsReader
144
 
145
  async def writerAgent():
146
+ writer = Agent(
147
  role='Content Writer',
148
  goal='To produce higly accurate and easy to understand information',
149
+ backstory="""You are a content specialist and are responsible to generate reliable and easy to understand content or information based on the summary of data.
150
  You should provide indetail results on the summary data.""",
151
  verbose=True,
152
  llm=llm
 
156
  #<------------------------------Agents END------------------------->
157
 
158
  #<-------------------------------Tasks---------------------------->
159
+ async def getTasks(query, agent, exp):
160
+ task_read = Task(
161
  description=f'{query}',
162
  agent=agent,
163
  expected_output=f'A detailed information on {query}'
164
  )
165
 
166
+ writer_agent = await AgentLoader.writerAgent()
167
+
168
+ task_write = Task(
169
  description=f'{query}',
170
+ agent=writer_agent,
171
  expected_output=exp
172
  )
173
 
 
176
  # Gradio interface function
177
  def process_file(file, query, expected_output):
178
  path = file.name
179
+
180
+ async def process_async():
181
+ if path.endswith(".pdf"):
182
+ agent = await AgentLoader.PdfReaderAgent(path)
183
+ elif path.endswith(".docx"):
184
+ agent = await AgentLoader.DocsReaderAgent(path)
185
+ elif path.endswith(".json") or path.endswith(".txt"):
186
+ agent = await AgentLoader.fileReaderAgent(path)
187
+ elif path.endswith(".csv"):
188
+ agent = await AgentLoader.csvReaderAgent(path)
189
+ results = agent.run(query)
190
+ return results
191
+ else:
192
+ return 'File NOT supported'
193
+
194
+ tasks = await getTasks(query, agent, expected_output)
195
  mycrew = Crew(
196
+ agents=[agent, await AgentLoader.writerAgent()],
197
+ tasks=tasks,
198
  verbose=True
199
  )
200
  results = mycrew.kickoff()
201
+ return results
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(
 
218
 
219
  # Launch the Gradio interface
220
  interface.launch()