JEPHONETORRE commited on
Commit
46ac0ee
·
1 Parent(s): 027949b

ig last commit for this app

Browse files
Files changed (1) hide show
  1. app.py +55 -41
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  from PyPDF2 import PdfReader
3
  import random
 
4
 
5
  # App Title
6
  st.set_page_config(page_title="Procurement Guide App", page_icon="📘", layout="wide")
@@ -20,17 +21,15 @@ procurement_type = st.sidebar.selectbox(
20
  st.markdown("### Upload Your Procurement Document")
21
  uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
22
 
23
- # Glossary Section
24
- st.sidebar.header("Glossary")
25
- glossary = {
26
- "Procurement": "The process of acquiring goods or services.",
27
- "End-user": "The person who ultimately uses or is intended to use a product or service.",
28
- "Admin": "The person responsible for overseeing and managing operations.",
29
- "Procurement Officer": "The individual responsible for purchasing and managing contracts."
30
- }
31
- st.sidebar.write("Here are some key terms in procurement:")
32
- for term, definition in glossary.items():
33
- st.sidebar.markdown(f"**{term}**: {definition}")
34
 
35
  if uploaded_file is not None:
36
  try:
@@ -38,6 +37,10 @@ if uploaded_file is not None:
38
  pdf_reader = PdfReader(uploaded_file)
39
  pdf_text = "".join(page.extract_text() for page in pdf_reader.pages)
40
 
 
 
 
 
41
  # Display selected options
42
  st.markdown(f"### Selected Role: `{role}`")
43
  st.markdown(f"### Selected Procurement Type: `{procurement_type}`")
@@ -46,41 +49,52 @@ if uploaded_file is not None:
46
  st.markdown("### Document Content:")
47
  st.text_area("PDF Content", pdf_text, height=500)
48
 
49
- # Generate Questions and Check Answers
50
- st.markdown("### Generated Questions:")
51
- sentences = pdf_text.split(".")
52
- if len(sentences) >= 3:
53
- questions = random.sample(sentences, 3)
54
- for i, question in enumerate(questions, 1):
55
- st.markdown(f"**Question {i}:** {question.strip()}?")
56
- user_answer = st.text_input(f"Your Answer to Question {i}:", key=f"answer_{i}")
57
-
58
- # Check correctness if answer is provided
59
- if user_answer:
60
- correct_answer = question.strip()
61
- if user_answer.lower() == correct_answer.lower():
62
- st.success(f"Correct! Your answer matches the expected answer.")
63
- else:
64
- st.error(f"Incorrect. The correct answer is: {correct_answer}")
65
- else:
66
- st.warning("Not enough content to generate questions.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
  except Exception as e:
69
  st.error(f"Error reading the PDF: {e}")
70
  else:
71
  st.info("Please upload a PDF file to view its content.")
72
 
73
- # Checklist Section
74
- st.sidebar.header("Procurement Checklist")
75
- checklist = [
76
- "Ensure the document is signed by the authorized person",
77
- "Verify that the items are properly listed and described",
78
- "Check for any required legal or compliance information",
79
- "Confirm payment terms and conditions"
80
- ]
81
- for item in checklist:
82
- st.sidebar.checkbox(item)
83
-
84
  # Footer
85
  st.markdown("---")
86
- st.markdown("© 2025 Procurement Guide App - Powered by Streamlit")
 
1
  import streamlit as st
2
  from PyPDF2 import PdfReader
3
  import random
4
+ import re
5
 
6
  # App Title
7
  st.set_page_config(page_title="Procurement Guide App", page_icon="📘", layout="wide")
 
21
  st.markdown("### Upload Your Procurement Document")
22
  uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
23
 
24
+ # Function to extract glossary terms
25
+ def extract_glossary(text):
26
+ glossary_terms = re.findall(r"\b[A-Z][a-z]+\b", text)
27
+ return list(set(glossary_terms))
28
+
29
+ # Function to extract checklist items
30
+ def extract_checklist(text):
31
+ checklist_items = re.findall(r"(\d+\.\s.*|\•\s.*)", text)
32
+ return checklist_items
 
 
33
 
34
  if uploaded_file is not None:
35
  try:
 
37
  pdf_reader = PdfReader(uploaded_file)
38
  pdf_text = "".join(page.extract_text() for page in pdf_reader.pages)
39
 
40
+ # Extract glossary terms and checklist items
41
+ glossary = extract_glossary(pdf_text)
42
+ checklist = extract_checklist(pdf_text)
43
+
44
  # Display selected options
45
  st.markdown(f"### Selected Role: `{role}`")
46
  st.markdown(f"### Selected Procurement Type: `{procurement_type}`")
 
49
  st.markdown("### Document Content:")
50
  st.text_area("PDF Content", pdf_text, height=500)
51
 
52
+ # Selection box for content to display
53
+ content_choice = st.selectbox("Choose what to view:", ["Questions", "Glossary", "Checklist"])
54
+
55
+ if content_choice == "Questions":
56
+ # Generate Questions and Check Answers
57
+ st.markdown("### Generated Questions:")
58
+ sentences = pdf_text.split(".")
59
+ if len(sentences) >= 3:
60
+ questions = random.sample(sentences, 3)
61
+ for i, question in enumerate(questions, 1):
62
+ st.markdown(f"**Question {i}:** {question.strip()}?")
63
+ user_answer = st.text_input(f"Your Answer to Question {i}:", key=f"answer_{i}")
64
+
65
+ # Check correctness if answer is provided
66
+ if user_answer:
67
+ correct_answer = question.strip()
68
+ if user_answer.lower() == correct_answer.lower():
69
+ st.success(f"Correct! Your answer matches the expected answer.")
70
+ else:
71
+ st.error(f"Incorrect. The correct answer is: {correct_answer}")
72
+ else:
73
+ st.warning("Not enough content to generate questions.")
74
+
75
+ elif content_choice == "Glossary":
76
+ # Display Glossary
77
+ st.markdown("### Glossary Terms Extracted:")
78
+ if glossary:
79
+ for term in glossary:
80
+ st.markdown(f"- **{term}**")
81
+ else:
82
+ st.markdown("No glossary terms found.")
83
+
84
+ elif content_choice == "Checklist":
85
+ # Display Checklist
86
+ st.markdown("### Checklist Items Extracted:")
87
+ if checklist:
88
+ for item in checklist:
89
+ st.markdown(f"- {item}")
90
+ else:
91
+ st.markdown("No checklist items found.")
92
 
93
  except Exception as e:
94
  st.error(f"Error reading the PDF: {e}")
95
  else:
96
  st.info("Please upload a PDF file to view its content.")
97
 
 
 
 
 
 
 
 
 
 
 
 
98
  # Footer
99
  st.markdown("---")
100
+ st.markdown("© 2025 Procurement Guide App - Powered by Streamlit")