louiecerv commited on
Commit
e1a32e3
·
1 Parent(s): 752a7b0
Files changed (2) hide show
  1. app.py +306 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,306 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import google.generativeai as genai
4
+ from huggingface_hub import hf_hub_download
5
+
6
+ MODEL_ID = "gemini-2.0-flash-exp" # Keep the model ID as is
7
+ try:
8
+ api_key = os.getenv("GEMINI_API_KEY")
9
+ model_id = MODEL_ID
10
+ genai.configure(api_key=api_key)
11
+ except Exception as e:
12
+ st.error(f"Error: {e}")
13
+ st.stop
14
+
15
+ model = genai.GenerativeModel(MODEL_ID)
16
+ chat = model.start_chat()
17
+
18
+
19
+ def multimodal_prompt(pdf_path, text_prompt):
20
+ """
21
+ Sends a multimodal prompt to the Gemini model with a PDF and a text prompt.
22
+
23
+ Args:
24
+ pdf_path: The path to the PDF file.
25
+ text_prompt: The text prompt for the model.
26
+
27
+ Returns:
28
+ The model's response as a string.
29
+ """
30
+
31
+ try:
32
+ pdf_part = genai.upload_file(pdf_path, mime_type="application/pdf") # Corrected - use genai.upload_file
33
+
34
+ # Construct the multimodal prompt
35
+ prompt = [
36
+ text_prompt,
37
+ pdf_part
38
+ ]
39
+
40
+ # Send the request to the model
41
+ response = chat.send_message(prompt)
42
+ return response.text
43
+ except Exception as e:
44
+ return f"An error occurred: {e}"
45
+
46
+ # Define roles and procurement types from the document
47
+ roles = ["End-user", "Procurement Staff", "Top Management", "Implementing Unit",
48
+ "BAC Chairperson", "BAC Member", "BAC Secretariat", "TWG Member", "Project Consultant"]
49
+ procurement_types = ["Competitive Bidding", "Limited Source Bidding", "Competitive Dialogue",
50
+ "Unsolicited Offer with Bid Matching", "Direct Contracting", "Direct Acquisition",
51
+ "Repeat Order", "Small Value Procurement", "Negotiated Procurement",
52
+ "Direct Sales", "Direct Procurement for Science, Technology and Innovation"]
53
+
54
+ # --- Sidebar ---
55
+ st.sidebar.title("Visual Understanding App")
56
+ selected_role = st.sidebar.selectbox("Select Your Role", roles)
57
+ selected_procurement_type = st.sidebar.selectbox("Select Procurement Type", procurement_types)
58
+
59
+ # --- Main Page ---
60
+ st.title("Procurement Guide: 20250210-IRR-RA-12009-FRM.pdf")
61
+
62
+ # uploaded_pdf = "20250210-IRR-RA-12009-FRM.pdf" # Removed this line
63
+
64
+ # filepath = "" # Removed initialization
65
+ # if uploaded_pdf: # This block is no longer needed as we're downloading
66
+ # with open(uploaded_pdf, "rb") as file:
67
+ # filepath = file.name
68
+
69
+ # --- Hugging Face Download Logic (Integrated) ---
70
+ hf_token = os.getenv("HF_TOKEN")
71
+ if not hf_token:
72
+ st.error("Hugging Face token is missing. Please set HF_TOKEN as an environment variable.")
73
+ st.stop() # Stop execution if the token is missing
74
+
75
+ repo_id = "louiecerv/vqa_procurement_dataset" # Corrected dataset repo path
76
+ filename = "20250210-IRR-RA-12009-FRM.pdf"
77
+ try:
78
+ filepath = hf_hub_download(repo_id=repo_id, filename=filename, token=hf_token, repo_type="dataset")
79
+ except Exception as e:
80
+ st.error(f"Failed to download PDF from Hugging Face Hub: {e}")
81
+ st.stop() # Stop if the download fails
82
+
83
+
84
+ # --- Tabs ---
85
+ tab1, tab2, tab3 = st.tabs(["Q and A", "Glossary", "Checklists"])
86
+
87
+ # --- Q and A Tab ---
88
+ with tab1:
89
+ st.header("Questions and Answers")
90
+
91
+ # Generate 5 questions based on the selected role
92
+ if selected_role == "End-user":
93
+ questions = [
94
+ "What are the key steps involved in the procurement process for an end-user?",
95
+ "How can I ensure that my procurement request aligns with the PPMP and APP?",
96
+ "What are the different modes of procurement available to me as an end-user?",
97
+ "What are my responsibilities in the post-qualification stage?",
98
+ "What are the common reasons for bid disqualification that I should be aware of?"
99
+ ]
100
+ elif selected_role == "Procurement Staff":
101
+ questions = [
102
+ "What are the legal requirements for procurement staff in handling bid documents?",
103
+ "How can I ensure the security and integrity of the PhilGEPS system during procurement activities?",
104
+ "What are the criteria for evaluating the quality component of bids in the MEARB process?",
105
+ "What are the grounds for contract termination that I should monitor?",
106
+ "How can I contribute to the development of a Green Local Market?"
107
+ ]
108
+ elif selected_role == "Top Management":
109
+ questions = [
110
+ "What are the key policy decisions that Top Management needs to make regarding public procurement?",
111
+ "How can we ensure alignment between our procurement strategy and the organization's overall goals?",
112
+ "What are the critical monitoring and evaluation metrics for assessing the effectiveness of our procurement program?",
113
+ "How can we leverage data analytics to enhance procurement planning and decision-making?",
114
+ "What are the key risks and challenges associated with public procurement, and how can we mitigate them?"
115
+ ]
116
+ elif selected_role == "Implementing Unit":
117
+ questions = [
118
+ "What is the role of the Implementing Unit in the procurement process?",
119
+ "How can we ensure effective coordination between the Implementing Unit and the BAC?",
120
+ "What are the key steps involved in contract implementation and management?",
121
+ "What are the common challenges faced by Implementing Units in procurement projects?",
122
+ "How can we improve the efficiency and effectiveness of contract implementation?"
123
+ ]
124
+ elif selected_role == "BAC Chairperson":
125
+ questions = [
126
+ "What are the primary responsibilities of the BAC Chairperson in the procurement process?",
127
+ "How can I ensure that the BAC operates in a transparent and accountable manner?",
128
+ "What are the key ethical considerations for BAC members?",
129
+ "How can I effectively manage and resolve bid protests?",
130
+ "What are the best practices for conducting bid evaluations and post-qualification?"
131
+ ]
132
+ elif selected_role == "BAC Member":
133
+ questions = [
134
+ "What are the specific roles and responsibilities of a BAC Member?",
135
+ "How can I contribute to fair and competitive bid evaluations?",
136
+ "What are the critical factors to consider during post-qualification?",
137
+ "How can I ensure that procurement decisions are aligned with the law and the organization's policies?",
138
+ "What are the ethical guidelines that I should follow as a BAC Member?"
139
+ ]
140
+ elif selected_role == "BAC Secretariat":
141
+ questions = [
142
+ "What are the key functions and responsibilities of the BAC Secretariat?",
143
+ "How can I effectively manage procurement documents and records?",
144
+ "What are the best practices for organizing and conducting pre-bid conferences?",
145
+ "How can I ensure timely and accurate communication with bidders?",
146
+ "What is the role of the BAC Secretariat in contract implementation and monitoring?"
147
+ ]
148
+ elif selected_role == "TWG Member":
149
+ questions = [
150
+ "What is the purpose and function of a Technical Working Group (TWG) in procurement?",
151
+ "How can I contribute my technical expertise to the bid evaluation process?",
152
+ "What are the key factors to consider when reviewing technical specifications?",
153
+ "How can I ensure that procurement decisions are technically sound and aligned with project requirements?",
154
+ "What are the challenges and opportunities for TWG members in public procurement?"
155
+ ]
156
+ elif selected_role == "Project Consultant":
157
+ questions = [
158
+ "What is the role of a Project Consultant in the procurement process?",
159
+ "How can I ensure that my consultancy services contribute to successful procurement outcomes?",
160
+ "What are the ethical considerations for Project Consultants in procurement projects?",
161
+ "How can I effectively collaborate with the Procuring Entity and the BAC?",
162
+ "What are the key challenges and opportunities for Project Consultants in public procurement?"
163
+ ]
164
+
165
+ # Create a selection box
166
+ selected_question = st.selectbox("Choose a question", questions)
167
+
168
+ if st.button("Ask AI"):
169
+ with st.spinner("AI is thinking..."):
170
+ text_prompt = f"Use the provided document to answer the following question in the context of {selected_role} and {selected_procurement_type} question: {selected_question}. Cite the relevant sections of the IRR."
171
+
172
+ response = multimodal_prompt(filepath, text_prompt) # Use the downloaded filepath
173
+ st.markdown(f"**Response:** {response}")
174
+
175
+ # --- Glossary Tab ---
176
+ with tab2:
177
+ st.header("Glossary")
178
+
179
+ # Define 10 common terms and their definitions
180
+ glossary = {
181
+ "ABC": "Approved Budget for the Contract",
182
+ "BAC": "Bids and Awards Committee",
183
+ "PhilGEPS": "Philippine Government Electronic Procurement System",
184
+ "CSE": "Common-Use Supplies and Equipment",
185
+ "GPP": "Green Public Procurement",
186
+ "HOPE": "Head of the Procuring Entity",
187
+ "IRR": "Implementing Rules and Regulations",
188
+ "LCB": "Lowest Calculated Bid",
189
+ "MEARB": "Most Economically Advantageous Responsive Bid",
190
+ "NGO": "Non-Government Organization"
191
+ }
192
+
193
+ for term, definition in glossary.items():
194
+ st.write(f"**{term}:** {definition}")
195
+
196
+ user_term = st.text_input("Enter a term to search:")
197
+ if user_term:
198
+ with st.spinner("Searching for term..."):
199
+ text_prompt = f"Use the provided document to define in the context of {selected_role} and {selected_procurement_type} term: {user_term}"
200
+
201
+ response = multimodal_prompt(filepath, text_prompt) # Use downloaded filepath
202
+ st.markdown(f"**Response:** {response}")
203
+
204
+
205
+ # --- Checklists Tab ---
206
+ with tab3:
207
+ st.header("Checklists")
208
+
209
+ # Generate a sample checklist based on selected role and procurement type
210
+ if selected_role == "End-user" and selected_procurement_type == "Competitive Bidding":
211
+ checklist = [
212
+ "Prepare and submit procurement request",
213
+ "Ensure alignment with PPMP and APP",
214
+ "Define technical specifications",
215
+ "Participate in pre-bid conference",
216
+ "Review bid documents",
217
+ "Submit bid",
218
+ "Attend bid opening",
219
+ "Participate in post-qualification",
220
+ "Sign contract"
221
+ ]
222
+ elif selected_role == "Procurement Staff" and selected_procurement_type == "Competitive Bidding":
223
+ checklist = [
224
+ "Prepare bidding documents",
225
+ "Publish invitation to bid",
226
+ "Conduct pre-bid conference",
227
+ "Receive and open bids",
228
+ "Evaluate bids",
229
+ "Conduct post-qualification",
230
+ "Recommend award of contract",
231
+ "Issue notice of award",
232
+ "Facilitate contract signing"
233
+ ]
234
+ elif selected_role == "Top Management" and selected_procurement_type == "Competitive Bidding":
235
+ checklist = [
236
+ "Approve procurement plan",
237
+ "Set procurement policies",
238
+ "Ensure budget availability",
239
+ "Monitor procurement process",
240
+ "Approve contract award",
241
+ "Oversee contract implementation",
242
+ "Address bid protests",
243
+ "Ensure compliance with laws and regulations"
244
+ ]
245
+ elif selected_role == "Implementing Unit" and selected_procurement_type == "Competitive Bidding":
246
+ checklist = [
247
+ "Identify project needs",
248
+ "Prepare technical specifications",
249
+ "Develop PPMP",
250
+ "Participate in bid evaluation",
251
+ "Oversee project implementation",
252
+ "Monitor contractor performance",
253
+ "Accept project deliverables"
254
+ ]
255
+ elif selected_role == "BAC Chairperson" and selected_procurement_type == "Competitive Bidding":
256
+ checklist = [
257
+ "Lead BAC meetings",
258
+ "Ensure compliance with procurement law",
259
+ "Oversee bid evaluation process",
260
+ "Resolve bid protests",
261
+ "Recommend contract award",
262
+ "Sign bid documents and notices"
263
+ ]
264
+ elif selected_role == "BAC Member" and selected_procurement_type == "Competitive Bidding":
265
+ checklist = [
266
+ "Attend BAC meetings",
267
+ "Review bid documents",
268
+ "Evaluate bids",
269
+ "Participate in post-qualification",
270
+ "Submit recommendations to BAC Chairperson"
271
+ ]
272
+ elif selected_role == "BAC Secretariat" and selected_procurement_type == "Competitive Bidding":
273
+ checklist = [
274
+ "Provide administrative support to BAC",
275
+ "Prepare meeting minutes and resolutions",
276
+ "Handle bid documents and records",
277
+ "Publish bidding opportunities",
278
+ "Assist in bid evaluation and post-qualification"
279
+ ]
280
+ elif selected_role == "TWG Member" and selected_procurement_type == "Competitive Bidding":
281
+ checklist = [
282
+ "Review technical specifications",
283
+ "Evaluate bids based on technical criteria",
284
+ "Provide technical expertise to BAC",
285
+ "Prepare technical reports"
286
+ ]
287
+ elif selected_role == "Project Consultant" and selected_procurement_type == "Competitive Bidding":
288
+ checklist = [
289
+ "Provide technical advice to Procuring Entity",
290
+ "Assist in preparing bidding documents",
291
+ "Participate in bid evaluation if requested",
292
+ "Monitor project implementation"
293
+ ]
294
+ else:
295
+ checklist = []
296
+
297
+ for i, task in enumerate(checklist):
298
+ st.write(f"{i+1}. {task}")
299
+
300
+ user_task = st.text_input("Enter a task to get checklist:")
301
+ if user_task:
302
+ with st.spinner("Searching for term..."):
303
+ text_prompt = f"Use the provided document to create a checklist in the context of {selected_role} and {selected_procurement_type} task: {user_task}"
304
+
305
+ response = multimodal_prompt(filepath, text_prompt) # Use downloaded filepath
306
+ st.markdown(f"**Response:** {response}")
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ requests
3
+ pdfplumber
4
+ huggingface_hub
5
+ google-generativeai