Update verifier.py
Browse files- verifier.py +22 -19
verifier.py
CHANGED
|
@@ -26,12 +26,19 @@ def verifier_page():
|
|
| 26 |
|
| 27 |
fields_to_fetch = ['filename', 'pdf_url', 'text']
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
# Check if a file has already been selected and displayed
|
| 30 |
-
if
|
| 31 |
# When a file is selected, clear everything and display the details only
|
| 32 |
st.empty() # Clear all content before displaying details
|
| 33 |
st.title(f"Selected File: {st.session_state.selected_file}")
|
| 34 |
-
#st.write(f"Text: {st.session_state.selected_text}")
|
| 35 |
st.write(f"AI Response: {st.session_state.selected_ai}")
|
| 36 |
else:
|
| 37 |
# Automatically load and display the data table on page load
|
|
@@ -60,7 +67,7 @@ def verifier_page():
|
|
| 60 |
st.session_state.selected_file = row['filename']
|
| 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
|
|
@@ -81,38 +88,34 @@ def verifier_page():
|
|
| 81 |
return text
|
| 82 |
|
| 83 |
|
|
|
|
| 84 |
pdf_path = 'VCS-Standard.pdf'
|
| 85 |
-
start_page = 0
|
| 86 |
-
end_page = 93
|
| 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
|
| 92 |
-
end_page = 89
|
| 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
|
| 98 |
-
end_page = 34
|
| 99 |
template_text = extract_text_from_pdf(pdf_path, start_page, end_page)
|
| 100 |
-
#print(template_text)
|
| 101 |
|
| 102 |
-
|
| 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 |
-
|
| 110 |
-
response = model.generate_content(
|
|
|
|
| 111 |
|
| 112 |
-
|
| 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}")
|
| 117 |
-
#st.write(f"Text: {st.session_state.selected_text}")
|
| 118 |
st.write(f"AI Response: {st.session_state.selected_ai}")
|
|
|
|
| 26 |
|
| 27 |
fields_to_fetch = ['filename', 'pdf_url', 'text']
|
| 28 |
|
| 29 |
+
# Initialize session_state attributes if not present
|
| 30 |
+
if 'selected_file' not in st.session_state:
|
| 31 |
+
st.session_state.selected_file = None
|
| 32 |
+
if 'selected_text' not in st.session_state:
|
| 33 |
+
st.session_state.selected_text = ""
|
| 34 |
+
if 'selected_ai' not in st.session_state:
|
| 35 |
+
st.session_state.selected_ai = ""
|
| 36 |
+
|
| 37 |
# Check if a file has already been selected and displayed
|
| 38 |
+
if st.session_state.selected_file:
|
| 39 |
# When a file is selected, clear everything and display the details only
|
| 40 |
st.empty() # Clear all content before displaying details
|
| 41 |
st.title(f"Selected File: {st.session_state.selected_file}")
|
|
|
|
| 42 |
st.write(f"AI Response: {st.session_state.selected_ai}")
|
| 43 |
else:
|
| 44 |
# Automatically load and display the data table on page load
|
|
|
|
| 67 |
st.session_state.selected_file = row['filename']
|
| 68 |
st.session_state.selected_text = row['text']
|
| 69 |
|
| 70 |
+
# Function to extract text from PDF
|
| 71 |
def extract_text_from_pdf(uploaded_file, start_page, end_page):
|
| 72 |
if uploaded_file is None:
|
| 73 |
return "" # Return an empty string if no file is uploaded
|
|
|
|
| 88 |
return text
|
| 89 |
|
| 90 |
|
| 91 |
+
# Extract the relevant content from the PDFs
|
| 92 |
pdf_path = 'VCS-Standard.pdf'
|
| 93 |
+
start_page = 0
|
| 94 |
+
end_page = 93
|
| 95 |
vcs_text = extract_text_from_pdf(pdf_path, start_page, end_page)
|
|
|
|
| 96 |
|
| 97 |
pdf_path = 'VCS-Methodology-Requirements.pdf'
|
| 98 |
+
start_page = 0
|
| 99 |
+
end_page = 89
|
| 100 |
methodology_text = extract_text_from_pdf(pdf_path, start_page, end_page)
|
|
|
|
| 101 |
|
| 102 |
pdf_path = 'VCS-Project-Description-Template-v4.4-FINAL2.docx.pdf'
|
| 103 |
+
start_page = 0
|
| 104 |
+
end_page = 34
|
| 105 |
template_text = extract_text_from_pdf(pdf_path, start_page, end_page)
|
|
|
|
| 106 |
|
| 107 |
+
# Configure the AI model
|
| 108 |
GOOGLE_API_KEY = "AIzaSyC7TpzrIH_3-dppWE8exqdZX3DAdE6cy8w"
|
| 109 |
genai.configure(api_key=GOOGLE_API_KEY)
|
|
|
|
|
|
|
| 110 |
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 111 |
|
| 112 |
+
# Generate the AI response based on the selected file's text
|
| 113 |
+
response = model.generate_content(
|
| 114 |
+
"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 and 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)
|
| 115 |
|
| 116 |
+
# Save the AI response in session state
|
| 117 |
st.session_state.selected_ai = response.text
|
| 118 |
|
| 119 |
# Display the selected file and AI response
|
| 120 |
st.title(f"Selected File: {st.session_state.selected_file}")
|
|
|
|
| 121 |
st.write(f"AI Response: {st.session_state.selected_ai}")
|