Ashar086 commited on
Commit
4dd5497
·
verified ·
1 Parent(s): 923995b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -116,17 +116,17 @@ else:
116
 
117
 
118
  '''
 
 
119
  import streamlit as st
120
  import json
121
- import base64
122
  import openai
123
  import fitz # PyMuPDF
124
  import docx # python-docx
125
 
126
  # Setup for the 3rd party OpenAI API
127
- base_url="https://api.aimlapi.com/v1"
128
- api_key='3fbfe25109b647efb7bf2f45bd667163'
129
-
130
 
131
  # Set the API key for OpenAI
132
  openai.api_key = api_key
@@ -137,9 +137,8 @@ def call_ai_api(prompt, max_tokens=1000, temperature=0.7):
137
  Function to call the 3rd party OpenAI API.
138
  """
139
  try:
140
- response = openai.ChatCompletion.create
141
- #response = client.chat.completions.create(
142
- model="gpt-3.5-turbo", # or the appropriate model for your API
143
  messages=[{"role": "user", "content": prompt}],
144
  max_tokens=max_tokens,
145
  temperature=temperature
@@ -203,9 +202,7 @@ def analyze_contract(file_content, file_type):
203
 
204
  for chunk in chunks:
205
  prompt = f"""Analyze the following contract section and provide a detailed breakdown of its clauses, including their titles, content, risk level, and a brief explanation for each. The document content is as follows:
206
-
207
  {chunk}
208
-
209
  Format your response as a JSON object with a 'clauses' key containing an array of clause objects. Each clause object should have 'title', 'content', 'risk_level', and 'explanation' keys.
210
  """
211
  # Call AI API to analyze each chunk
@@ -237,16 +234,17 @@ if uploaded_file is not None:
237
  clause_decisions = {}
238
 
239
  for i, clause in enumerate(clauses):
240
- st.subheader(f"Clause {i+1}: {clause['title']}")
241
  st.write(clause['content'])
242
  st.write(f"Risk Level: {clause['risk_level']}")
243
  st.write(f"Explanation: {clause['explanation']}")
244
 
245
- decision = st.radio(f"Decision for Clause {i+1}", ["Accept", "Negotiate", "Reject"], key=f"decision_{i}")
246
  clause_decisions[i] = decision
247
 
248
  if decision == "Negotiate":
249
- negotiation_points = st.text_area(f"Enter negotiation points for Clause {i+1}", key=f"negotiation_{i}")
 
250
 
251
  # Finalize Contract button
252
  if st.button("Finalize Contract"):
@@ -254,7 +252,7 @@ if uploaded_file is not None:
254
 
255
  for i, clause in enumerate(clauses):
256
  decision = clause_decisions[i]
257
- prompt += f"Clause {i+1} ({clause['title']}): {decision}\n"
258
  if decision == "Negotiate":
259
  prompt += f"Negotiation points: {clause_decisions.get(f'{i}_points', 'No specific points provided.')}\n"
260
  prompt += "\n"
@@ -274,5 +272,3 @@ if uploaded_file is not None:
274
  st.write("No clauses found in the contract analysis. Please try again.")
275
  else:
276
  st.write("Please upload a contract to begin the analysis.")
277
-
278
-
 
116
 
117
 
118
  '''
119
+
120
+
121
  import streamlit as st
122
  import json
 
123
  import openai
124
  import fitz # PyMuPDF
125
  import docx # python-docx
126
 
127
  # Setup for the 3rd party OpenAI API
128
+ base_url = "https://api.aimlapi.com/v1"
129
+ api_key = '3fbfe25109b647efb7bf2f45bd667163'
 
130
 
131
  # Set the API key for OpenAI
132
  openai.api_key = api_key
 
137
  Function to call the 3rd party OpenAI API.
138
  """
139
  try:
140
+ response = openai.ChatCompletion.create(
141
+ model="gpt-3.5-turbo", # or the appropriate model for your API
 
142
  messages=[{"role": "user", "content": prompt}],
143
  max_tokens=max_tokens,
144
  temperature=temperature
 
202
 
203
  for chunk in chunks:
204
  prompt = f"""Analyze the following contract section and provide a detailed breakdown of its clauses, including their titles, content, risk level, and a brief explanation for each. The document content is as follows:
 
205
  {chunk}
 
206
  Format your response as a JSON object with a 'clauses' key containing an array of clause objects. Each clause object should have 'title', 'content', 'risk_level', and 'explanation' keys.
207
  """
208
  # Call AI API to analyze each chunk
 
234
  clause_decisions = {}
235
 
236
  for i, clause in enumerate(clauses):
237
+ st.subheader(f"Clause {i + 1}: {clause['title']}")
238
  st.write(clause['content'])
239
  st.write(f"Risk Level: {clause['risk_level']}")
240
  st.write(f"Explanation: {clause['explanation']}")
241
 
242
+ decision = st.radio(f"Decision for Clause {i + 1}", ["Accept", "Negotiate", "Reject"], key=f"decision_{i}")
243
  clause_decisions[i] = decision
244
 
245
  if decision == "Negotiate":
246
+ negotiation_points = st.text_area(f"Enter negotiation points for Clause {i + 1}", key=f"negotiation_{i}")
247
+ clause_decisions[f"{i}_points"] = negotiation_points # Save negotiation points
248
 
249
  # Finalize Contract button
250
  if st.button("Finalize Contract"):
 
252
 
253
  for i, clause in enumerate(clauses):
254
  decision = clause_decisions[i]
255
+ prompt += f"Clause {i + 1} ({clause['title']}): {decision}\n"
256
  if decision == "Negotiate":
257
  prompt += f"Negotiation points: {clause_decisions.get(f'{i}_points', 'No specific points provided.')}\n"
258
  prompt += "\n"
 
272
  st.write("No clauses found in the contract analysis. Please try again.")
273
  else:
274
  st.write("Please upload a contract to begin the analysis.")