Spaces:
Running
Running
Baskar2005
commited on
Update extract_date.py
Browse files- extract_date.py +18 -8
extract_date.py
CHANGED
@@ -33,6 +33,7 @@ class ExtractDateAndDuration:
|
|
33 |
"""
|
34 |
Initialize the ExtractDateAndDuration class.
|
35 |
"""
|
|
|
36 |
pass
|
37 |
|
38 |
def get_date_and_duration(self, contract_text: str) -> str:
|
@@ -46,16 +47,25 @@ class ExtractDateAndDuration:
|
|
46 |
str: Extracted dates and durations.
|
47 |
"""
|
48 |
try:
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
temperature=0
|
56 |
)
|
57 |
-
|
58 |
-
return
|
59 |
|
60 |
except Exception as e:
|
61 |
LOGGER.error(f"An error occurred during text analysis: {str(e)}")
|
|
|
33 |
"""
|
34 |
Initialize the ExtractDateAndDuration class.
|
35 |
"""
|
36 |
+
self.client=OpenAI()
|
37 |
pass
|
38 |
|
39 |
def get_date_and_duration(self, contract_text: str) -> str:
|
|
|
47 |
str: Extracted dates and durations.
|
48 |
"""
|
49 |
try:
|
50 |
+
conversation = [
|
51 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
52 |
+
{"role": "user", "content": f"""Your task is Identify Dates and Durations Mentioned in the contract and extract that date and duration in key-value pair.
|
53 |
+
```contract: {contract_text}```
|
54 |
+
format:
|
55 |
+
date:extracted date
|
56 |
+
Durations:extracted Durations
|
57 |
+
"""}
|
58 |
+
]
|
59 |
+
|
60 |
+
# Call OpenAI GPT-3.5-turbo
|
61 |
+
chat_completion = client.chat.completions.create(
|
62 |
+
model = "gpt-3.5-turbo",
|
63 |
+
messages = conversation,
|
64 |
+
max_tokens=1000,
|
65 |
temperature=0
|
66 |
)
|
67 |
+
response = chat_completion.choices[0].message.content
|
68 |
+
return response
|
69 |
|
70 |
except Exception as e:
|
71 |
LOGGER.error(f"An error occurred during text analysis: {str(e)}")
|