File size: 15,111 Bytes
e1a32e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe90003
 
 
 
 
 
 
 
 
 
 
 
 
 
f5cd6eb
 
fe90003
f5cd6eb
 
e1a32e3
 
 
f5cd6eb
e1a32e3
 
 
 
 
 
f5cd6eb
e1a32e3
 
 
fe90003
e1a32e3
 
 
fe90003
e1a32e3
 
 
f5cd6eb
 
 
 
 
 
e1a32e3
 
 
 
 
 
 
 
f5cd6eb
e1a32e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c430bc8
 
 
ae28734
c430bc8
e1a32e3
 
9278a60
 
 
fe90003
e1a32e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5cd6eb
9278a60
 
fe90003
9278a60
e1a32e3
f5cd6eb
e1a32e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5cd6eb
9278a60
 
 
fe90003
e1a32e3
f5cd6eb
e1a32e3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import streamlit as st
import os
import google.generativeai as genai
from huggingface_hub import hf_hub_download

MODEL_ID = "gemini-2.0-flash-exp"  # Keep the model ID as is
try:
    api_key = os.getenv("GEMINI_API_KEY")
    model_id = MODEL_ID
    genai.configure(api_key=api_key)
except Exception as e:
    st.error(f"Error: {e}")
    st.stop

model = genai.GenerativeModel(MODEL_ID)
chat = model.start_chat()

def download_pdf():
    """
    Downloads the PDF file from the Hugging Face Hub using the correct repo path and filename.
    """
    try:
        hf_token = os.getenv("HF_TOKEN")
        repo_id = "louiecerv/vqa_procurement_dataset"  # Corrected dataset repo path
        filename = "20250210-IRR-RA-12009-FRM.pdf"
        filepath = hf_hub_download(repo_id=repo_id, filename=filename, token=hf_token, repo_type="dataset")
        return filepath
    except Exception as e:
        st.error(f"Failed to download PDF from Hugging Face Hub: {e}")
        st.stop()  # Stop if the download fails

# Initialize session state for the uploaded PDF and its path
if "uploaded_pdf_path" not in st.session_state:
    st.session_state.uploaded_pdf_path = download_pdf() 
if "conversation_history" not in st.session_state:
    st.session_state.conversation_history = []  # Store the conversation history

def multimodal_prompt(pdf_path, text_prompt):
    """
    Sends a multimodal prompt (PDF + text) to Gemini for the *first* message.

    Args:
        pdf_path: The path to the PDF file.
        text_prompt: The text prompt for the model.

    Returns:
        The model's response as a string, or an error message.
    """

    try:
        pdf_part = genai.upload_file(pdf_path, mime_type="application/pdf")

        prompt = [
            text_prompt,
            pdf_part
        ]

        response = chat.send_message(prompt)
        st.session_state.conversation_history.append({"role": "user", "content": text_prompt, "has_pdf": True}) # Add to history
        st.session_state.conversation_history.append({"role": "assistant", "content": response.text}) # Add to history
        return response.text
    except Exception as e:
        return f"An error occurred: {e}"

# Define roles and procurement types from the document
roles = ["End-user", "Procurement Staff", "Top Management", "Implementing Unit",
         "BAC Chairperson", "BAC Member", "BAC Secretariat", "TWG Member", "Project Consultant"]
procurement_types = ["Competitive Bidding", "Limited Source Bidding", "Competitive Dialogue",
                     "Unsolicited Offer with Bid Matching", "Direct Contracting", "Direct Acquisition",
                     "Repeat Order", "Small Value Procurement", "Negotiated Procurement",
                     "Direct Sales", "Direct Procurement for Science, Technology and Innovation"]


# --- Sidebar ---
st.sidebar.title("Visual Understanding App")
selected_role = st.sidebar.selectbox("Select Your Role", roles)
selected_procurement_type = st.sidebar.selectbox("Select Procurement Type", procurement_types)

# --- Main Page ---
st.title("Procurement Guide: 20250210-IRR-RA-12009-FRM.pdf")


# --- Tabs ---
tab1, tab2, tab3 = st.tabs(["Q and A", "Glossary", "Checklists"])

