import streamlit as st from PyPDF2 import PdfReader import openai import os import csv import textwrap import re import requests def add_line_break(text): # Use the re.sub() function with a regex pattern to add a line break before "amendment" result = re.sub(r"(amendment)", r"\n\1", text) return result def process_pdf(pdf_file): # Your existing code that processes the uploaded PDF print("Processing PDF:", pdf_file.name) # Replace the file path with your actual CSV file containing MPs' information file = "C:\\Users\\phili\\Downloads\\member_list_clean.csv" namedict = dict() biglist = "" with open(file, mode='r') as csvfile: csvFile = csv.reader(csvfile) for lines in csvFile: MPid = lines[1] mpnam = lines[2] mpparty = lines[7] namedict[MPid] = [mpnam, mpparty] biglist += (MPid + "," + mpnam + "," + mpparty) # Rest of your existing code... # Please uncomment and complete the API calls using the openai library. def process_text(text_input): # Your existing code that processes the text input # Please replace the file path with your actual CSV file containing MPs' information file = "C:\\Users\\phili\\Downloads\\member_list_clean.csv" membernam = text_input namedict = dict() biglist = "" with open(file, mode='r') as csvfile: csvFile = csv.reader(csvfile) for lines in csvFile: MPid = lines[1] mpnam1 = lines[2] mpnam2 = lines[3] mpnam3 = lines[4] mpnam4 = lines[5] namedict[MPid] = [mpnam1, mpnam2, mpnam3, mpnam4] idlist = list(namedict.keys()) for nam in idlist: mpnamlist = namedict[nam] if membernam in mpnamlist: memberid = nam break # Rest of your existing code... # Please complete the API calls using the openai library and update the API keys. def main(): house_of_commons_green = "#007A57" # Apply custom CSS to set the background color custom_css = ''' ''' # Use st.markdown() to apply the custom CSS targeting the root element (body) st.markdown(custom_css, unsafe_allow_html=True) st.title("Legislative Passage Toolkit") # File Uploader for PDF uploaded_pdf = st.file_uploader("Upload an amendment here", type=["pdf"]) if uploaded_pdf is not None: # Button to process the uploaded PDF if st.button("Upload Amendments Summary"): process_pdf(uploaded_pdf) user_input = st.text_input("Which MP would you like more information about?:") if st.button("Search MP"): process_text(user_input) if __name__ == "__main__": main()