louiecerv commited on
Commit
3f93684
·
1 Parent(s): dac886b

sync with remote

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