Spaces:
Runtime error
Runtime error
Adding another class to chat with uploaded document
Browse files- app.py +3 -3
- csv_agent.py +35 -0
app.py
CHANGED
@@ -10,6 +10,7 @@ from dotenv import load_dotenv
|
|
10 |
from langchain.chat_models import ChatOpenAI
|
11 |
from langchain.embeddings import OpenAIEmbeddings
|
12 |
|
|
|
13 |
from grader import Grader
|
14 |
from grader_qa import GraderQA
|
15 |
from ingest import ingest_canvas_discussions
|
@@ -197,14 +198,13 @@ def upload_grading_results(file, history):
|
|
197 |
path = os.path.join("output", os.path.basename(file.name))
|
198 |
# Copy the uploaded file from its temporary location to the desired location
|
199 |
shutil.copyfile(file.name, path)
|
200 |
-
|
201 |
-
grader_qa = GraderQA(grader, embeddings)
|
202 |
history = [(None, 'Grading results uploaded successfully')]
|
203 |
return history
|
204 |
|
205 |
|
206 |
def bot(history):
|
207 |
-
return
|
208 |
|
209 |
|
210 |
with gr.Blocks() as demo:
|
|
|
10 |
from langchain.chat_models import ChatOpenAI
|
11 |
from langchain.embeddings import OpenAIEmbeddings
|
12 |
|
13 |
+
from csv_agent import CSVAgent
|
14 |
from grader import Grader
|
15 |
from grader_qa import GraderQA
|
16 |
from ingest import ingest_canvas_discussions
|
|
|
198 |
path = os.path.join("output", os.path.basename(file.name))
|
199 |
# Copy the uploaded file from its temporary location to the desired location
|
200 |
shutil.copyfile(file.name, path)
|
201 |
+
grader_qa = CSVAgent(llm, embeddings, path)
|
|
|
202 |
history = [(None, 'Grading results uploaded successfully')]
|
203 |
return history
|
204 |
|
205 |
|
206 |
def bot(history):
|
207 |
+
return history
|
208 |
|
209 |
|
210 |
with gr.Blocks() as demo:
|
csv_agent.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.agents import create_csv_agent, AgentType
|
2 |
+
|
3 |
+
import utils
|
4 |
+
|
5 |
+
|
6 |
+
class CSVAgent:
|
7 |
+
def __init__(self, llm, embeddings, file):
|
8 |
+
self.llm = llm
|
9 |
+
self.file = file
|
10 |
+
self.summary_index_name = "canvas-discussions-summary"
|
11 |
+
self.folder_path = "vector_stores/"
|
12 |
+
self.summary_index_file = "vector_stores/canvas-discussions-summary.faiss"
|
13 |
+
self.summary_pickle_file = "vector_stores/canvas-discussions-summary.pkl"
|
14 |
+
self.summary_docs = utils.get_csv_files(self.file, source_column='student_name')
|
15 |
+
self.summary_index = self.get_search_index(embeddings)
|
16 |
+
self.agent = self.create_agent()
|
17 |
+
|
18 |
+
def get_search_index(self, embeddings):
|
19 |
+
if utils.index_exists(self.summary_pickle_file, self.summary_index_file):
|
20 |
+
# Load index from pickle file
|
21 |
+
search_index = utils.load_index(self.folder_path, self.summary_index_name, embeddings)
|
22 |
+
else:
|
23 |
+
search_index = utils.create_index(self.folder_path, self.summary_index_name, embeddings, self.summary_docs)
|
24 |
+
print("Created index")
|
25 |
+
return search_index
|
26 |
+
|
27 |
+
def create_agent(self):
|
28 |
+
|
29 |
+
agent = create_csv_agent(
|
30 |
+
self.llm,
|
31 |
+
self.file,
|
32 |
+
verbose=True,
|
33 |
+
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
34 |
+
)
|
35 |
+
return agent
|