Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,149 @@
|
|
1 |
import requests
|
2 |
import streamlit as st
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
# Set your API key here
|
5 |
API_KEY = "3fbfe25109b647efb7bf2f45bd667163" # Replace with your actual API key
|
6 |
API_URL = "https://aimlapi.com/v1" # Replace with the actual API endpoint
|
@@ -121,3 +264,4 @@ if st.session_state.uploaded_file is not None:
|
|
121 |
|
122 |
else:
|
123 |
st.write("Please upload a contract to begin the analysis.")
|
|
|
|
1 |
import requests
|
2 |
import streamlit as st
|
3 |
|
4 |
+
# Set your API key and endpoint here
|
5 |
+
API_KEY = "3fbfe25109b647efb7bf2f45bd667163" # Replace with your actual API key
|
6 |
+
API_URL = "https://aimlapi.com/" # Replace with the actual API endpoint
|
7 |
+
|
8 |
+
def call_ai_ml_api(prompt):
|
9 |
+
headers = {
|
10 |
+
"Authorization": f"Bearer {API_KEY}",
|
11 |
+
"Content-Type": "application/json",
|
12 |
+
}
|
13 |
+
payload = {
|
14 |
+
"model": "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
|
15 |
+
"prompt": prompt,
|
16 |
+
"max_new_tokens": 500,
|
17 |
+
"temperature": 0.7,
|
18 |
+
}
|
19 |
+
|
20 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
21 |
+
|
22 |
+
if response.status_code == 200:
|
23 |
+
return response.json()["generated_text"]
|
24 |
+
else:
|
25 |
+
st.error("Failed to generate response from AI/ML API.")
|
26 |
+
return ""
|
27 |
+
|
28 |
+
def call_llama_for_response(clauses_data):
|
29 |
+
prompt = "As an AI assistant specializing in contract analysis, draft a professional and courteous response to a contract drafter based on the following clause analyses and decisions:\n\n"
|
30 |
+
|
31 |
+
for clause in clauses_data:
|
32 |
+
prompt += f"Clause: {clause['agent']}\n"
|
33 |
+
prompt += f"Analysis: {clause['analysis']}\n"
|
34 |
+
prompt += f"Recommendation: {clause['recommendation']}\n"
|
35 |
+
prompt += f"Decision: {clause['action']}\n"
|
36 |
+
if clause['action'] == 'Negotiate':
|
37 |
+
prompt += f"Negotiation points: {clause['negotiation_points']}\n"
|
38 |
+
prompt += "\n"
|
39 |
+
|
40 |
+
prompt += "Draft a response that addresses each clause, explaining our position on acceptance, rejection, or negotiation. The tone should be professional, courteous, and constructive."
|
41 |
+
|
42 |
+
response = call_ai_ml_api(prompt)
|
43 |
+
return response
|
44 |
+
|
45 |
+
st.title("Contract Negotiation Assistant")
|
46 |
+
|
47 |
+
# Use session state to store the uploaded file and analysis results
|
48 |
+
if 'uploaded_file' not in st.session_state:
|
49 |
+
st.session_state.uploaded_file = None
|
50 |
+
if 'analysis_results' not in st.session_state:
|
51 |
+
st.session_state.analysis_results = None
|
52 |
+
|
53 |
+
# File uploader
|
54 |
+
uploaded_file = st.file_uploader("Upload Contract", type=["pdf", "docx"])
|
55 |
+
|
56 |
+
# If a new file is uploaded, update the session state and clear previous results
|
57 |
+
if uploaded_file is not None and uploaded_file != st.session_state.uploaded_file:
|
58 |
+
st.session_state.uploaded_file = uploaded_file
|
59 |
+
st.session_state.analysis_results = None
|
60 |
+
|
61 |
+
# If we have an uploaded file, process it
|
62 |
+
if st.session_state.uploaded_file is not None:
|
63 |
+
# Simulate analysis of the uploaded contract (you may replace this with your actual analysis logic)
|
64 |
+
# For now, we just mock some analysis results for demonstration purposes
|
65 |
+
st.write("Contract uploaded successfully. Analyzing...")
|
66 |
+
|
67 |
+
# Example of simulated analysis results
|
68 |
+
st.session_state.analysis_results = {
|
69 |
+
"crew_analysis": {
|
70 |
+
"final_recommendation": {
|
71 |
+
"tasks_output": [
|
72 |
+
{
|
73 |
+
"agent": "Clause 1",
|
74 |
+
"pydantic": {
|
75 |
+
"analysis": "This clause limits liability.",
|
76 |
+
"recommendation": "Consider revising for fairness."
|
77 |
+
}
|
78 |
+
},
|
79 |
+
{
|
80 |
+
"agent": "Clause 2",
|
81 |
+
"pydantic": {
|
82 |
+
"analysis": "This clause outlines payment terms.",
|
83 |
+
"recommendation": "This is acceptable."
|
84 |
+
}
|
85 |
+
}
|
86 |
+
]
|
87 |
+
}
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
# If we have analysis results, display them and allow user interaction
|
92 |
+
if st.session_state.analysis_results is not None:
|
93 |
+
data = st.session_state.analysis_results
|
94 |
+
crew_analysis = data.get("crew_analysis", {})
|
95 |
+
|
96 |
+
# Extract the tasks_output from the nested structure
|
97 |
+
tasks_output = crew_analysis.get("final_recommendation", {}).get("tasks_output", [])
|
98 |
+
|
99 |
+
clauses_data = []
|
100 |
+
for task in tasks_output:
|
101 |
+
agent = task.get("agent", "")
|
102 |
+
if task.get("pydantic"):
|
103 |
+
clause_analysis = task["pydantic"].get("analysis", "")
|
104 |
+
recommendation = task["pydantic"].get("recommendation", "")
|
105 |
+
|
106 |
+
st.subheader(f"Clause: {agent}")
|
107 |
+
st.write("Analysis:")
|
108 |
+
st.write(clause_analysis)
|
109 |
+
st.write("Recommendation:")
|
110 |
+
st.write(recommendation)
|
111 |
+
|
112 |
+
action = st.selectbox(
|
113 |
+
f"Action for {agent}",
|
114 |
+
["Accept", "Negotiate", "Reject"],
|
115 |
+
key=f"action_{agent}"
|
116 |
+
)
|
117 |
+
negotiation_points = ""
|
118 |
+
if action == "Negotiate":
|
119 |
+
negotiation_points = st.text_area("Enter your negotiation points:", key=f"negotiate_{agent}")
|
120 |
+
|
121 |
+
clauses_data.append({
|
122 |
+
"agent": agent,
|
123 |
+
"analysis": clause_analysis,
|
124 |
+
"recommendation": recommendation,
|
125 |
+
"action": action,
|
126 |
+
"negotiation_points": negotiation_points
|
127 |
+
})
|
128 |
+
|
129 |
+
st.markdown("---") # Add a separator between clauses
|
130 |
+
|
131 |
+
# Finalize Contract button
|
132 |
+
if st.button("Finalize Contract"):
|
133 |
+
with st.spinner("Generating response..."):
|
134 |
+
response_to_drafter = call_llama_for_response(clauses_data)
|
135 |
+
st.subheader("Response to Contract Drafter:")
|
136 |
+
st.text_area("", response_to_drafter, height=400)
|
137 |
+
st.success("Contract negotiation completed. Response generated for review.")
|
138 |
+
|
139 |
+
else:
|
140 |
+
st.write("Please upload a contract to begin the analysis.")
|
141 |
+
|
142 |
+
|
143 |
+
'''
|
144 |
+
import requests
|
145 |
+
import streamlit as st
|
146 |
+
|
147 |
# Set your API key here
|
148 |
API_KEY = "3fbfe25109b647efb7bf2f45bd667163" # Replace with your actual API key
|
149 |
API_URL = "https://aimlapi.com/v1" # Replace with the actual API endpoint
|
|
|
264 |
|
265 |
else:
|
266 |
st.write("Please upload a contract to begin the analysis.")
|
267 |
+
'''
|