|
import streamlit as st |
|
import os |
|
import google.generativeai as genai |
|
from huggingface_hub import hf_hub_download |
|
from PIL import Image |
|
import base64 |
|
|
|
MODEL_ID = "gemini-2.0-flash-exp" |
|
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" |
|
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() |
|
|
|
|
|
if "conversation_history" not in st.session_state: |
|
st.session_state.conversation_history = [] |
|
if "uploaded_file_part" not in st.session_state: |
|
st.session_state.uploaded_file_part = None |
|
if "uploaded_pdf_path" not in st.session_state: |
|
st.session_state.uploaded_pdf_path = download_pdf() |
|
|
|
def multimodal_prompt(pdf_path, text_prompt): |
|
""" |
|
Sends a multimodal prompt to Gemini, handling file uploads efficiently. |
|
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: |
|
if st.session_state.uploaded_file_part is None: |
|
pdf_part = genai.upload_file(pdf_path, mime_type="application/pdf") |
|
st.session_state.uploaded_file_part = pdf_part |
|
prompt = [text_prompt, pdf_part] |
|
else: |
|
|
|
prompt = [text_prompt, st.session_state.uploaded_file_part] |
|
|
|
response = chat.send_message(prompt) |
|
|
|
|
|
st.session_state.conversation_history.append({"role": "user", "content": text_prompt, "has_pdf": True}) |
|
st.session_state.conversation_history.append({"role": "assistant", "content": response.text}) |
|
return response.text |
|
|
|
except Exception as e: |
|
return f"An error occurred: {e}" |
|
|
|
|
|
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"] |
|
|
|
def display_download_button(file_path, file_name): |
|
try: |
|
with open(file_path, "rb") as f: |
|
file_bytes = f.read() |
|
b64 = base64.b64encode(file_bytes).decode() |
|
href = f'<a href="data:application/pdf;base64,{b64}" download="{file_name}">Download the source document (PDF)</a>' |
|
st.markdown(href, unsafe_allow_html=True) |
|
except FileNotFoundError: |
|
st.error("File not found for download.") |
|
except Exception as e: |
|
st.error(f"Error during download: {e}") |
|
|
|
|
|
st.sidebar.title("🤖 Visual Q and A") |
|
selected_role = st.sidebar.selectbox("Select Your Role", roles) |
|
selected_procurement_type = st.sidebar.selectbox("Select Procurement Type", procurement_types) |
|
|
|
st.sidebar.markdown("[Visit our Hugging Face Space!](https://huggingface.co/wvsuaidev)") |
|
st.sidebar.markdown("© 2025 WVSU AI Dev Team 🤖 ✨") |
|
|
|
|
|
st.title("📚❓Procurement Guide: 20250210-IRR-RA-12009-FRM.pdf") |
|
about = """ |
|
**How to use this App** |
|
|
|
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). |
|
|
|
Key features: |
|
|
|
* **Role-based Information:** Information is customized based on your selected role, providing relevant details and perspectives. |
|
* **Procurement Type Filtering:** Filter information by procurement type to focus on specific processes. |
|
* **AI-Powered Q&A:** Ask questions about the document and receive AI-generated answers, including citations of relevant IRR sections. |
|
* **Glossary:** Quickly access definitions of common procurement terms. You can also ask the AI for a definition. |
|
* **Checklists:** Generate checklists tailored to your role and procurement type for specific tasks. |
|
""" |
|
with st.expander("How to use this App"): |
|
st.markdown(about) |
|
|
|
|
|
image = Image.open("procurement.png") |
|
st.image(image, width=400) |
|
|
|
|
|
tab1, tab2, tab3 = st.tabs(["Q and A", "Glossary", "Checklists"]) |
|
|
|
|
|
with tab1: |
|
st.header("Questions and Answers") |
|
|
|
|
|
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?" |
|
] |
|
|
|
|
|
selected_question = st.selectbox("Choose a question", questions) |
|
|
|
|
|
if st.checkbox('Enter a question'): |
|
|
|
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) |
|
st.markdown(f"**Response:** {response}") |
|
|
|
|
|
with tab2: |
|
st.header("Glossary") |
|
|
|
|
|
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) |
|
st.markdown(f"**Response:** {response}") |
|
|
|
|
|
with tab3: |
|
st.header("Checklists") |
|
|
|
|
|
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) |
|
st.markdown(f"**Response:** {response}") |
|
|
|
if st.session_state.uploaded_pdf_path: |
|
display_download_button(st.session_state.uploaded_pdf_path, "Generative_AI_and_Education.pdf") |