MadMarx37 commited on
Commit
2c57572
·
1 Parent(s): 98c73a3

change app

Browse files
Files changed (2) hide show
  1. app.py +112 -2
  2. requirements.txt +3 -0
app.py CHANGED
@@ -1,4 +1,114 @@
 
1
  import streamlit as st
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
  import streamlit as st
3
+ from together import Together
4
 
5
+ # Initialize Together AI client
6
+ client = Together(api_key=st.secrets["TOGETHER_API_KEY"])
7
+
8
+ def call_llama_for_response(clauses_data):
9
+ 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"
10
+
11
+ for clause in clauses_data:
12
+ prompt += f"Clause: {clause['agent']}\n"
13
+ prompt += f"Analysis: {clause['analysis']}\n"
14
+ prompt += f"Recommendation: {clause['recommendation']}\n"
15
+ prompt += f"Decision: {clause['action']}\n"
16
+ if clause['action'] == 'Negotiate':
17
+ prompt += f"Negotiation points: {clause['negotiation_points']}\n"
18
+ prompt += "\n"
19
+
20
+ prompt += "Draft a response that addresses each clause, explaining our position on acceptance, rejection, or negotiation. The tone should be professional, courteous, and constructive."
21
+
22
+ response = client.chat.completions.create(
23
+ model="meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
24
+ messages=[{"role": "user", "content": prompt}],
25
+ max_tokens=2048,
26
+ temperature=0.3,
27
+ top_p=0.8,
28
+ top_k=50,
29
+ repetition_penalty=1,
30
+ stop=["<|eot_id|>", "<|eom_id|>"],
31
+ stream=False
32
+ )
33
+ return response.choices[0].message.content
34
+
35
+ st.title("Contract Negotiation Assistant")
36
+
37
+ # Use session state to store the uploaded file and analysis results
38
+ if 'uploaded_file' not in st.session_state:
39
+ st.session_state.uploaded_file = None
40
+ if 'analysis_results' not in st.session_state:
41
+ st.session_state.analysis_results = None
42
+
43
+ # File uploader
44
+ uploaded_file = st.file_uploader("Upload Contract", type=["pdf", "docx"])
45
+
46
+ # If a new file is uploaded, update the session state and clear previous results
47
+ if uploaded_file is not None and uploaded_file != st.session_state.uploaded_file:
48
+ st.session_state.uploaded_file = uploaded_file
49
+ st.session_state.analysis_results = None
50
+
51
+ # If we have an uploaded file, process it
52
+ if st.session_state.uploaded_file is not None:
53
+ # Only call the API if we don't have analysis results yet
54
+ if st.session_state.analysis_results is None:
55
+ files = {"file": st.session_state.uploaded_file}
56
+ with st.status("Contract uploaded successfully. Analyzing..."):
57
+ st.write("Analysing data...")
58
+ response = requests.post("http://35.172.179.19:5002/upload", files=files)
59
+ if response.status_code == 200:
60
+ st.session_state.analysis_results = response.json()
61
+ else:
62
+ st.error("Failed to analyze the contract. Please try again.")
63
+
64
+ # If we have analysis results, display them and allow user interaction
65
+ if st.session_state.analysis_results is not None:
66
+ data = st.session_state.analysis_results
67
+ segmented_contract = data.get("segmented_contract", {})
68
+ crew_analysis = data.get("crew_analysis", {})
69
+
70
+ # Extract the tasks_output from the nested structure
71
+ tasks_output = crew_analysis.get("final_recommendation", {}).get("tasks_output", [])
72
+
73
+ clauses_data = []
74
+ for task in tasks_output:
75
+ agent = task.get("agent", "")
76
+ if task.get("pydantic"):
77
+ clause_analysis = task["pydantic"].get("analysis", "")
78
+ recommendation = task["pydantic"].get("recommendation", "")
79
+
80
+ st.subheader(f"Clause: {agent}")
81
+ st.write("Analysis:")
82
+ st.write(clause_analysis)
83
+ st.write("Recommendation:")
84
+ st.write(recommendation)
85
+
86
+ action = st.selectbox(
87
+ f"Action for {agent}",
88
+ ["Accept", "Negotiate", "Reject"],
89
+ key=f"action_{agent}"
90
+ )
91
+ negotiation_points = ""
92
+ if action == "Negotiate":
93
+ negotiation_points = st.text_area("Enter your negotiation points:", key=f"negotiate_{agent}")
94
+
95
+ clauses_data.append({
96
+ "agent": agent,
97
+ "analysis": clause_analysis,
98
+ "recommendation": recommendation,
99
+ "action": action,
100
+ "negotiation_points": negotiation_points
101
+ })
102
+
103
+ st.markdown("---") # Add a separator between clauses
104
+
105
+ # Finalize Contract button
106
+ if st.button("Finalize Contract"):
107
+ with st.spinner("Generating response..."):
108
+ response_to_drafter = call_llama_for_response(clauses_data)
109
+ st.subheader("Response to Contract Drafter:")
110
+ st.text_area("", response_to_drafter, height=400)
111
+ st.success("Contract negotiation completed. Response generated for review.")
112
+
113
+ else:
114
+ st.write("Please upload a contract to begin the analysis.")
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit=="^1.38.0"
2
+ together=="^1.2.12"
3
+ requests=="^2.32.3"