Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,14 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
3 |
-
from
|
4 |
-
from
|
5 |
-
from
|
6 |
-
from
|
7 |
-
from
|
8 |
import tempfile
|
9 |
import os
|
10 |
-
import logging
|
11 |
|
12 |
-
#
|
13 |
-
logging.basicConfig(level=logging.INFO)
|
14 |
-
logger = logging.getLogger(__name__)
|
15 |
-
|
16 |
-
# Initialize the session state variables
|
17 |
def init_session_state():
|
18 |
"""Initialize session state variables"""
|
19 |
if 'openai_api_key' not in st.session_state:
|
@@ -35,36 +30,31 @@ def init_qdrant():
|
|
35 |
raise ValueError("Qdrant API key not provided")
|
36 |
if not st.session_state.qdrant_url:
|
37 |
raise ValueError("Qdrant URL not provided")
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
)
|
48 |
-
# Test connection
|
49 |
-
vector_db.client.get_collections()
|
50 |
-
return vector_db
|
51 |
-
except Exception as e:
|
52 |
-
logger.error(f"Failed to initialize Qdrant: {str(e)}")
|
53 |
-
raise
|
54 |
|
55 |
def process_document(uploaded_file, vector_db: Qdrant):
|
56 |
"""Process document, create embeddings and store in Qdrant vector database"""
|
57 |
if not st.session_state.openai_api_key:
|
58 |
raise ValueError("OpenAI API key not provided")
|
59 |
-
|
60 |
os.environ['OPENAI_API_KEY'] = st.session_state.openai_api_key
|
61 |
|
62 |
with tempfile.TemporaryDirectory() as temp_dir:
|
|
|
63 |
temp_file_path = os.path.join(temp_dir, uploaded_file.name)
|
64 |
with open(temp_file_path, "wb") as f:
|
65 |
f.write(uploaded_file.getbuffer())
|
66 |
|
67 |
try:
|
|
|
68 |
embedder = OpenAIEmbedder(
|
69 |
model="text-embedding-3-small",
|
70 |
api_key=st.session_state.openai_api_key
|
@@ -81,7 +71,6 @@ def process_document(uploaded_file, vector_db: Qdrant):
|
|
81 |
knowledge_base.load()
|
82 |
return knowledge_base
|
83 |
except Exception as e:
|
84 |
-
logger.error(f"Error processing document: {str(e)}")
|
85 |
raise Exception(f"Error processing document: {str(e)}")
|
86 |
|
87 |
def main():
|
@@ -144,7 +133,7 @@ def main():
|
|
144 |
name="Legal Researcher",
|
145 |
role="Legal research specialist",
|
146 |
model=OpenAIChat(model="gpt-4o"),
|
147 |
-
tools=[
|
148 |
knowledge=st.session_state.knowledge_base,
|
149 |
search_knowledge=True,
|
150 |
instructions=[
|
@@ -271,8 +260,7 @@ def main():
|
|
271 |
}
|
272 |
|
273 |
st.info(f"π {analysis_configs[analysis_type]['description']}")
|
274 |
-
st.write(f"π€ Active Legal AI Agents: {', '.join(analysis_configs[analysis_type]['agents'])}")
|
275 |
-
|
276 |
|
277 |
# Replace the existing user_query section with this:
|
278 |
if analysis_type == "Custom Query":
|
|
|
1 |
import streamlit as st
|
2 |
+
from agno.agent import Agent
|
3 |
+
from agno.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
4 |
+
from agno.vectordb.qdrant import Qdrant
|
5 |
+
from agno.tools.duckduckgo import DuckDuckGoTools
|
6 |
+
from agno.models.openai import OpenAIChat
|
7 |
+
from agno.embedder.openai import OpenAIEmbedder
|
8 |
import tempfile
|
9 |
import os
|
|
|
10 |
|
11 |
+
#initializing the session state variables
|
|
|
|
|
|
|
|
|
12 |
def init_session_state():
|
13 |
"""Initialize session state variables"""
|
14 |
if 'openai_api_key' not in st.session_state:
|
|
|
30 |
raise ValueError("Qdrant API key not provided")
|
31 |
if not st.session_state.qdrant_url:
|
32 |
raise ValueError("Qdrant URL not provided")
|
33 |
+
|
34 |
+
return Qdrant(
|
35 |
+
collection="legal_knowledge",
|
36 |
+
url=st.session_state.qdrant_url,
|
37 |
+
api_key=st.session_state.qdrant_api_key,
|
38 |
+
https=True,
|
39 |
+
timeout=None,
|
40 |
+
distance="cosine"
|
41 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
def process_document(uploaded_file, vector_db: Qdrant):
|
44 |
"""Process document, create embeddings and store in Qdrant vector database"""
|
45 |
if not st.session_state.openai_api_key:
|
46 |
raise ValueError("OpenAI API key not provided")
|
47 |
+
|
48 |
os.environ['OPENAI_API_KEY'] = st.session_state.openai_api_key
|
49 |
|
50 |
with tempfile.TemporaryDirectory() as temp_dir:
|
51 |
+
|
52 |
temp_file_path = os.path.join(temp_dir, uploaded_file.name)
|
53 |
with open(temp_file_path, "wb") as f:
|
54 |
f.write(uploaded_file.getbuffer())
|
55 |
|
56 |
try:
|
57 |
+
|
58 |
embedder = OpenAIEmbedder(
|
59 |
model="text-embedding-3-small",
|
60 |
api_key=st.session_state.openai_api_key
|
|
|
71 |
knowledge_base.load()
|
72 |
return knowledge_base
|
73 |
except Exception as e:
|
|
|
74 |
raise Exception(f"Error processing document: {str(e)}")
|
75 |
|
76 |
def main():
|
|
|
133 |
name="Legal Researcher",
|
134 |
role="Legal research specialist",
|
135 |
model=OpenAIChat(model="gpt-4o"),
|
136 |
+
tools=[DuckDuckGoTools()],
|
137 |
knowledge=st.session_state.knowledge_base,
|
138 |
search_knowledge=True,
|
139 |
instructions=[
|
|
|
260 |
}
|
261 |
|
262 |
st.info(f"π {analysis_configs[analysis_type]['description']}")
|
263 |
+
st.write(f"π€ Active Legal AI Agents: {', '.join(analysis_configs[analysis_type]['agents'])}") #dictionary!!
|
|
|
264 |
|
265 |
# Replace the existing user_query section with this:
|
266 |
if analysis_type == "Custom Query":
|