Spaces:
Sleeping
Sleeping
Download key_value_extractor.py from productions/Data_Conversion: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/productions/Data_Conversion/resolve/d08709095c3a829b97014a9c4c578e3ebd842db8/key_value_extractor.py
- Command line
-
hf download hf://spaces/productions/Data_Conversion@d08709095c3a829b97014a9c4c578e3ebd842db8/key_value_extractor.py
-
curl -L -o key_value_extractor.py https://huggingface.co/spaces/productions/Data_Conversion/resolve/d08709095c3a829b97014a9c4c578e3ebd842db8/key_value_extractor.py
1.18 kB
| import openai | |
| import os | |
| # Define the KeyValue class | |
| class KeyValue: | |
| def __init__(self): | |
| """ | |
| Initialize the Extractor class. | |
| """ | |
| # Set OpenAI API key | |
| # os.environ["OPENAI_API_KEY"] = "" | |
| def extract_key_value_pair(extracted_summary): | |
| """ | |
| Extract key-value pairs from the refined summary. | |
| Prints the extracted key-value pairs. | |
| """ | |
| try: | |
| # Use OpenAI's Completion API to analyze the text and extract key-value pairs | |
| response = openai.Completion.create( | |
| engine="text-davinci-003", | |
| temperature=0, | |
| prompt=f"analyze the given contract and get meaningful key value pairs in given content.contract in backticks.```{extracted_summary}```.", | |
| max_tokens=1000 | |
| ) | |
| # Extract and return the chatbot's reply | |
| result = response['choices'][0]['text'].strip() | |
| return result | |
| except Exception as e: | |
| # If an error occurs during the key-value extraction process, log the error | |
| print(f"Error occurred while extracting key-value pairs: {str(e)}") | |