Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import PyPDF2
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
st.title('NBS Project Submission Evaluation')
|
| 6 |
+
|
| 7 |
+
def extract_text_from_pdf(uploaded_file, start_page, end_page):
|
| 8 |
+
if uploaded_file is None:
|
| 9 |
+
return "" # Return an empty string if no file is uploaded
|
| 10 |
+
|
| 11 |
+
reader = PyPDF2.PdfReader(uploaded_file)
|
| 12 |
+
num_pages = len(reader.pages)
|
| 13 |
+
|
| 14 |
+
if start_page < 0 or start_page >= num_pages:
|
| 15 |
+
start_page = 0
|
| 16 |
+
if end_page < start_page or end_page >= num_pages:
|
| 17 |
+
end_page = num_pages - 1
|
| 18 |
+
|
| 19 |
+
text = ''
|
| 20 |
+
for page_num in range(start_page, end_page + 1):
|
| 21 |
+
page = reader.pages[page_num]
|
| 22 |
+
text += page.extract_text()
|
| 23 |
+
|
| 24 |
+
return text
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# Rest of your code remains the same
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
st.text("Upload a project submission")
|
| 31 |
+
pdf_path = st.file_uploader("Choose a file")
|
| 32 |
+
start_page = 0
|
| 33 |
+
end_page = 117
|
| 34 |
+
submission_text = extract_text_from_pdf(pdf_path, start_page, end_page)
|
| 35 |
+
#print(submission_text)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
pdf_path = 'VCS-Standard.pdf'
|
| 42 |
+
start_page = 0 # Start extracting from the first page (0-based index)
|
| 43 |
+
end_page = 93 # Extract up to the third page (0-based index)
|
| 44 |
+
vcs_text = extract_text_from_pdf(pdf_path, start_page, end_page)
|
| 45 |
+
print(vcs_text)
|
| 46 |
+
|
| 47 |
+
pdf_path = 'VCS-Methodology-Requirements.pdf'
|
| 48 |
+
start_page = 0 # Start extracting from the first page (0-based index)
|
| 49 |
+
end_page = 89 # Extract up to the third page (0-based index)
|
| 50 |
+
methodology_text = extract_text_from_pdf(pdf_path, start_page, end_page)
|
| 51 |
+
print(methodology_text)
|
| 52 |
+
|
| 53 |
+
pdf_path = 'VCS-Project-Description-Template-v4.4-FINAL2.docx.pdf'
|
| 54 |
+
start_page = 0 # Start extracting from the first page (0-based index)
|
| 55 |
+
end_page = 34 # Extract up to the third page (0-based index)
|
| 56 |
+
template_text = extract_text_from_pdf(pdf_path, start_page, end_page)
|
| 57 |
+
print(template_text)
|
| 58 |
+
|
| 59 |
+
# deploy a llm and use 'text' as the input.
|
| 60 |
+
|
| 61 |
+
# Commented out IPython magic to ensure Python compatibility.
|
| 62 |
+
# %pip install google-generativeai
|
| 63 |
+
|
| 64 |
+
import pathlib
|
| 65 |
+
import textwrap
|
| 66 |
+
|
| 67 |
+
import google.generativeai as genai
|
| 68 |
+
|
| 69 |
+
from IPython.display import display
|
| 70 |
+
from IPython.display import Markdown
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def to_markdown(text):
|
| 74 |
+
text = text.replace('•', ' *')
|
| 75 |
+
return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
GOOGLE_API_KEY="AIzaSyCDFpWY_8xI9ESgBLVzEtz1EV1kzaPB62I"
|
| 80 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
| 81 |
+
|
| 82 |
+
for m in genai.list_models():
|
| 83 |
+
if 'generateContent' in m.supported_generation_methods:
|
| 84 |
+
print(m.name)
|
| 85 |
+
|
| 86 |
+
#For text-only prompts, use a Gemini 1.5 model or the Gemini 1.0 Pro model:
|
| 87 |
+
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
| 88 |
+
|
| 89 |
+
# Commented out IPython magic to ensure Python compatibility.
|
| 90 |
+
if st.button("Evaluate", 2):
|
| 91 |
+
# %%time
|
| 92 |
+
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:" + submission_text + "Here is the vcs standards:" + vcs_text + "Here is the methodology requirement:" + methodology_text + "Here is the project description template:" + template_text)
|
| 93 |
+
to_markdown(response.text)
|
| 94 |
+
st.write(response.text)
|