# --- Q and A Tab ---
with tab1:
    st.header("Questions and Answers")

    # Generate 5 questions based on the selected role
    if selected_role == "End-user":
        questions = [
            "What are the key steps involved in the procurement process for an end-user?",
            "How can I ensure that my procurement request aligns with the PPMP and APP?",
            "What are the different modes of procurement available to me as an end-user?",
            "What are my responsibilities in the post-qualification stage?",
            "What are the common reasons for bid disqualification that I should be aware of?"
        ]
    elif selected_role == "Procurement Staff":
        questions = [
            "What are the legal requirements for procurement staff in handling bid documents?",
            "How can I ensure the security and integrity of the PhilGEPS system during procurement activities?",
            "What are the criteria for evaluating the quality component of bids in the MEARB process?",
            "What are the grounds for contract termination that I should monitor?",
            "How can I contribute to the development of a Green Local Market?"
        ]
    elif selected_role == "Top Management":
        questions = [
            "What are the key policy decisions that Top Management needs to make regarding public procurement?",
            "How can we ensure alignment between our procurement strategy and the organization's overall goals?",
            "What are the critical monitoring and evaluation metrics for assessing the effectiveness of our procurement program?",
            "How can we leverage data analytics to enhance procurement planning and decision-making?",
            "What are the key risks and challenges associated with public procurement, and how can we mitigate them?"
        ]
    elif selected_role == "Implementing Unit":
        questions = [
            "What is the role of the Implementing Unit in the procurement process?",
            "How can we ensure effective coordination between the Implementing Unit and the BAC?",
            "What are the key steps involved in contract implementation and management?",
            "What are the common challenges faced by Implementing Units in procurement projects?",
            "How can we improve the efficiency and effectiveness of contract implementation?"
        ]
    elif selected_role == "BAC Chairperson":
        questions = [
            "What are the primary responsibilities of the BAC Chairperson in the procurement process?",
            "How can I ensure that the BAC operates in a transparent and accountable manner?",
            "What are the key ethical considerations for BAC members?",
            "How can I effectively manage and resolve bid protests?",
            "What are the best practices for conducting bid evaluations and post-qualification?"
        ]
    elif selected_role == "BAC Member":
        questions = [
            "What are the specific roles and responsibilities of a BAC Member?",
            "How can I contribute to fair and competitive bid evaluations?",
            "What are the critical factors to consider during post-qualification?",
            "How can I ensure that procurement decisions are aligned with the law and the organization's policies?",
            "What are the ethical guidelines that I should follow as a BAC Member?"
        ]
    elif selected_role == "BAC Secretariat":
        questions = [
            "What are the key functions and responsibilities of the BAC Secretariat?",
            "How can I effectively manage procurement documents and records?",
            "What are the best practices for organizing and conducting pre-bid conferences?",
            "How can I ensure timely and accurate communication with bidders?",
            "What is the role of the BAC Secretariat in contract implementation and monitoring?"
        ]
    elif selected_role == "TWG Member":
        questions = [
            "What is the purpose and function of a Technical Working Group (TWG) in procurement?",
            "How can I contribute my technical expertise to the bid evaluation process?",
            "What are the key factors to consider when reviewing technical specifications?",
            "How can I ensure that procurement decisions are technically sound and aligned with project requirements?",
            "What are the challenges and opportunities for TWG members in public procurement?"
        ]
    elif selected_role == "Project Consultant":
        questions = [
            "What is the role of a Project Consultant in the procurement process?",
            "How can I ensure that my consultancy services contribute to successful procurement outcomes?",
            "What are the ethical considerations for Project Consultants in procurement projects?",
            "How can I effectively collaborate with the Procuring Entity and the BAC?",
            "What are the key challenges and opportunities for Project Consultants in public procurement?"
        ]

    # Create a selection box
    selected_question = st.selectbox("Choose a question", questions)

    # Display a checkbox
    if st.checkbox('Enter a question'):
        # If the checkbox is checked, display a text box
        selected_question = st.text_input('Enter a question')

    if st.button("Ask AI"):
        with st.spinner("AI is thinking..."):
            if st.session_state.uploaded_pdf_path is None:
                st.session_state.uploaded_pdf_path = download_pdf()

            filepath = st.session_state.uploaded_pdf_path
            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."
            response = multimodal_prompt(filepath, text_prompt)  # Use the downloaded filepath
            st.markdown(f"**Response:** {response}")

