Spaces:
Sleeping
Sleeping
Akshayram1
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,11 @@ from phi.agent import Agent
|
|
3 |
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
4 |
from phi.vectordb.qdrant import Qdrant
|
5 |
from phi.tools.duckduckgo import DuckDuckGo
|
|
|
|
|
|
|
|
|
|
|
6 |
from phi.model.openai import OpenAIChat
|
7 |
from phi.embedder.openai import OpenAIEmbedder
|
8 |
import tempfile
|
@@ -34,6 +39,7 @@ from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
|
34 |
from phi.vectordb.qdrant import Qdrant
|
35 |
from phi.tools.duckduckgo import DuckDuckGo
|
36 |
from phi.model.openai import OpenAIChat
|
|
|
37 |
from phi.embedder.openai import OpenAIEmbedder
|
38 |
import tempfile
|
39 |
import os
|
@@ -58,12 +64,42 @@ def init_qdrant():
|
|
58 |
"""Initialize Qdrant vector database"""
|
59 |
if not st.session_state.qdrant_api_key:
|
60 |
raise ValueError("Qdrant API key not provided")
|
61 |
-
if not st.session_state.qdrant_url:
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
main()
|
68 |
raise ValueError("Qdrant URL not provided")
|
69 |
|
@@ -89,7 +125,43 @@ def process_document(uploaded_file, vector_db: Qdrant):
|
|
89 |
with open(temp_file_path, "wb") as f:
|
90 |
f.write(uploaded_file.getbuffer())
|
91 |
|
92 |
-
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
embedder = OpenAIEmbedder(
|
95 |
model="text-embedding-3-small",
|
@@ -99,7 +171,8 @@ def process_document(uploaded_file, vector_db: Qdrant):
|
|
99 |
# Creating knowledge base with explicit Qdrant configuration
|
100 |
knowledge_base = PDFKnowledgeBase(
|
101 |
path=temp_dir,
|
102 |
-
vector_db=vector_db,
|
|
|
103 |
from phi.agent import Agent
|
104 |
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
105 |
from phi.vectordb.qdrant import Qdrant
|
@@ -129,14 +202,13 @@ def init_qdrant():
|
|
129 |
"""Initialize Qdrant vector database"""
|
130 |
if not st.session_state.qdrant_api_key:
|
131 |
raise ValueError("Qdrant API key not provided")
|
132 |
-
if not st.session_state.qdrant_url:
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
main()
|
139 |
-
reader=PDFReader(chunk=True),
|
140 |
embedder=embedder,
|
141 |
recreate_vector_db=True
|
142 |
)
|
@@ -153,18 +225,7 @@ def main():
|
|
153 |
|
154 |
with st.sidebar:
|
155 |
st.header("π API Configuration")
|
156 |
-
|
157 |
-
openai_key = st.text_input(
|
158 |
-
"OpenAI API Key",
|
159 |
-
type="password",
|
160 |
-
value=st.session_state.openai_api_key if st.session_state.openai_api_key else "",
|
161 |
-
help="Enter your OpenAI API key"
|
162 |
-
)
|
163 |
-
if openai_key:
|
164 |
-
st.session_state.openai_api_key = openai_key
|
165 |
-
|
166 |
-
qdrant_key = st.text_input(
|
167 |
-
"Qdrant API Key",import streamlit as st
|
168 |
from phi.agent import Agent
|
169 |
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
170 |
from phi.vectordb.qdrant import Qdrant
|
@@ -180,7 +241,47 @@ def init_session_state():
|
|
180 |
if 'openai_api_key' not in st.session_state:
|
181 |
st.session_state.openai_api_key = None
|
182 |
if 'qdrant_api_key' not in st.session_state:
|
183 |
-
st.session_state.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
from phi.agent import Agent
|
185 |
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
186 |
from phi.vectordb.qdrant import Qdrant
|
@@ -210,42 +311,13 @@ def init_qdrant():
|
|
210 |
"""Initialize Qdrant vector database"""
|
211 |
if not st.session_state.qdrant_api_key:
|
212 |
raise ValueError("Qdrant API key not provided")
|
213 |
-
if not st.session_state.qdrant_url:
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
main() _key = None
|
220 |
-
if 'qdrant_url' not in st.session_state:
|
221 |
-
st.session_state.qdrant_url = None
|
222 |
-
if 'vector_db' not in st.session_state:
|
223 |
-
st.session_state.vector_db = None
|
224 |
-
if 'legal_team' not in st.session_state:
|
225 |
-
st.session_state.legal_team = None
|
226 |
-
if 'knowledge_base' not in st.session_state:
|
227 |
-
st.session_state.knowledge_base = None
|
228 |
-
|
229 |
-
def init_qdrant():
|
230 |
-
"""Initialize Qdrant vector database"""
|
231 |
-
if not st.session_state.qdrant_api_key:
|
232 |
-
raise ValueError("Qdrant API key not provided")
|
233 |
-
if not st.session_state.qdrant_url:
|
234 |
-
raise ValueError("Qdrant URL not provided")
|
235 |
-
|
236 |
-
return Qdrant(
|
237 |
-
collection="legal_knowledge",
|
238 |
-
url=st.session_state.qdrant_url,
|
239 |
main()
|
240 |
-
type="password",
|
241 |
-
value=st.session_state.qdrant_api_key if st.session_state.qdrant_api_key else "",
|
242 |
-
help="Enter your Qdrant API key"
|
243 |
-
)
|
244 |
-
if qdrant_key:
|
245 |
-
st.session_state.qdrant_api_key = qdrant_key
|
246 |
-
|
247 |
-
qdrant_url = st.text_input(
|
248 |
-
"Qdrant URL",
|
249 |
value=st.session_state.qdrant_url if st.session_state.qdrant_url else "https://f499085c-b4bf-4bda-a9a5-227f62a9ca20.us-west-2-0.aws.cloud.qdrant.io:6333",
|
250 |
help="Enter your Qdrant instance URL"
|
251 |
)
|
@@ -259,7 +331,10 @@ def init_qdrant():
|
|
259 |
st.success("Successfully connected to Qdrant!")
|
260 |
except Exception as e:
|
261 |
st.error(f"Failed to connect to Qdrant: {str(e)}")
|
262 |
-
|
|
|
|
|
|
|
263 |
from phi.agent import Agent
|
264 |
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
265 |
from phi.vectordb.qdrant import Qdrant
|
@@ -289,16 +364,13 @@ def init_qdrant():
|
|
289 |
"""Initialize Qdrant vector database"""
|
290 |
if not st.session_state.qdrant_api_key:
|
291 |
raise ValueError("Qdrant API key not provided")
|
292 |
-
if not st.session_state.qdrant_url:
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
main()
|
299 |
-
st.divider()
|
300 |
-
|
301 |
-
if all([st.session_state.openai_api_key, st.session_state.vector_db]):
|
302 |
st.header("π Document Upload")
|
303 |
uploaded_file = st.file_uploader("Upload Legal Document", type=['pdf'])
|
304 |
|
@@ -317,7 +389,43 @@ def init_qdrant():
|
|
317 |
knowledge=st.session_state.knowledge_base,
|
318 |
search_knowledge=True,
|
319 |
instructions=[
|
320 |
-
"Find and cite relevant legal cases and precedents",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
"Provide detailed research summaries with sources",
|
322 |
"Reference specific sections from the uploaded document",
|
323 |
"Always search the knowledge base for relevant information"
|
@@ -390,43 +498,7 @@ def init_qdrant():
|
|
390 |
"Custom Query"
|
391 |
]
|
392 |
)
|
393 |
-
else:
|
394 |
-
from phi.agent import Agent
|
395 |
-
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
396 |
-
from phi.vectordb.qdrant import Qdrant
|
397 |
-
from phi.tools.duckduckgo import DuckDuckGo
|
398 |
-
from phi.model.openai import OpenAIChat
|
399 |
-
from phi.embedder.openai import OpenAIEmbedder
|
400 |
-
import tempfile
|
401 |
-
import os
|
402 |
-
|
403 |
-
#initializing the session state variables
|
404 |
-
def init_session_state():
|
405 |
-
"""Initialize session state variables"""
|
406 |
-
if 'openai_api_key' not in st.session_state:
|
407 |
-
st.session_state.openai_api_key = None
|
408 |
-
if 'qdrant_api_key' not in st.session_state:
|
409 |
-
st.session_state.qdrant_api_key = None
|
410 |
-
if 'qdrant_url' not in st.session_state:
|
411 |
-
st.session_state.qdrant_url = None
|
412 |
-
if 'vector_db' not in st.session_state:
|
413 |
-
st.session_state.vector_db = None
|
414 |
-
if 'legal_team' not in st.session_state:
|
415 |
-
st.session_state.legal_team = None
|
416 |
-
if 'knowledge_base' not in st.session_state:
|
417 |
-
st.session_state.knowledge_base = None
|
418 |
-
|
419 |
-
def init_qdrant():
|
420 |
-
"""Initialize Qdrant vector database"""
|
421 |
-
if not st.session_state.qdrant_api_key:
|
422 |
-
raise ValueError("Qdrant API key not provided")
|
423 |
-
if not st.session_state.qdrant_url:
|
424 |
-
raise ValueError("Qdrant URL not provided")
|
425 |
-
|
426 |
-
return Qdrant(
|
427 |
-
collection="legal_knowledge",
|
428 |
-
url=st.session_state.qdrant_url,
|
429 |
-
main()
|
430 |
st.warning("Please configure all API credentials to proceed")
|
431 |
|
432 |
# Main content area
|
@@ -435,43 +507,7 @@ def init_qdrant():
|
|
435 |
elif not uploaded_file:
|
436 |
st.info("π Please upload a legal document to begin analysis")
|
437 |
elif st.session_state.legal_team:
|
438 |
-
# Create a dictionary for
|
439 |
-
from phi.agent import Agent
|
440 |
-
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
441 |
-
from phi.vectordb.qdrant import Qdrant
|
442 |
-
from phi.tools.duckduckgo import DuckDuckGo
|
443 |
-
from phi.model.openai import OpenAIChat
|
444 |
-
from phi.embedder.openai import OpenAIEmbedder
|
445 |
-
import tempfile
|
446 |
-
import os
|
447 |
-
|
448 |
-
#initializing the session state variables
|
449 |
-
def init_session_state():
|
450 |
-
"""Initialize session state variables"""
|
451 |
-
if 'openai_api_key' not in st.session_state:
|
452 |
-
st.session_state.openai_api_key = None
|
453 |
-
if 'qdrant_api_key' not in st.session_state:
|
454 |
-
st.session_state.qdrant_api_key = None
|
455 |
-
if 'qdrant_url' not in st.session_state:
|
456 |
-
st.session_state.qdrant_url = None
|
457 |
-
if 'vector_db' not in st.session_state:
|
458 |
-
st.session_state.vector_db = None
|
459 |
-
if 'legal_team' not in st.session_state:
|
460 |
-
st.session_state.legal_team = None
|
461 |
-
if 'knowledge_base' not in st.session_state:
|
462 |
-
st.session_state.knowledge_base = None
|
463 |
-
|
464 |
-
def init_qdrant():
|
465 |
-
"""Initialize Qdrant vector database"""
|
466 |
-
if not st.session_state.qdrant_api_key:
|
467 |
-
raise ValueError("Qdrant API key not provided")
|
468 |
-
if not st.session_state.qdrant_url:
|
469 |
-
raise ValueError("Qdrant URL not provided")
|
470 |
-
|
471 |
-
return Qdrant(
|
472 |
-
collection="legal_knowledge",
|
473 |
-
url=st.session_state.qdrant_url,
|
474 |
-
main() analysis type icons
|
475 |
analysis_icons = {
|
476 |
"Contract Review": "π",
|
477 |
"Legal Research": "π",
|
|
|
3 |
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
4 |
from phi.vectordb.qdrant import Qdrant
|
5 |
from phi.tools.duckduckgo import DuckDuckGo
|
6 |
+
from phi.model.openai import OpenAIChatimport streamlit as st
|
7 |
+
from phi.agent import Agent
|
8 |
+
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
9 |
+
from phi.vectordb.qdrant import Qdrant
|
10 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
11 |
from phi.model.openai import OpenAIChat
|
12 |
from phi.embedder.openai import OpenAIEmbedder
|
13 |
import tempfile
|
|
|
39 |
from phi.vectordb.qdrant import Qdrant
|
40 |
from phi.tools.duckduckgo import DuckDuckGo
|
41 |
from phi.model.openai import OpenAIChat
|
42 |
+
main()
|
43 |
from phi.embedder.openai import OpenAIEmbedder
|
44 |
import tempfile
|
45 |
import os
|
|
|
64 |
"""Initialize Qdrant vector database"""
|
65 |
if not st.session_state.qdrant_api_key:
|
66 |
raise ValueError("Qdrant API key not provided")
|
67 |
+
if not st.session_state.qdrant_url:import streamlit as st
|
68 |
+
from phi.agent import Agent
|
69 |
+
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
70 |
+
from phi.vectordb.qdrant import Qdrant
|
71 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
72 |
+
from phi.model.openai import OpenAIChat
|
73 |
+
from phi.embedder.openai import OpenAIEmbedder
|
74 |
+
import tempfile
|
75 |
+
import os
|
76 |
+
|
77 |
+
#initializing the session state variables
|
78 |
+
def init_session_state():
|
79 |
+
"""Initialize session state variables"""
|
80 |
+
if 'openai_api_key' not in st.session_state:
|
81 |
+
st.session_state.openai_api_key = None
|
82 |
+
if 'qdrant_api_key' not in st.session_state:
|
83 |
+
st.session_state.qdrant_api_key = None
|
84 |
+
if 'qdrant_url' not in st.session_state:
|
85 |
+
st.session_state.qdrant_url = None
|
86 |
+
if 'vector_db' not in st.session_state:
|
87 |
+
st.session_state.vector_db = None
|
88 |
+
if 'legal_team' not in st.session_state:
|
89 |
+
st.session_state.legal_team = None
|
90 |
+
if 'knowledge_base' not in st.session_state:
|
91 |
+
st.session_state.knowledge_base = None
|
92 |
+
|
93 |
+
def init_qdrant():
|
94 |
+
"""Initialize Qdrant vector database"""
|
95 |
+
if not st.session_state.qdrant_api_key:
|
96 |
+
raise ValueError("Qdrant API key not provided")
|
97 |
+
if not st.session_state.qdrant_url:import streamlit as st
|
98 |
+
from phi.agent import Agent
|
99 |
+
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
100 |
+
from phi.vectordb.qdrant import Qdrant
|
101 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
102 |
+
from phi.model.openai import OpenAIChat
|
103 |
main()
|
104 |
raise ValueError("Qdrant URL not provided")
|
105 |
|
|
|
125 |
with open(temp_file_path, "wb") as f:
|
126 |
f.write(uploaded_file.getbuffer())
|
127 |
|
128 |
+
try:import streamlit as st
|
129 |
+
from phi.agent import Agent
|
130 |
+
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
131 |
+
from phi.vectordb.qdrant import Qdrant
|
132 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
133 |
+
from phi.model.openai import OpenAIChat
|
134 |
+
from phi.embedder.openai import OpenAIEmbedder
|
135 |
+
import tempfile
|
136 |
+
import os
|
137 |
+
|
138 |
+
#initializing the session state variables
|
139 |
+
def init_session_state():
|
140 |
+
"""Initialize session state variables"""
|
141 |
+
if 'openai_api_key' not in st.session_state:
|
142 |
+
st.session_state.openai_api_key = None
|
143 |
+
if 'qdrant_api_key' not in st.session_state:
|
144 |
+
st.session_state.qdrant_api_key = None
|
145 |
+
if 'qdrant_url' not in st.session_state:
|
146 |
+
st.session_state.qdrant_url = None
|
147 |
+
if 'vector_db' not in st.session_state:
|
148 |
+
st.session_state.vector_db = None
|
149 |
+
if 'legal_team' not in st.session_state:
|
150 |
+
st.session_state.legal_team = None
|
151 |
+
if 'knowledge_base' not in st.session_state:
|
152 |
+
st.session_state.knowledge_base = None
|
153 |
+
|
154 |
+
def init_qdrant():
|
155 |
+
"""Initialize Qdrant vector database"""
|
156 |
+
if not st.session_state.qdrant_api_key:
|
157 |
+
raise ValueError("Qdrant API key not provided")
|
158 |
+
if not st.session_state.qdrant_url:import streamlit as st
|
159 |
+
from phi.agent import Agent
|
160 |
+
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
161 |
+
from phi.vectordb.qdrant import Qdrant
|
162 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
163 |
+
from phi.model.openai import OpenAIChat
|
164 |
+
main()
|
165 |
|
166 |
embedder = OpenAIEmbedder(
|
167 |
model="text-embedding-3-small",
|
|
|
171 |
# Creating knowledge base with explicit Qdrant configuration
|
172 |
knowledge_base = PDFKnowledgeBase(
|
173 |
path=temp_dir,
|
174 |
+
vector_db=vector_db,
|
175 |
+
reader=PDFReader(chunk=True),import streamlit as st
|
176 |
from phi.agent import Agent
|
177 |
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
178 |
from phi.vectordb.qdrant import Qdrant
|
|
|
202 |
"""Initialize Qdrant vector database"""
|
203 |
if not st.session_state.qdrant_api_key:
|
204 |
raise ValueError("Qdrant API key not provided")
|
205 |
+
if not st.session_state.qdrant_url:import streamlit as st
|
206 |
+
from phi.agent import Agent
|
207 |
+
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
208 |
+
from phi.vectordb.qdrant import Qdrant
|
209 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
210 |
+
from phi.model.openai import OpenAIChat
|
211 |
main()
|
|
|
212 |
embedder=embedder,
|
213 |
recreate_vector_db=True
|
214 |
)
|
|
|
225 |
|
226 |
with st.sidebar:
|
227 |
st.header("π API Configuration")
|
228 |
+
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
from phi.agent import Agent
|
230 |
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
231 |
from phi.vectordb.qdrant import Qdrant
|
|
|
241 |
if 'openai_api_key' not in st.session_state:
|
242 |
st.session_state.openai_api_key = None
|
243 |
if 'qdrant_api_key' not in st.session_state:
|
244 |
+
st.session_state.qdrant_api_key = None
|
245 |
+
if 'qdrant_url' not in st.session_state:
|
246 |
+
st.session_state.qdrant_url = None
|
247 |
+
if 'vector_db' not in st.session_state:
|
248 |
+
st.session_state.vector_db = None
|
249 |
+
if 'legal_team' not in st.session_state:
|
250 |
+
st.session_state.legal_team = None
|
251 |
+
if 'knowledge_base' not in st.session_state:
|
252 |
+
st.session_state.knowledge_base = None
|
253 |
+
|
254 |
+
def init_qdrant():
|
255 |
+
"""Initialize Qdrant vector database"""
|
256 |
+
if not st.session_state.qdrant_api_key:
|
257 |
+
raise ValueError("Qdrant API key not provided")
|
258 |
+
if not st.session_state.qdrant_url:import streamlit as st
|
259 |
+
from phi.agent import Agent
|
260 |
+
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
261 |
+
from phi.vectordb.qdrant import Qdrant
|
262 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
263 |
+
from phi.model.openai import OpenAIChat
|
264 |
+
main()
|
265 |
+
openai_key = st.text_input(
|
266 |
+
"OpenAI API Key",
|
267 |
+
type="password",
|
268 |
+
value=st.session_state.openai_api_key if st.session_state.openai_api_key else "",
|
269 |
+
help="Enter your OpenAI API key"
|
270 |
+
)
|
271 |
+
if openai_key:
|
272 |
+
st.session_state.openai_api_key = openai_key
|
273 |
+
|
274 |
+
qdrant_key = st.text_input(
|
275 |
+
"Qdrant API Key",
|
276 |
+
type="password",
|
277 |
+
value=st.session_state.qdrant_api_key if st.session_state.qdrant_api_key else "",
|
278 |
+
help="Enter your Qdrant API key"
|
279 |
+
)
|
280 |
+
if qdrant_key:
|
281 |
+
st.session_state.qdrant_api_key = qdrant_key
|
282 |
+
|
283 |
+
qdrant_url = st.text_input(
|
284 |
+
"Qdrant URL",import streamlit as st
|
285 |
from phi.agent import Agent
|
286 |
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
287 |
from phi.vectordb.qdrant import Qdrant
|
|
|
311 |
"""Initialize Qdrant vector database"""
|
312 |
if not st.session_state.qdrant_api_key:
|
313 |
raise ValueError("Qdrant API key not provided")
|
314 |
+
if not st.session_state.qdrant_url:import streamlit as st
|
315 |
+
from phi.agent import Agent
|
316 |
+
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
317 |
+
from phi.vectordb.qdrant import Qdrant
|
318 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
319 |
+
from phi.model.openai import OpenAIChat
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
320 |
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
value=st.session_state.qdrant_url if st.session_state.qdrant_url else "https://f499085c-b4bf-4bda-a9a5-227f62a9ca20.us-west-2-0.aws.cloud.qdrant.io:6333",
|
322 |
help="Enter your Qdrant instance URL"
|
323 |
)
|
|
|
331 |
st.success("Successfully connected to Qdrant!")
|
332 |
except Exception as e:
|
333 |
st.error(f"Failed to connect to Qdrant: {str(e)}")
|
334 |
+
|
335 |
+
st.divider()
|
336 |
+
|
337 |
+
if all([st.session_state.openai_api_key, st.session_state.vector_db]):import streamlit as st
|
338 |
from phi.agent import Agent
|
339 |
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
340 |
from phi.vectordb.qdrant import Qdrant
|
|
|
364 |
"""Initialize Qdrant vector database"""
|
365 |
if not st.session_state.qdrant_api_key:
|
366 |
raise ValueError("Qdrant API key not provided")
|
367 |
+
if not st.session_state.qdrant_url:import streamlit as st
|
368 |
+
from phi.agent import Agent
|
369 |
+
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
370 |
+
from phi.vectordb.qdrant import Qdrant
|
371 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
372 |
+
from phi.model.openai import OpenAIChat
|
373 |
main()
|
|
|
|
|
|
|
374 |
st.header("π Document Upload")
|
375 |
uploaded_file = st.file_uploader("Upload Legal Document", type=['pdf'])
|
376 |
|
|
|
389 |
knowledge=st.session_state.knowledge_base,
|
390 |
search_knowledge=True,
|
391 |
instructions=[
|
392 |
+
"Find and cite relevant legal cases and precedents",import streamlit as st
|
393 |
+
from phi.agent import Agent
|
394 |
+
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
395 |
+
from phi.vectordb.qdrant import Qdrant
|
396 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
397 |
+
from phi.model.openai import OpenAIChat
|
398 |
+
from phi.embedder.openai import OpenAIEmbedder
|
399 |
+
import tempfile
|
400 |
+
import os
|
401 |
+
|
402 |
+
#initializing the session state variables
|
403 |
+
def init_session_state():
|
404 |
+
"""Initialize session state variables"""
|
405 |
+
if 'openai_api_key' not in st.session_state:
|
406 |
+
st.session_state.openai_api_key = None
|
407 |
+
if 'qdrant_api_key' not in st.session_state:
|
408 |
+
st.session_state.qdrant_api_key = None
|
409 |
+
if 'qdrant_url' not in st.session_state:
|
410 |
+
st.session_state.qdrant_url = None
|
411 |
+
if 'vector_db' not in st.session_state:
|
412 |
+
st.session_state.vector_db = None
|
413 |
+
if 'legal_team' not in st.session_state:
|
414 |
+
st.session_state.legal_team = None
|
415 |
+
if 'knowledge_base' not in st.session_state:
|
416 |
+
st.session_state.knowledge_base = None
|
417 |
+
|
418 |
+
def init_qdrant():
|
419 |
+
"""Initialize Qdrant vector database"""
|
420 |
+
if not st.session_state.qdrant_api_key:
|
421 |
+
raise ValueError("Qdrant API key not provided")
|
422 |
+
if not st.session_state.qdrant_url:import streamlit as st
|
423 |
+
from phi.agent import Agent
|
424 |
+
from phi.knowledge.pdf import PDFKnowledgeBase, PDFReader
|
425 |
+
from phi.vectordb.qdrant import Qdrant
|
426 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
427 |
+
from phi.model.openai import OpenAIChat
|
428 |
+
main()
|
429 |
"Provide detailed research summaries with sources",
|
430 |
"Reference specific sections from the uploaded document",
|
431 |
"Always search the knowledge base for relevant information"
|
|
|
498 |
"Custom Query"
|
499 |
]
|
500 |
)
|
501 |
+
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
502 |
st.warning("Please configure all API credentials to proceed")
|
503 |
|
504 |
# Main content area
|
|
|
507 |
elif not uploaded_file:
|
508 |
st.info("π Please upload a legal document to begin analysis")
|
509 |
elif st.session_state.legal_team:
|
510 |
+
# Create a dictionary for analysis type icons
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
511 |
analysis_icons = {
|
512 |
"Contract Review": "π",
|
513 |
"Legal Research": "π",
|