-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d926f49
commit 19ea4b4
Showing
9 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const dotnetApiUrl = "https://cf-contract-analysis-mvp.azurewebsites.net"; | ||
// export const dotnetApiUrl = "https://localhost:7254"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
from dotenv import load_dotenv | ||
from azure.core.credentials import AzureKeyCredential | ||
from azure.ai.formrecognizer import DocumentAnalysisClient | ||
from openai import OpenAI | ||
|
||
from prompt import system_prompt | ||
|
||
load_dotenv() | ||
azure_key = os.getenv("AZURE_KEY") | ||
azure_service_endpoint = os.getenv("AZURE_SERVICE_ENDPOINT") | ||
open_ai_org_id = os.getenv("OPEN_AI_ORG_ID") | ||
|
||
document_analysis_client = DocumentAnalysisClient( | ||
endpoint=azure_service_endpoint, credential=AzureKeyCredential(azure_key) | ||
) | ||
|
||
client = OpenAI() | ||
|
||
|
||
def analyze_contract(path_to_file): | ||
print("Uploading to Azure Document AI...") | ||
print("________________________________________") | ||
|
||
with open(path_to_file, "rb") as f: | ||
poller = document_analysis_client.begin_analyze_document( | ||
"prebuilt-read", document=f | ||
) | ||
|
||
result = poller.result() | ||
|
||
print("File read by Azure Document AI") | ||
print("Uploading file content to Open AI API...") | ||
print("________________________________________") | ||
|
||
messages = system_prompt | ||
|
||
messages.append({"role": "user", "content": "Upload Starting Now."}) | ||
for paragraph in result.paragraphs: | ||
messages.append({"role": "user", "content": paragraph.content}) | ||
|
||
messages.append({"role": "user", "content": "Please Start Summary Results."}) | ||
|
||
response = client.chat.completions.create(model="gpt-3.5-turbo", messages=messages) | ||
|
||
print("Contract Summary Results:") | ||
print("________________________________________") | ||
|
||
print(response.choices[0].message.content) | ||
|
||
|
||
if __name__ == "__main__": | ||
analyze_contract( | ||
"/Users/kaden/dev/cf/sample-contract-files/AmendmentToContract.pdf" | ||
) | ||
# analyze_contract( | ||
# "/Users/kaden/dev/cf/sample-contract-files/FarmAndRanchContract.pdf" | ||
# ) | ||
# analyze_contract( | ||
# "/Users/kaden/dev/cf/sample-contract-files/Sample_Utah_Real_Estate_Contract.pdf" | ||
# ) | ||
# analyze_contract("/Users/kaden/dev/cf/sample-contract-files/SimpleContract.pdf") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import PyPDF2 | ||
|
||
|
||
def try_parse_pdf(path_to_file): | ||
pdfFileObj = open(path_to_file, "rb") | ||
|
||
pdfReader = PyPDF2.PdfReader(pdfFileObj) | ||
print(len(pdfReader.pages)) | ||
|
||
pageObj = pdfReader.pages[0] | ||
print(pageObj.extract_text()) | ||
|
||
pdfFileObj.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
try_parse_pdf("/Users/kaden/dev/cf/sample-contract-files/AmendmentToContract.pdf") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
system_prompt = [ | ||
{ | ||
"role": "system", | ||
"content": "You are a document research assistant that reads long files and summarizes them.", | ||
}, | ||
{ | ||
"role": "system", | ||
"content": "The conversation will start by the user saying 'Upload Starting Now.' The user will then provide you with document paragraphs.", | ||
}, | ||
{ | ||
"role": "system", | ||
"content": "You will not answer until the user has asked, 'Please Start Summary Results.'", | ||
}, | ||
{ | ||
"role": "system", | ||
"content": "You will then provide the most accurate details about the current information given to you.", | ||
}, | ||
{ | ||
"role": "system", | ||
"content": "You will start by listing in bullet points the following information: Buyer Name (if applicable), Seller Name (if applicable), Contract Amount (if applicable), Contract Key Dates, and Contract Property Address (if applicable).", | ||
}, | ||
{ | ||
"role": "system", | ||
"content": "After providing that information, you will give a summary of all other major details in paragraph form.", | ||
}, | ||
] |