Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,45 +67,45 @@ def main():
|
|
| 67 |
|
| 68 |
|
| 69 |
if apikey:
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
with st.spinner('Please wait, AMGPT is loading....'):
|
| 76 |
-
paper_to_tools_dict = {}
|
| 77 |
-
for paper in tex_files:
|
| 78 |
-
path = Path(paper)
|
| 79 |
-
vector_tool = create_doc_tools(doc_name=path.stem, document_fp=path)
|
| 80 |
-
paper_to_tools_dict[path.stem] = [vector_tool]
|
| 81 |
-
|
| 82 |
-
initial_tools = [t for paper in tex_files for t in paper_to_tools_dict[Path(paper).stem]]
|
| 83 |
-
|
| 84 |
-
obj_index = ObjectIndex.from_objects(
|
| 85 |
-
initial_tools,
|
| 86 |
-
index_cls=VectorStoreIndex,
|
| 87 |
-
)
|
| 88 |
-
|
| 89 |
-
obj_retriever = obj_index.as_retriever(similarity_top_k=6)
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
context = """You are an agent designed to answer scientific queries over a set of given documents.
|
| 93 |
-
Please always use the tools provided to answer a question. Do not rely on prior knowledge.
|
| 94 |
-
"""
|
| 95 |
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
if apikey:
|
| 70 |
+
if "tools_loaded" not in st.session_state:
|
| 71 |
+
try:
|
| 72 |
+
directory = '/home/user/app/rag_docs_final_review_tex_merged'
|
| 73 |
+
tex_files = find_tex_files(directory)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
with st.spinner('Please wait, AMGPT is loading....'):
|
| 76 |
+
paper_to_tools_dict = {}
|
| 77 |
+
for paper in tex_files:
|
| 78 |
+
path = Path(paper)
|
| 79 |
+
vector_tool = create_doc_tools(doc_name=path.stem, document_fp=path)
|
| 80 |
+
paper_to_tools_dict[path.stem] = [vector_tool]
|
| 81 |
+
|
| 82 |
+
initial_tools = [t for paper in tex_files for t in paper_to_tools_dict[Path(paper).stem]]
|
| 83 |
+
|
| 84 |
+
obj_index = ObjectIndex.from_objects(
|
| 85 |
+
initial_tools,
|
| 86 |
+
index_cls=VectorStoreIndex,
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
obj_retriever = obj_index.as_retriever(similarity_top_k=6)
|
| 90 |
+
|
| 91 |
+
context = """You are an agent designed to answer scientific queries over a set of given documents.
|
| 92 |
+
Please always use the tools provided to answer a question. Do not rely on prior knowledge.
|
| 93 |
+
"""
|
| 94 |
+
|
| 95 |
+
agent = ReActAgent.from_tools(
|
| 96 |
+
tool_retriever=obj_retriever,
|
| 97 |
+
llm=llm,
|
| 98 |
+
verbose=True,
|
| 99 |
+
context=context
|
| 100 |
+
)
|
| 101 |
+
st.success('Done!, you may start asking questions now')
|
| 102 |
+
|
| 103 |
+
# store session state variables
|
| 104 |
+
st.session_state["tools_loaded"] = True
|
| 105 |
+
st.session_state["agent"] = agent
|
| 106 |
+
except Exception as e:
|
| 107 |
+
st.error(e)
|
| 108 |
+
|
| 109 |
|
| 110 |
|
| 111 |
|