# --- Glossary Tab ---
with tab2:
    st.header("Glossary")

    # Define 10 common terms and their definitions
    glossary = {
        "ABC": "Approved Budget for the Contract",
        "BAC": "Bids and Awards Committee",
        "PhilGEPS": "Philippine Government Electronic Procurement System",
        "CSE": "Common-Use Supplies and Equipment",
        "GPP": "Green Public Procurement",
        "HOPE": "Head of the Procuring Entity",
        "IRR": "Implementing Rules and Regulations",
        "LCB": "Lowest Calculated Bid",
        "MEARB": "Most Economically Advantageous Responsive Bid",
        "NGO": "Non-Government Organization"
    }

    for term, definition in glossary.items():
        st.write(f"**{term}:** {definition}")

    user_term = st.text_input("Enter a term to search:")
    if user_term:
        with st.spinner("AI is thinking..."):
            if st.session_state.uploaded_pdf_path is None:
                st.session_state.uploaded_pdf_path = download_pdf()
            filepath = st.session_state.uploaded_pdf_path

            text_prompt = f"Use the provided document to define in the context of {selected_role} and {selected_procurement_type} term: {user_term}"
            response = multimodal_prompt(filepath, text_prompt)  # Use the downloaded filepath
            st.markdown(f"**Response:** {response}")

# --- Checklists Tab ---
with tab3:
    st.header("Checklists")

    # Generate a sample checklist based on selected role and procurement type
    if selected_role == "End-user" and selected_procurement_type == "Competitive Bidding":
        checklist = [
            "Prepare and submit procurement request",
            "Ensure alignment with PPMP and APP",
            "Define technical specifications",
            "Participate in pre-bid conference",
            "Review bid documents",
            "Submit bid",
            "Attend bid opening",
            "Participate in post-qualification",
            "Sign contract"
        ]
    elif selected_role == "Procurement Staff" and selected_procurement_type == "Competitive Bidding":
        checklist = [
            "Prepare bidding documents",
            "Publish invitation to bid",
            "Conduct pre-bid conference",
            "Receive and open bids",
            "Evaluate bids",
            "Conduct post-qualification",
            "Recommend award of contract",
            "Issue notice of award",
            "Facilitate contract signing"
        ]
    elif selected_role == "Top Management" and selected_procurement_type == "Competitive Bidding":
        checklist = [
            "Approve procurement plan",
            "Set procurement policies",
            "Ensure budget availability",
            "Monitor procurement process",
            "Approve contract award",
            "Oversee contract implementation",
            "Address bid protests",
            "Ensure compliance with laws and regulations"
        ]
    elif selected_role == "Implementing Unit" and selected_procurement_type == "Competitive Bidding":
        checklist = [
            "Identify project needs",
            "Prepare technical specifications",
            "Develop PPMP",
            "Participate in bid evaluation",
            "Oversee project implementation",
            "Monitor contractor performance",
            "Accept project deliverables"
        ]
    elif selected_role == "BAC Chairperson" and selected_procurement_type == "Competitive Bidding":
        checklist = [
            "Lead BAC meetings",
            "Ensure compliance with procurement law",
            "Oversee bid evaluation process",
            "Resolve bid protests",
            "Recommend contract award",
            "Sign bid documents and notices"
        ]
    elif selected_role == "BAC Member" and selected_procurement_type == "Competitive Bidding":
        checklist = [
            "Attend BAC meetings",
            "Review bid documents",
            "Evaluate bids",
            "Participate in post-qualification",
            "Submit recommendations to BAC Chairperson"
        ]
    elif selected_role == "BAC Secretariat" and selected_procurement_type == "Competitive Bidding":
        checklist = [
            "Provide administrative support to BAC",
            "Prepare meeting minutes and resolutions",
            "Handle bid documents and records",
            "Publish bidding opportunities",
            "Assist in bid evaluation and post-qualification"
        ]
    elif selected_role == "TWG Member" and selected_procurement_type == "Competitive Bidding":
        checklist = [
            "Review technical specifications",
            "Evaluate bids based on technical criteria",
            "Provide technical expertise to BAC",
            "Prepare technical reports"
        ]
    elif selected_role == "Project Consultant" and selected_procurement_type == "Competitive Bidding":
        checklist = [
            "Provide technical advice to Procuring Entity",
            "Assist in preparing bidding documents",
            "Participate in bid evaluation if requested",
            "Monitor project implementation"
        ]
    else:
        checklist = []

    for i, task in enumerate(checklist):
        st.write(f"{i+1}. {task}")

    user_task = st.text_input("Enter a task to get checklist:")
    if user_task:
        with st.spinner("AI is thinking..."):
            if st.session_state.uploaded_pdf_path is None:
                st.session_state.uploaded_pdf_path = download_pdf()
                        
            filepath = st.session_state.uploaded_pdf_path
            text_prompt = f"Use the provided document to create a checklist in the context of {selected_role} and {selected_procurement_type} task: {user_task}"
            response = multimodal_prompt(filepath, text_prompt)  # Use the downloaded filepath
            st.markdown(f"**Response:** {response}")