npolimeni commited on
Commit
2cab561
·
1 Parent(s): ff87b14
Files changed (3) hide show
  1. README.md +29 -13
  2. chatbot.py +83 -0
  3. requirements.txt +64 -0
README.md CHANGED
@@ -1,13 +1,29 @@
1
- ---
2
- title: Legislation Chatbot
3
- emoji: 📉
4
- colorFrom: green
5
- colorTo: yellow
6
- sdk: streamlit
7
- sdk_version: 1.28.2
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # legislation-chatbot
2
+
3
+ ### [Link](https://legislation-chat.streamlit.app/) to Web App
4
+ ### What is this?
5
+ An intelligent, ChatGPT-like chatbot for asking about US legislation, built on
6
+ cutting-edge LLMs and a database of thousands of Congressional documents. It is
7
+ also accessible as an API.
8
+
9
+ ### Why?
10
+ Federal legislation impacts the entire nation, but there are hundreds
11
+ of thousands of documents to sift through. Unfortunately, that makes it
12
+ possible to hide important changes from the people. Use it to learn more about
13
+ issues you care about or even as a research assistant.
14
+
15
+ ### How?
16
+ Utilizing the Congress API, sentence transformers, Google Cloud functions, and
17
+ built off of Anthropic's Claude-2 (shout-out to Anthropic for
18
+ providing an API key!), we've created a complex retrieval-augmented generative AI to answer your
19
+ queries.
20
+
21
+ ### How do I use this?
22
+ Try to ask about bills related to a topic you care about, ask for details about
23
+ a specific bill, or anything you think is important! **Power to the people :fist:**
24
+
25
+ **More info** [here](https://devpost.com/software/legislation-llm), including potential future features (like notifications
26
+ for topics you care about)!
27
+
28
+ **Authors: [Nicholas Polimeni](https://www.linkedin.com/in/nickpolimeni/),
29
+ [Faris Durrani](https://www.linkedin.com/in/farisdurrani/), [Justin Singh](https://www.linkedin.com/in/justin-singh-/)
chatbot.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+ import ast
4
+ import re
5
+
6
+ import streamlit as st
7
+
8
+
9
+ def query_llm(query):
10
+ url = "https://us-east4-legistlation-llm.cloudfunctions.net/llm-backend"
11
+ data = {"query": query}
12
+ response = requests.post(
13
+ url, data=json.dumps(data), headers={"Content-Type": "application/json"}
14
+ ).json()
15
+ return response["answer"], response["context"]
16
+
17
+
18
+ def main():
19
+ st.set_page_config(layout="wide", page_title="Legislation Chatbot")
20
+ left, right = st.columns(2, gap="large")
21
+ answer = None
22
+
23
+ with left:
24
+ st.title("US Legislation Chatbot")
25
+ st.subheader("Enter a query about US legislation")
26
+ user_input = st.text_input("Input", label_visibility="hidden")
27
+ if user_input:
28
+ with st.spinner(
29
+ "Please wait while we analyze thousands of documents (average response time: 30 sec)..."
30
+ ):
31
+ answer, context = query_llm(user_input)
32
+ st.divider()
33
+ st.write(
34
+ """
35
+ ### What is this?
36
+ An intelligent, ChatGPT-like chatbot for asking about US legislation, built on
37
+ cutting-edge LLMs and a database of thousands of Congressional documents. It is
38
+ also accessible as an API.
39
+
40
+ ### Why?
41
+ Federal legislation impacts the entire nation, but there are hundreds
42
+ of thousands of documents to sift through. Unfortunately, that makes it
43
+ possible to hide important changes from the people. Use it to learn more about
44
+ issues you care about or even as a research assistant.
45
+
46
+ ### How?
47
+ Utilizing the Congress API, sentence transformers, Google Cloud functions, and
48
+ built off of Anthropic's Claude-2 (shout-out to Anthropic for
49
+ providing an API key!), we've created a complex retrieval-augmented generative AI to answer your
50
+ queries.
51
+
52
+ ### How do I use this?
53
+ Try to ask about bills related to a topic you care about, ask for details about
54
+ a specific bill, or anything you think is important! **Power to the people :fist:**
55
+
56
+ **More info** [here](https://devpost.com/software/legislation-llm), including potential future features (like notifications
57
+ for topics you care about)!
58
+
59
+ **Authors: [Nicholas Polimeni](https://www.linkedin.com/in/nickpolimeni/),
60
+ [Faris Durrani](https://www.linkedin.com/in/farisdurrani/), [Justin Singh](https://www.linkedin.com/in/justin-singh-/)**
61
+ """
62
+ )
63
+
64
+ with right:
65
+ if answer:
66
+ context = [ast.literal_eval(item) for item in context]
67
+ st.header("Answer")
68
+ st.write(answer)
69
+ st.write("")
70
+ st.subheader("Related Bills and Sub-sections")
71
+ for bill in context:
72
+ for key, val in bill.items():
73
+ key = key.replace(".txt", "").upper()
74
+
75
+ exp = r"[^\w\n .()]+"
76
+ val = re.sub(exp, "", val)
77
+
78
+ with st.expander(f"BILL {key}"):
79
+ st.text(val)
80
+
81
+
82
+ if __name__ == "__main__":
83
+ main()
requirements.txt ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file may be used to create an environment using:
2
+ # $ conda create --name <env> --file <this file>
3
+ # platform: win-64
4
+ altair=5.1.2=pypi_0
5
+ attrs=23.1.0=pypi_0
6
+ blinker=1.7.0=pypi_0
7
+ bzip2=1.0.8=he774522_0
8
+ ca-certificates=2023.08.22=haa95532_0
9
+ cachetools=5.3.2=pypi_0
10
+ certifi=2023.11.17=pypi_0
11
+ charset-normalizer=3.3.2=pypi_0
12
+ click=8.1.7=pypi_0
13
+ colorama=0.4.6=pypi_0
14
+ expat=2.5.0=hd77b12b_0
15
+ gitdb=4.0.11=pypi_0
16
+ gitpython=3.1.40=pypi_0
17
+ idna=3.4=pypi_0
18
+ importlib-metadata=6.8.0=pypi_0
19
+ jinja2=3.1.2=pypi_0
20
+ jsonschema=4.20.0=pypi_0
21
+ jsonschema-specifications=2023.11.1=pypi_0
22
+ libffi=3.4.4=hd77b12b_0
23
+ markdown-it-py=3.0.0=pypi_0
24
+ markupsafe=2.1.3=pypi_0
25
+ mdurl=0.1.2=pypi_0
26
+ numpy=1.26.2=pypi_0
27
+ openssl=3.0.12=h2bbff1b_0
28
+ packaging=23.2=pypi_0
29
+ pandas=2.1.3=pypi_0
30
+ pillow=10.1.0=pypi_0
31
+ pip=23.3=py312haa95532_0
32
+ protobuf=4.25.1=pypi_0
33
+ pyarrow=14.0.1=pypi_0
34
+ pydeck=0.8.1b0=pypi_0
35
+ pygments=2.17.1=pypi_0
36
+ python=3.12.0=h1d929f7_0
37
+ python-dateutil=2.8.2=pypi_0
38
+ pytz=2023.3.post1=pypi_0
39
+ referencing=0.31.0=pypi_0
40
+ requests=2.31.0=pypi_0
41
+ rich=13.7.0=pypi_0
42
+ rpds-py=0.13.0=pypi_0
43
+ setuptools=68.0.0=py312haa95532_0
44
+ six=1.16.0=pypi_0
45
+ smmap=5.0.1=pypi_0
46
+ sqlite=3.41.2=h2bbff1b_0
47
+ streamlit=1.28.2=pypi_0
48
+ tenacity=8.2.3=pypi_0
49
+ tk=8.6.12=h2bbff1b_0
50
+ toml=0.10.2=pypi_0
51
+ toolz=0.12.0=pypi_0
52
+ tornado=6.3.3=pypi_0
53
+ typing-extensions=4.8.0=pypi_0
54
+ tzdata=2023.3=pypi_0
55
+ tzlocal=5.2=pypi_0
56
+ urllib3=2.1.0=pypi_0
57
+ validators=0.22.0=pypi_0
58
+ vc=14.2=h21ff451_1
59
+ vs2015_runtime=14.27.29016=h5e58377_2
60
+ watchdog=3.0.0=pypi_0
61
+ wheel=0.41.2=py312haa95532_0
62
+ xz=5.4.2=h8cc25b3_0
63
+ zipp=3.17.0=pypi_0
64
+ zlib=1.2.13=h8cc25b3_0