Update app2.py
Browse files
app2.py
CHANGED
@@ -637,21 +637,31 @@ def legal_cost_estimator_ui():
|
|
637 |
else:
|
638 |
st.write("No web search results found for the selected criteria.")
|
639 |
|
|
|
|
|
|
|
640 |
def analyze_contract(contract_text: str) -> Dict[str, Any]:
|
641 |
"""Analyzes the contract text for clauses, benefits, and potential exploits."""
|
|
|
|
|
642 |
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
|
|
647 |
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
|
652 |
-
|
653 |
-
|
|
|
|
|
|
|
654 |
|
|
|
655 |
|
656 |
def contract_analysis_ui():
|
657 |
st.subheader("Contract Analyzer")
|
@@ -662,15 +672,17 @@ def contract_analysis_ui():
|
|
662 |
)
|
663 |
|
664 |
if uploaded_file:
|
665 |
-
contract_text =
|
666 |
|
667 |
if st.button("Analyze Contract"):
|
668 |
with st.spinner("Analyzing contract..."):
|
669 |
analysis_results = analyze_contract(contract_text)
|
670 |
|
671 |
st.write("### Contract Analysis")
|
672 |
-
|
673 |
-
|
|
|
|
|
674 |
|
675 |
CASE_TYPES = [
|
676 |
"Civil Rights", "Contract", "Real Property", "Tort", "Labor", "Intellectual Property",
|
@@ -1287,9 +1299,6 @@ def extract_text_from_document(uploaded_file):
|
|
1287 |
text = uploaded_file.getvalue().decode("utf-8")
|
1288 |
return text
|
1289 |
|
1290 |
-
def split_text(text, max_chunk_size=4000):
|
1291 |
-
return [text[i:i+max_chunk_size] for i in range(0, len(text), max_chunk_size)]
|
1292 |
-
|
1293 |
def generate_legal_brief(case_info):
|
1294 |
chunks = split_text(case_info)
|
1295 |
full_brief = ""
|
|
|
637 |
else:
|
638 |
st.write("No web search results found for the selected criteria.")
|
639 |
|
640 |
+
def split_text(text, max_chunk_size=4000):
|
641 |
+
return [text[i:i+max_chunk_size] for i in range(0, len(text), max_chunk_size)]
|
642 |
+
|
643 |
def analyze_contract(contract_text: str) -> Dict[str, Any]:
|
644 |
"""Analyzes the contract text for clauses, benefits, and potential exploits."""
|
645 |
+
chunks = split_text(contract_text)
|
646 |
+
full_analysis = ""
|
647 |
|
648 |
+
for i, chunk in enumerate(chunks):
|
649 |
+
analysis_prompt = f"""
|
650 |
+
Analyze the following part of the contract ({i+1}/{len(chunks)}), identifying clauses that are favorable and unfavorable to each party involved.
|
651 |
+
Highlight potential areas of concern or clauses that could be exploited.
|
652 |
+
Provide specific examples within this part of the contract to support your analysis.
|
653 |
|
654 |
+
**Contract Text (Part {i+1}/{len(chunks)}):**
|
655 |
+
{chunk}
|
656 |
+
"""
|
657 |
|
658 |
+
try:
|
659 |
+
chunk_analysis = get_ai_response(analysis_prompt)
|
660 |
+
full_analysis += chunk_analysis + "\n\n"
|
661 |
+
except Exception as e:
|
662 |
+
return {"error": f"Error analyzing part {i+1} of the contract: {str(e)}"}
|
663 |
|
664 |
+
return {"analysis": full_analysis}
|
665 |
|
666 |
def contract_analysis_ui():
|
667 |
st.subheader("Contract Analyzer")
|
|
|
672 |
)
|
673 |
|
674 |
if uploaded_file:
|
675 |
+
contract_text = analyze_uploaded_document(uploaded_file)
|
676 |
|
677 |
if st.button("Analyze Contract"):
|
678 |
with st.spinner("Analyzing contract..."):
|
679 |
analysis_results = analyze_contract(contract_text)
|
680 |
|
681 |
st.write("### Contract Analysis")
|
682 |
+
if "error" in analysis_results:
|
683 |
+
st.error(analysis_results["error"])
|
684 |
+
else:
|
685 |
+
st.write(analysis_results.get("analysis", "No analysis available."))
|
686 |
|
687 |
CASE_TYPES = [
|
688 |
"Civil Rights", "Contract", "Real Property", "Tort", "Labor", "Intellectual Property",
|
|
|
1299 |
text = uploaded_file.getvalue().decode("utf-8")
|
1300 |
return text
|
1301 |
|
|
|
|
|
|
|
1302 |
def generate_legal_brief(case_info):
|
1303 |
chunks = split_text(case_info)
|
1304 |
full_brief = ""
|