Ashar086 commited on
Commit
7e6bc54
·
verified ·
1 Parent(s): 3954c69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -128
app.py CHANGED
@@ -137,131 +137,4 @@ if st.session_state.uploaded_file is not None:
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
150
-
151
- def call_ai_ml_api(prompt):
152
- headers = {
153
- "Authorization": f"Bearer {API_KEY}",
154
- "Content-Type": "application/json",
155
- }
156
- payload = {
157
- "model": "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
158
- "prompt": prompt,
159
- "max_new_tokens": 500,
160
- "temperature": 0.7,
161
- }
162
-
163
- response = requests.post(API_URL, headers=headers, json=payload)
164
-
165
- if response.status_code == 200:
166
- return response.json()["generated_text"]
167
- else:
168
- st.error("Failed to generate response from AI/ML API.")
169
- return ""
170
-
171
- def call_llama_for_response(clauses_data):
172
- 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"
173
-
174
- for clause in clauses_data:
175
- prompt += f"Clause: {clause['agent']}\n"
176
- prompt += f"Analysis: {clause['analysis']}\n"
177
- prompt += f"Recommendation: {clause['recommendation']}\n"
178
- prompt += f"Decision: {clause['action']}\n"
179
- if clause['action'] == 'Negotiate':
180
- prompt += f"Negotiation points: {clause['negotiation_points']}\n"
181
- prompt += "\n"
182
-
183
- prompt += "Draft a response that addresses each clause, explaining our position on acceptance, rejection, or negotiation. The tone should be professional, courteous, and constructive."
184
-
185
- response = call_ai_ml_api(prompt)
186
- return response
187
-
188
- st.title("Contract Negotiation Assistant")
189
-
190
- # Use session state to store the uploaded file and analysis results
191
- if 'uploaded_file' not in st.session_state:
192
- st.session_state.uploaded_file = None
193
- if 'analysis_results' not in st.session_state:
194
- st.session_state.analysis_results = None
195
-
196
- # File uploader
197
- uploaded_file = st.file_uploader("Upload Contract", type=["pdf", "docx"])
198
-
199
- # If a new file is uploaded, update the session state and clear previous results
200
- if uploaded_file is not None and uploaded_file != st.session_state.uploaded_file:
201
- st.session_state.uploaded_file = uploaded_file
202
- st.session_state.analysis_results = None
203
-
204
- # If we have an uploaded file, process it
205
- if st.session_state.uploaded_file is not None:
206
- # Only call the API if we don't have analysis results yet
207
- if st.session_state.analysis_results is None:
208
- files = {"file": st.session_state.uploaded_file}
209
- response = requests.post("http://localhost:5002/upload", files=files)
210
- if response.status_code == 200:
211
- st.write("Contract uploaded successfully. Analyzing...")
212
- st.session_state.analysis_results = response.json()
213
- else:
214
- st.error("Failed to analyze the contract. Please try again.")
215
-
216
- # If we have analysis results, display them and allow user interaction
217
- if st.session_state.analysis_results is not None:
218
- data = st.session_state.analysis_results
219
- segmented_contract = data.get("segmented_contract", {})
220
- crew_analysis = data.get("crew_analysis", {})
221
-
222
- # Extract the tasks_output from the nested structure
223
- tasks_output = crew_analysis.get("final_recommendation", {}).get("tasks_output", [])
224
-
225
- clauses_data = []
226
- for task in tasks_output:
227
- agent = task.get("agent", "")
228
- if task.get("pydantic"):
229
- clause_analysis = task["pydantic"].get("analysis", "")
230
- recommendation = task["pydantic"].get("recommendation", "")
231
-
232
- st.subheader(f"Clause: {agent}")
233
- st.write("Analysis:")
234
- st.write(clause_analysis)
235
- st.write("Recommendation:")
236
- st.write(recommendation)
237
-
238
- action = st.selectbox(
239
- f"Action for {agent}",
240
- ["Accept", "Negotiate", "Reject"],
241
- key=f"action_{agent}"
242
- )
243
- negotiation_points = ""
244
- if action == "Negotiate":
245
- negotiation_points = st.text_area("Enter your negotiation points:", key=f"negotiate_{agent}")
246
-
247
- clauses_data.append({
248
- "agent": agent,
249
- "analysis": clause_analysis,
250
- "recommendation": recommendation,
251
- "action": action,
252
- "negotiation_points": negotiation_points
253
- })
254
-
255
- st.markdown("---") # Add a separator between clauses
256
-
257
- # Finalize Contract button
258
- if st.button("Finalize Contract"):
259
- with st.spinner("Generating response..."):
260
- response_to_drafter = call_llama_for_response(clauses_data)
261
- st.subheader("Response to Contract Drafter:")
262
- st.text_area("", response_to_drafter, height=400)
263
- st.success("Contract negotiation completed. Response generated for review.")
264
-
265
- else:
266
- st.write("Please upload a contract to begin the analysis.")
267
- '''
 
137
  st.success("Contract negotiation completed. Response generated for review.")
138
 
139
  else:
140
+ st.write("Please upload a contract to begin the analysis.")