Spaces:
Runtime error
Runtime error
Commit
·
eef679a
1
Parent(s):
5630d67
anotehr change
Browse files
app.py
CHANGED
@@ -1021,6 +1021,9 @@
|
|
1021 |
|
1022 |
|
1023 |
|
|
|
|
|
|
|
1024 |
import os
|
1025 |
import gradio as gr
|
1026 |
from pinecone import Pinecone
|
@@ -1609,20 +1612,20 @@ def create_graph_visualization(graph_data: List[Dict]) -> go.Figure:
|
|
1609 |
|
1610 |
return fig
|
1611 |
|
1612 |
-
def create_interface(
|
1613 |
"""Create Gradio interface with interactive graph"""
|
1614 |
-
|
|
|
1615 |
with gr.Blocks(css="footer {display: none !important;}") as demo:
|
1616 |
gr.Markdown("""
|
1617 |
-
#
|
1618 |
-
Enter your legal query below to search through documents and get an AI-powered analysis.
|
1619 |
-
This system combines graph-based and semantic search capabilities for comprehensive legal research.
|
1620 |
""")
|
1621 |
|
1622 |
with gr.Row():
|
1623 |
query_input = gr.Textbox(
|
1624 |
label="Legal Query",
|
1625 |
-
placeholder="e.g., What are the
|
1626 |
lines=3
|
1627 |
)
|
1628 |
|
@@ -1635,24 +1638,28 @@ def create_interface(search_system: EnhancedLegalSearchSystem):
|
|
1635 |
)
|
1636 |
|
1637 |
with gr.Tabs():
|
|
|
|
|
|
|
|
|
|
|
|
|
1638 |
with gr.TabItem("AI Legal Analysis"):
|
1639 |
-
|
1640 |
label="AI-Generated Legal Analysis",
|
1641 |
value="Analysis will appear here..."
|
1642 |
)
|
1643 |
-
|
1644 |
-
with gr.TabItem("Retrieved Documents"):
|
1645 |
-
|
1646 |
label="Source Documents",
|
1647 |
value="Search results will appear here..."
|
1648 |
)
|
1649 |
-
|
1650 |
-
|
1651 |
-
concepts_output = gr.Json(
|
1652 |
-
label="Related Legal Concepts",
|
1653 |
value={}
|
1654 |
)
|
1655 |
-
|
1656 |
with gr.TabItem("Knowledge Graph"):
|
1657 |
# Graph visualization
|
1658 |
graph_output = gr.Plot(
|
@@ -1664,39 +1671,48 @@ def create_interface(search_system: EnhancedLegalSearchSystem):
|
|
1664 |
interactive=False,
|
1665 |
lines=10
|
1666 |
)
|
1667 |
-
|
1668 |
async def process_query(query):
|
1669 |
if not query.strip():
|
1670 |
return (
|
1671 |
"Please enter a query",
|
1672 |
-
"No
|
1673 |
-
"No
|
|
|
1674 |
{},
|
1675 |
None,
|
1676 |
""
|
1677 |
)
|
1678 |
|
1679 |
-
|
1680 |
-
|
|
|
|
|
|
|
|
|
|
|
1681 |
graph_fig = create_graph_visualization(graph_data)
|
1682 |
-
|
1683 |
return (
|
1684 |
-
|
1685 |
-
|
1686 |
-
|
1687 |
-
|
|
|
1688 |
graph_fig,
|
1689 |
"Click on a node to view document content"
|
1690 |
)
|
1691 |
-
|
|
|
1692 |
search_button.click(
|
1693 |
fn=process_query,
|
1694 |
inputs=[query_input],
|
1695 |
outputs=[
|
1696 |
status_output,
|
1697 |
-
analysis_output,
|
1698 |
docs_output,
|
1699 |
-
|
|
|
|
|
1700 |
graph_output,
|
1701 |
selected_doc_content
|
1702 |
]
|
@@ -1706,7 +1722,6 @@ def create_interface(search_system: EnhancedLegalSearchSystem):
|
|
1706 |
|
1707 |
|
1708 |
|
1709 |
-
|
1710 |
class LegalSearchSystem:
|
1711 |
def __init__(
|
1712 |
self,
|
@@ -1892,8 +1907,17 @@ class LegalSearchSystem:
|
|
1892 |
}
|
1893 |
))
|
1894 |
|
1895 |
-
return
|
1896 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1897 |
|
1898 |
if __name__ == "__main__":
|
1899 |
graph_search_system = EnhancedLegalSearchSystem(
|
|
|
1021 |
|
1022 |
|
1023 |
|
1024 |
+
|
1025 |
+
|
1026 |
+
|
1027 |
import os
|
1028 |
import gradio as gr
|
1029 |
from pinecone import Pinecone
|
|
|
1612 |
|
1613 |
return fig
|
1614 |
|
1615 |
+
def create_interface(graph_search_system: EnhancedLegalSearchSystem):
|
1616 |
"""Create Gradio interface with interactive graph"""
|
1617 |
+
search_system = LegalSearchSystem()
|
1618 |
+
|
1619 |
with gr.Blocks(css="footer {display: none !important;}") as demo:
|
1620 |
gr.Markdown("""
|
1621 |
+
# Corporate Law Legal Search Engine
|
1622 |
+
Enter your legal query below to search through documents and get an AI-powered analysis. Queries only related to corporate law will give relevant information.
|
|
|
1623 |
""")
|
1624 |
|
1625 |
with gr.Row():
|
1626 |
query_input = gr.Textbox(
|
1627 |
label="Legal Query",
|
1628 |
+
placeholder="e.g., What are the key principles of contract law?",
|
1629 |
lines=3
|
1630 |
)
|
1631 |
|
|
|
1638 |
)
|
1639 |
|
1640 |
with gr.Tabs():
|
1641 |
+
with gr.TabItem("Search Results"):
|
1642 |
+
docs_output = gr.Markdown(
|
1643 |
+
label="Retrieved Documents",
|
1644 |
+
value="Search results will appear here..."
|
1645 |
+
)
|
1646 |
+
|
1647 |
with gr.TabItem("AI Legal Analysis"):
|
1648 |
+
summary_output = gr.Markdown(
|
1649 |
label="AI-Generated Legal Analysis",
|
1650 |
value="Analysis will appear here..."
|
1651 |
)
|
1652 |
+
|
1653 |
+
with gr.TabItem("Retrieved Documents through Graph Rag"):
|
1654 |
+
docs_output_graph = gr.Markdown(
|
1655 |
label="Source Documents",
|
1656 |
value="Search results will appear here..."
|
1657 |
)
|
1658 |
+
graph_analysis_output = gr.JSON(
|
1659 |
+
label="Related Concepts",
|
|
|
|
|
1660 |
value={}
|
1661 |
)
|
1662 |
+
|
1663 |
with gr.TabItem("Knowledge Graph"):
|
1664 |
# Graph visualization
|
1665 |
graph_output = gr.Plot(
|
|
|
1671 |
interactive=False,
|
1672 |
lines=10
|
1673 |
)
|
1674 |
+
|
1675 |
async def process_query(query):
|
1676 |
if not query.strip():
|
1677 |
return (
|
1678 |
"Please enter a query",
|
1679 |
+
"No documents available from Pinecone",
|
1680 |
+
"No analysis available from Pinecone",
|
1681 |
+
"No documents available from Neo4j",
|
1682 |
{},
|
1683 |
None,
|
1684 |
""
|
1685 |
)
|
1686 |
|
1687 |
+
# Run the regular RAG search
|
1688 |
+
rag_results = search_system.search(query)
|
1689 |
+
|
1690 |
+
# Run the graph-based RAG search
|
1691 |
+
graph_results = await graph_search_system.process_legal_query(query)
|
1692 |
+
|
1693 |
+
graph_data = graph_search_system.generate_document_graph(query)
|
1694 |
graph_fig = create_graph_visualization(graph_data)
|
1695 |
+
|
1696 |
return (
|
1697 |
+
rag_results['status'],
|
1698 |
+
rag_results['documents'],
|
1699 |
+
rag_results['analysis'],
|
1700 |
+
graph_results['documents'],
|
1701 |
+
{"related_concepts": graph_results['related_concepts']},
|
1702 |
graph_fig,
|
1703 |
"Click on a node to view document content"
|
1704 |
)
|
1705 |
+
|
1706 |
+
|
1707 |
search_button.click(
|
1708 |
fn=process_query,
|
1709 |
inputs=[query_input],
|
1710 |
outputs=[
|
1711 |
status_output,
|
|
|
1712 |
docs_output,
|
1713 |
+
summary_output,
|
1714 |
+
docs_output_graph,
|
1715 |
+
graph_analysis_output,
|
1716 |
graph_output,
|
1717 |
selected_doc_content
|
1718 |
]
|
|
|
1722 |
|
1723 |
|
1724 |
|
|
|
1725 |
class LegalSearchSystem:
|
1726 |
def __init__(
|
1727 |
self,
|
|
|
1907 |
}
|
1908 |
))
|
1909 |
|
1910 |
+
return sorted(documents, key=lambda x: x.metadata['page_number'])
|
1911 |
+
|
1912 |
+
def _format_documents(self, results: List[Dict]) -> str:
|
1913 |
+
"""
|
1914 |
+
Format search results as markdown.
|
1915 |
+
"""
|
1916 |
+
markdown = "### Retrieved Documents\n\n"
|
1917 |
+
for i, result in enumerate(results, 1):
|
1918 |
+
markdown += f"**Document {i}** (Page {result['metadata']['page_number']})\n"
|
1919 |
+
markdown += f"```\n{result['metadata']['text']}\n```\n\n"
|
1920 |
+
return markdown
|
1921 |
|
1922 |
if __name__ == "__main__":
|
1923 |
graph_search_system = EnhancedLegalSearchSystem(
|