Spaces:
Runtime error
Runtime error
File size: 2,925 Bytes
cb98a9e 04a30cc cb98a9e 04a30cc ba52e15 cb98a9e ba52e15 cb98a9e ba52e15 cb98a9e ba52e15 cb98a9e ba52e15 cb98a9e ba52e15 cb98a9e ba52e15 cb98a9e ba52e15 cb98a9e ba52e15 cb98a9e ba52e15 cb98a9e ba52e15 8bd698c cb98a9e ba52e15 cb98a9e ba52e15 cb98a9e ba52e15 cb98a9e ba52e15 cb98a9e | 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 | 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 = '''
<style>
body {
background-color: #007A57;
}
container {
background-color: #007A57;
}
</style>
'''
# 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()
|