Ashar086 commited on
Commit
de3a5aa
·
verified ·
1 Parent(s): 07bb588

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -17
app.py CHANGED
@@ -1,21 +1,29 @@
1
  import requests
2
  import streamlit as st
3
- import torch
4
- from transformers import pipeline
5
 
6
- # Initialize Llama 3.2 model
7
- @st.cache_resource
8
- def load_model():
9
- model_id = "meta-llama/Llama-3.2-1B"
10
- pipe = pipeline(
11
- "text-generation",
12
- model=model_id,
13
- torch_dtype=torch.bfloat16,
14
- device_map="auto"
15
- )
16
- return pipe
17
 
18
- pipe = load_model()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  def call_llama_for_response(clauses_data):
21
  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"
@@ -31,8 +39,8 @@ def call_llama_for_response(clauses_data):
31
 
32
  prompt += "Draft a response that addresses each clause, explaining our position on acceptance, rejection, or negotiation. The tone should be professional, courteous, and constructive."
33
 
34
- response = pipe(prompt, max_new_tokens=500, do_sample=True, temperature=0.7)
35
- return response[0]['generated_text']
36
 
37
  st.title("Contract Negotiation Assistant")
38
 
@@ -112,4 +120,4 @@ if st.session_state.uploaded_file is not None:
112
  st.success("Contract negotiation completed. Response generated for review.")
113
 
114
  else:
115
- st.write("Please upload a contract to begin the analysis.")
 
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
 
 
 
 
 
 
 
 
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"
 
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
 
 
120
  st.success("Contract negotiation completed. Response generated for review.")
121
 
122
  else:
123
+ st.write("Please upload a contract to begin the analysis.")