GoData commited on
Commit
7613c93
·
1 Parent(s): f960252

initial commit

Browse files
Files changed (3) hide show
  1. .gitignore +4 -0
  2. README.md +12 -0
  3. app2.py +123 -0
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ venv/
2
+ .env
3
+ persist/
4
+ .gradio/
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: LLM Demo
3
+ emoji: 📉
4
+ colorFrom: gray
5
+ colorTo: red
6
+ sdk: static
7
+ pinned: false
8
+ app_file: app2.py
9
+ short_description: LLM Demo of the One Big Beautiful Bill Act
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app2.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!pip install python-dotenv
2
+ #pip install duckdb
3
+ #####
4
+ import duckdb
5
+ #pip install llama_index_core
6
+ import os
7
+ #pip install openai
8
+ import openai
9
+ import textwrap
10
+ #pip install llama_index.vector_stores.duckdb
11
+ import llama_index.vector_stores.duckdb
12
+ #pip install llama-index-embeddings-openai
13
+ #import llama-index-embeddings-openai
14
+ import os
15
+ import openai
16
+ import textwrap
17
+
18
+
19
+
20
+ file_path = 'persist/my_vector_store.duckdb'
21
+
22
+ # Check if file exists
23
+ if os.path.exists(file_path):
24
+ #Delete the file
25
+ os.remove(file_path)
26
+ print("File deleted successfully")
27
+ else:
28
+ print("File doesn't exist - first run - it's all good")
29
+
30
+ from dotenv import load_dotenv
31
+ load_dotenv()
32
+
33
+ api_key = os.getenv('OPENAI_API_KEY')
34
+
35
+ from openai import OpenAI
36
+ client = OpenAI(api_key=api_key)
37
+
38
+
39
+ print("OpenAI key generated")
40
+
41
+
42
+ default_model = os.environ.get('OPENAI_DEFAULT_MODEL')
43
+
44
+ if default_model:
45
+ print(f"The default OpenAI model (from environment variable) is: {default_model}")
46
+ else:
47
+ print("The OPENAI_DEFAULT_MODEL environment variable is not set.")
48
+
49
+
50
+
51
+ from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
52
+ from llama_index.vector_stores.duckdb import DuckDBVectorStore
53
+ from llama_index.core import StorageContext
54
+
55
+ print("Vector Stores Generated")
56
+
57
+
58
+ # Initialize DuckDB vector store with persistence
59
+ vector_store = DuckDBVectorStore("my_vector_store.duckdb", persist_dir="./persist/")
60
+
61
+
62
+ print("Initialized DuckDB vector store with peristance")
63
+
64
+ documents = SimpleDirectoryReader("PDFs").load_data()
65
+
66
+
67
+ print("PDFs loaded into Duckdb")
68
+
69
+ storage_context = StorageContext.from_defaults(vector_store=vector_store)
70
+
71
+ print("storage_context defined")
72
+
73
+ index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)
74
+
75
+ print("Index generated from vector stores in DuckDB")
76
+
77
+
78
+ import gradio as gr
79
+
80
+ theme = gr.themes.Default(primary_hue="blue")
81
+
82
+ def greet(query):
83
+ query_engine = index.as_query_engine()
84
+ response = query_engine.query(query)
85
+ strresponse = str(response)
86
+ #return(gradio.Markdown(strresponse))
87
+ #return(textwrap.fill(str(response), 80))
88
+ return(f"{response}")
89
+
90
+ with gr.Blocks(theme=theme) as demo:
91
+ gr.Markdown(
92
+ """
93
+ # One Big Beautiful Bill Act
94
+
95
+ This is a small customized LLM with actual text of the Act uploaded into the model. The Act was passed by both the House and Senate and has become law. The Democrats, who until now because they do not control the House or Senate have refused to vote to continue funding this act because of the problem with people currently enrolled in the ACA will have increased premiums.
96
+
97
+ The source document is available here: <a href="https://www.congress.gov/bill/119th-congress/house-bill/1/text">One Big Beautiful Bill Act </a>
98
+
99
+ Since LLMs are notorious for generating inaccurate responses, it's a good idea to make sure you ask for the provision or section number when querying so it can be verified with the source document. Specififying "output to list" clarifies the output to a list, if needed.
100
+
101
+
102
+ Suggested Promps:
103
+
104
+ - How are Medicaid programs affected? List provision or section number for verification. Output in list.</p>
105
+ - How are SNAP programs affected? List provision or section number for verification. Output list.</p>
106
+ - What are all the environmental reductions, rescinds, and rescissions? List provisions and section number for verification. Output to list.</p>
107
+ - What are all the environmental increases, and or establishment appropriations (not rescissions)? List provisions and section number for verification. Output to list.</p>
108
+ - What are all the welfare reductions, and rescissions. List provisions and section number for verification. Output to list.</p>
109
+ - What are all the law enforcement reductions, and rescissions. List provisions and section number for verification. Output to list.</p>
110
+ - What are all the law enforcement increases and or appropriations? List provisions and section number for verification. Output to list.</p>
111
+ - What are all the welfare appropriations, and increases?. List provisions and section number for verification. Output to list.</p>
112
+ - What is the DOJ fund named ”BIDEN.” What is it used for? list by item. What provision is it under? How much is being appropriated for it?</p>
113
+ - How is FEMA being appropriated? List the provision or section number along with description for verification. Is FEMA still going to be used for disaster recovery?</p>
114
+ """
115
+ )
116
+ #gr.Textbox(label="Query", lines=1, interactive=True, placeholder="Type something...", key="input")
117
+ #gr.Textbox(label="Response", lines=2, interactive=False, key="output")
118
+
119
+ # Bind current input/output to function
120
+ gr.Interface(fn=greet, inputs=gr.Textbox(label="Query"), outputs=gr.Textbox(label="Response"))
121
+
122
+ demo.launch(share=True)
123
+