Spaces:
Running
Running
naveenvenkatesh
commited on
Commit
•
f638900
1
Parent(s):
c425da2
Update Clauses_Extractor.py
Browse files- Clauses_Extractor.py +17 -24
Clauses_Extractor.py
CHANGED
@@ -1,18 +1,14 @@
|
|
1 |
import openai
|
2 |
import os
|
3 |
-
|
4 |
|
5 |
# Define the Clauses class
|
6 |
class Clauses:
|
7 |
def __init__(self):
|
8 |
-
"""
|
9 |
-
Initialize the Extractor class.
|
10 |
-
"""
|
11 |
|
12 |
-
|
13 |
-
# os.environ["OPENAI_API_KEY"] = ""
|
14 |
|
15 |
-
def get_extracted_clauses(extracted_summary):
|
16 |
"""
|
17 |
Gets extracted clauses using GPT-3 based on the provided PDF.
|
18 |
|
@@ -23,24 +19,21 @@ class Clauses:
|
|
23 |
str: Extracted clauses from GPT-3 response.
|
24 |
"""
|
25 |
try:
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
max_tokens=1000
|
39 |
)
|
40 |
-
|
41 |
-
|
42 |
-
result = response['choices'][0]['text'].strip()
|
43 |
-
return result
|
44 |
|
45 |
except Exception as e:
|
46 |
# If an error occurs during GPT-3 processing, log the error and raise an exception
|
|
|
1 |
import openai
|
2 |
import os
|
3 |
+
from openai import OpenAI
|
4 |
|
5 |
# Define the Clauses class
|
6 |
class Clauses:
|
7 |
def __init__(self):
|
|
|
|
|
|
|
8 |
|
9 |
+
self.client = OpenAI()
|
|
|
10 |
|
11 |
+
def get_extracted_clauses(self,extracted_summary):
|
12 |
"""
|
13 |
Gets extracted clauses using GPT-3 based on the provided PDF.
|
14 |
|
|
|
19 |
str: Extracted clauses from GPT-3 response.
|
20 |
"""
|
21 |
try:
|
22 |
+
conversation = [
|
23 |
+
{"role": "system", "content": "You are a helpful Cluases and SubCluases Extracter From Given Content."},
|
24 |
+
{"role": "user", "content": f"""Extract clauses and sub-clauses from the provided contract PDF
|
25 |
+
{extracted_summary}"""}
|
26 |
+
]
|
27 |
+
|
28 |
+
# Call OpenAI GPT-3.5-turbo
|
29 |
+
chat_completion = self.client.chat.completions.create(
|
30 |
+
model = "gpt-3.5-turbo",
|
31 |
+
messages = conversation,
|
32 |
+
max_tokens=500,
|
33 |
+
temperature=0
|
|
|
34 |
)
|
35 |
+
response = chat_completion.choices[0].message.content
|
36 |
+
return response
|
|
|
|
|
37 |
|
38 |
except Exception as e:
|
39 |
# If an error occurs during GPT-3 processing, log the error and raise an exception
|