Update verifier.py
Browse files- verifier.py +48 -48
verifier.py
CHANGED
|
@@ -61,56 +61,56 @@ def verifier_page():
|
|
| 61 |
st.session_state.selected_text = row['text']
|
| 62 |
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
# Configure AI (this could be dynamic depending on how your setup works)
|
| 103 |
-
GOOGLE_API_KEY = "AIzaSyC7TpzrIH_3-dppWE8exqdZX3DAdE6cy8w"
|
| 104 |
-
genai.configure(api_key=GOOGLE_API_KEY)
|
| 105 |
-
|
| 106 |
-
# Example of working with LLM models (Gemini 1.5)
|
| 107 |
-
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 108 |
-
|
| 109 |
-
# Generate the AI response based on the text of the selected file
|
| 110 |
-
response = model.generate_content("You are a project verifier officer at Verra, the leading registry for projects used to generate carbon credits. Your job is to look into project submissions from project developers who create an implement nature-based solutions in order to generate carbon credits. You go through the content of the project submissions to investigate whether the submission fits into the vcs standards, methodology requirements, and touches everything on the project description template. A verifier has to compare the submission to these 3 main criteria. As a verifier, I want you to evaluate the project submission below based on the resources listed below. The output should be in the format of summary of the project submission, the level of adherence to the standards, what needs to be fixed, and notes for improvement for project developers. The output needs to have project-specific feedback. You can bolster your feedback with quotes from the submission or referencing numbers mentioned in the submission. Here is the project submission:" + st.session_state.selected_text + "Here is the vcs standards:" + vcs_text + "Here is the methodology requirement:" + methodology_text + "Here is the project description template:" + template_text)
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
# Display the selected file and AI response
|
| 116 |
st.title(f"Selected File: {st.session_state.selected_file}")
|
|
|
|
| 61 |
st.session_state.selected_text = row['text']
|
| 62 |
|
| 63 |
|
| 64 |
+
def extract_text_from_pdf(uploaded_file, start_page, end_page):
|
| 65 |
+
if uploaded_file is None:
|
| 66 |
+
return "" # Return an empty string if no file is uploaded
|
| 67 |
+
|
| 68 |
+
reader = PyPDF2.PdfReader(uploaded_file)
|
| 69 |
+
num_pages = len(reader.pages)
|
| 70 |
+
|
| 71 |
+
if start_page < 0 or start_page >= num_pages:
|
| 72 |
+
start_page = 0
|
| 73 |
+
if end_page < start_page or end_page >= num_pages:
|
| 74 |
+
end_page = num_pages - 1
|
| 75 |
+
|
| 76 |
+
text = ''
|
| 77 |
+
for page_num in range(start_page, end_page + 1):
|
| 78 |
+
page = reader.pages[page_num]
|
| 79 |
+
text += page.extract_text()
|
| 80 |
+
|
| 81 |
+
return text
|
|
|
|
| 82 |
|
| 83 |
+
|
| 84 |
+
pdf_path = 'VCS-Standard.pdf'
|
| 85 |
+
start_page = 0 # Start extracting from the first page (0-based index)
|
| 86 |
+
end_page = 93 # Extract up to the third page (0-based index)
|
| 87 |
+
vcs_text = extract_text_from_pdf(pdf_path, start_page, end_page)
|
| 88 |
+
print(vcs_text)
|
| 89 |
+
|
| 90 |
+
pdf_path = 'VCS-Methodology-Requirements.pdf'
|
| 91 |
+
start_page = 0 # Start extracting from the first page (0-based index)
|
| 92 |
+
end_page = 89 # Extract up to the third page (0-based index)
|
| 93 |
+
methodology_text = extract_text_from_pdf(pdf_path, start_page, end_page)
|
| 94 |
+
print(methodology_text)
|
| 95 |
+
|
| 96 |
+
pdf_path = 'VCS-Project-Description-Template-v4.4-FINAL2.docx.pdf'
|
| 97 |
+
start_page = 0 # Start extracting from the first page (0-based index)
|
| 98 |
+
end_page = 34 # Extract up to the third page (0-based index)
|
| 99 |
+
template_text = extract_text_from_pdf(pdf_path, start_page, end_page)
|
| 100 |
+
#print(template_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
+
# Configure AI (this could be dynamic depending on how your setup works)
|
| 103 |
+
GOOGLE_API_KEY = "AIzaSyC7TpzrIH_3-dppWE8exqdZX3DAdE6cy8w"
|
| 104 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
| 105 |
+
|
| 106 |
+
# Example of working with LLM models (Gemini 1.5)
|
| 107 |
+
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 108 |
+
|
| 109 |
+
# Generate the AI response based on the text of the selected file
|
| 110 |
+
response = model.generate_content("You are a project verifier officer at Verra, the leading registry for projects used to generate carbon credits. Your job is to look into project submissions from project developers who create an implement nature-based solutions in order to generate carbon credits. You go through the content of the project submissions to investigate whether the submission fits into the vcs standards, methodology requirements, and touches everything on the project description template. A verifier has to compare the submission to these 3 main criteria. As a verifier, I want you to evaluate the project submission below based on the resources listed below. The output should be in the format of summary of the project submission, the level of adherence to the standards, what needs to be fixed, and notes for improvement for project developers. The output needs to have project-specific feedback. You can bolster your feedback with quotes from the submission or referencing numbers mentioned in the submission. Here is the project submission:" + st.session_state.selected_text + "Here is the vcs standards:" + vcs_text + "Here is the methodology requirement:" + methodology_text + "Here is the project description template:" + template_text)
|
| 111 |
+
|
| 112 |
+
# Save the response and filename in session state
|
| 113 |
+
st.session_state.selected_ai = response.text
|
| 114 |
|
| 115 |
# Display the selected file and AI response
|
| 116 |
st.title(f"Selected File: {st.session_state.selected_file}")
|