Spaces:
Sleeping
Sleeping
Update headings_extractor.py
Browse files- headings_extractor.py +15 -8
headings_extractor.py
CHANGED
|
@@ -16,7 +16,7 @@ class HeadingsExtractor:
|
|
| 16 |
Returns:
|
| 17 |
str: Extracted headings.
|
| 18 |
"""
|
| 19 |
-
|
| 20 |
|
| 21 |
def file_output_fnn(self,file_path):
|
| 22 |
file_path = file_path.name
|
|
@@ -35,15 +35,22 @@ class HeadingsExtractor:
|
|
| 35 |
"""
|
| 36 |
try:
|
| 37 |
#get response from openai api
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
temperature=0
|
| 44 |
)
|
| 45 |
-
|
| 46 |
-
return
|
| 47 |
|
| 48 |
except Exception as e:
|
| 49 |
# If an error occurs during the key-value extraction process, log the error
|
|
|
|
| 16 |
Returns:
|
| 17 |
str: Extracted headings.
|
| 18 |
"""
|
| 19 |
+
self.client=OpenAI()
|
| 20 |
|
| 21 |
def file_output_fnn(self,file_path):
|
| 22 |
file_path = file_path.name
|
|
|
|
| 35 |
"""
|
| 36 |
try:
|
| 37 |
#get response from openai api
|
| 38 |
+
|
| 39 |
+
conversation = [
|
| 40 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
| 41 |
+
{"role": "user", "content": f"""Extract Headings from given paragraph do not generate jsu extract the headings from paragraph.
|
| 42 |
+
```paragraph :{contract_page}```"""}
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
# Call OpenAI GPT-3.5-turbo
|
| 46 |
+
chat_completion =self.client.chat.completions.create(
|
| 47 |
+
model = "gpt-3.5-turbo",
|
| 48 |
+
messages = conversation,
|
| 49 |
+
max_tokens=1000,
|
| 50 |
temperature=0
|
| 51 |
)
|
| 52 |
+
response = chat_completion.choices[0].message.content
|
| 53 |
+
return response
|
| 54 |
|
| 55 |
except Exception as e:
|
| 56 |
# If an error occurs during the key-value extraction process, log the error
|