Spaces:
Sleeping
Sleeping
Download Clauses_Extractor.py from productions/Data_Conversion: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/spaces/productions/Data_Conversion/resolve/3c65a2f58851027e1d5d2401dfd885e7b4f3fd96/Clauses_Extractor.py
- Command line
-
hf download hf://spaces/productions/Data_Conversion@3c65a2f58851027e1d5d2401dfd885e7b4f3fd96/Clauses_Extractor.py
-
curl -L -o Clauses_Extractor.py https://huggingface.co/spaces/productions/Data_Conversion/resolve/3c65a2f58851027e1d5d2401dfd885e7b4f3fd96/Clauses_Extractor.py
1.48 kB
| import openai | |
| import os | |
| from openai import OpenAI | |
| # Define the Clauses class | |
| class Clauses: | |
| def __init__(self): | |
| self.client = OpenAI() | |
| def get_extracted_clauses(self,extracted_summary): | |
| """ | |
| Gets extracted clauses using GPT-3 based on the provided PDF. | |
| Args: | |
| max_tokens (int, optional): Maximum number of tokens for GPT-3 response. | |
| Returns: | |
| str: Extracted clauses from GPT-3 response. | |
| """ | |
| try: | |
| conversation = [ | |
| {"role": "system", "content": "You are a helpful Cluases and SubCluases Extracter From Given Content."}, | |
| {"role": "user", "content": f"""Extract clauses and sub-clauses from the provided contract PDF | |
| {extracted_summary}"""} | |
| ] | |
| # Call OpenAI GPT-3.5-turbo | |
| chat_completion = self.client.chat.completions.create( | |
| model = "gpt-3.5-turbo", | |
| messages = conversation, | |
| max_tokens=500, | |
| temperature=0 | |
| ) | |
| response = chat_completion.choices[0].message.content | |
| return response | |
| except Exception as e: | |
| # If an error occurs during GPT-3 processing, log the error and raise an exception | |
| print(f"Error occurred while processing PDF with GPT-3. Error message: {str(e)}") | |
| raise | |