Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ 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 |
|
| 11 |
# API keys-----------------move them to ENV
|
| 12 |
os.environ["OPENAI_API_KEY"] = "NA"
|
|
@@ -90,8 +91,9 @@ class tools:
|
|
| 90 |
|
| 91 |
class AgentLoader:
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
|
|
|
| 95 |
ChatGoogleGenerativeAI(temperature=0.6, model="gemini-1.5-flash-latest"),
|
| 96 |
path,
|
| 97 |
verbose=True,
|
|
@@ -171,7 +173,7 @@ def getTasks(query, agent, exp):
|
|
| 171 |
return [task_read, task_write]
|
| 172 |
|
| 173 |
# Gradio interface function
|
| 174 |
-
def process_file(file, query, expected_output):
|
| 175 |
path = file.name
|
| 176 |
|
| 177 |
if path.endswith(".pdf"):
|
|
@@ -181,8 +183,8 @@ def process_file(file, query, expected_output):
|
|
| 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 |
-
|
| 186 |
else:
|
| 187 |
return 'File NOT supported'
|
| 188 |
|
|
@@ -199,7 +201,7 @@ def process_file(file, query, expected_output):
|
|
| 199 |
|
| 200 |
# Create the Gradio interface
|
| 201 |
interface = gr.Interface(
|
| 202 |
-
fn=process_file,
|
| 203 |
inputs=[
|
| 204 |
gr.File(label="Upload File"),
|
| 205 |
gr.Textbox(label="Query"),
|
|
|
|
| 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 |
|
| 92 |
class AgentLoader:
|
| 93 |
|
| 94 |
+
@staticmethod
|
| 95 |
+
async def csvReaderAgent(path):
|
| 96 |
+
agent = await create_csv_agent(
|
| 97 |
ChatGoogleGenerativeAI(temperature=0.6, model="gemini-1.5-flash-latest"),
|
| 98 |
path,
|
| 99 |
verbose=True,
|
|
|
|
| 173 |
return [task_read, task_write]
|
| 174 |
|
| 175 |
# Gradio interface function
|
| 176 |
+
async def process_file(file, query, expected_output):
|
| 177 |
path = file.name
|
| 178 |
|
| 179 |
if path.endswith(".pdf"):
|
|
|
|
| 183 |
elif path.endswith(".json") or path.endswith(".txt"):
|
| 184 |
agent = AgentLoader.fileReaderAgent(path)
|
| 185 |
elif path.endswith(".csv"):
|
| 186 |
+
agent = await AgentLoader.csvReaderAgent(path)
|
| 187 |
+
results = agent.run(query)
|
| 188 |
else:
|
| 189 |
return 'File NOT supported'
|
| 190 |
|
|
|
|
| 201 |
|
| 202 |
# Create the Gradio interface
|
| 203 |
interface = gr.Interface(
|
| 204 |
+
fn=lambda file, query, expected_output: asyncio.run(process_file(file, query, expected_output)),
|
| 205 |
inputs=[
|
| 206 |
gr.File(label="Upload File"),
|
| 207 |
gr.Textbox(label="Query"),
|