Katie-Ch commited on
Commit
2b29718
·
verified ·
1 Parent(s): 94dc26a

Update verifier.py

Browse files
Files changed (1) hide show
  1. verifier.py +6 -26
verifier.py CHANGED
@@ -31,15 +31,15 @@ def verifier_page():
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
45
  data = fetch_data(fields_to_fetch)
@@ -65,7 +65,7 @@ def verifier_page():
65
  #st.session_state.selected_text = row['text']
66
 
67
  # Clear existing content on button click
68
- st.rerun()
69
 
70
  if st.session_state.selected_file:
71
  # Process the selected file and generate AI response
@@ -84,15 +84,6 @@ def verifier_page():
84
  end_page = 34 # Extract up to the third page (0-based index)
85
  template_text = extract_text_from_pdf(pdf_path, start_page, end_page)
86
 
87
- # Check if the extracted text is not empty
88
- if not st.session_state.selected_text:
89
- st.error("No text extracted from the selected file.")
90
- return
91
-
92
- # Debug print to check if the selected text is correct
93
- st.write("Extracted Text from Selected File:")
94
- st.write(st.session_state.selected_text)
95
-
96
  # Configure AI (this could be dynamic depending on how your setup works)
97
  GOOGLE_API_KEY = "AIzaSyC7TpzrIH_3-dppWE8exqdZX3DAdE6cy8w"
98
  genai.configure(api_key=GOOGLE_API_KEY)
@@ -100,20 +91,9 @@ def verifier_page():
100
  # Example of working with LLM models (Gemini 1.5)
101
  model = genai.GenerativeModel('gemini-1.5-flash-latest')
102
 
103
- # Debug log for checking the text before passing it to the AI model
104
- request_text = "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_file + "Here is the vcs standards:" + vcs_text + "Here is the methodology requirement:" + methodology_text + "Here is the project description template:" + template_text
105
-
106
- st.write("Request Text for AI Model:")
107
- st.write(request_text)
108
-
109
  # Generate the AI response based on the text of the selected file
110
- response = model.generate_content(request_text)
111
 
112
- # Check if response is empty
113
- if not response.text:
114
- st.error("AI response is empty.")
115
- return
116
-
117
  # Save the response and filename in session state
118
  st.session_state.selected_file = response.text
119
 
 
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.write(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
45
  data = fetch_data(fields_to_fetch)
 
65
  #st.session_state.selected_text = row['text']
66
 
67
  # Clear existing content on button click
68
+ st.experimental_rerun()
69
 
70
  if st.session_state.selected_file:
71
  # Process the selected file and generate AI response
 
84
  end_page = 34 # Extract up to the third page (0-based index)
85
  template_text = extract_text_from_pdf(pdf_path, start_page, end_page)
86
 
 
 
 
 
 
 
 
 
 
87
  # Configure AI (this could be dynamic depending on how your setup works)
88
  GOOGLE_API_KEY = "AIzaSyC7TpzrIH_3-dppWE8exqdZX3DAdE6cy8w"
89
  genai.configure(api_key=GOOGLE_API_KEY)
 
91
  # Example of working with LLM models (Gemini 1.5)
92
  model = genai.GenerativeModel('gemini-1.5-flash-latest')
93
 
 
 
 
 
 
 
94
  # Generate the AI response based on the text of the selected file
95
+ 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)
96
 
 
 
 
 
 
97
  # Save the response and filename in session state
98
  st.session_state.selected_file = response.text
99