File size: 4,874 Bytes
7613c93 1c5003e 7613c93 | 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | #!pip install python-dotenv
#pip install duckdb
import duckdb
#pip install llama_index_core
import os
#pip install openai
import openai
import textwrap
#pip install llama_index.vector_stores.duckdb
import llama_index.vector_stores.duckdb
#pip install llama-index-embeddings-openai
#import llama-index-embeddings-openai
import os
import openai
import textwrap
file_path = 'persist/my_vector_store.duckdb'
# Check if file exists
if os.path.exists(file_path):
#Delete the file
os.remove(file_path)
print("File deleted successfully")
else:
print("File doesn't exist - first run - it's all good")
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv('OPENAI_API_KEY')
from openai import OpenAI
client = OpenAI(api_key=api_key)
print("OpenAI key generated")
default_model = os.environ.get('OPENAI_DEFAULT_MODEL')
if default_model:
print(f"The default OpenAI model (from environment variable) is: {default_model}")
else:
print("The OPENAI_DEFAULT_MODEL environment variable is not set.")
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.vector_stores.duckdb import DuckDBVectorStore
from llama_index.core import StorageContext
print("Vector Stores Generated")
# Initialize DuckDB vector store with persistence
vector_store = DuckDBVectorStore("my_vector_store.duckdb", persist_dir="./persist/")
print("Initialized DuckDB vector store with peristance")
documents = SimpleDirectoryReader("PDFs").load_data()
print("PDFs loaded into Duckdb")
storage_context = StorageContext.from_defaults(vector_store=vector_store)
print("storage_context defined")
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)
print("Index generated from vector stores in DuckDB")
import gradio as gr
theme = gr.themes.Default(primary_hue="blue")
def greet(query):
query_engine = index.as_query_engine()
response = query_engine.query(query)
strresponse = str(response)
#return(gradio.Markdown(strresponse))
#return(textwrap.fill(str(response), 80))
return(f"{response}")
with gr.Blocks(theme=theme) as demo:
gr.Markdown(
"""
# One Big Beautiful Bill Act
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.
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>
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.
Suggested Prompts:
- How are Medicaid programs affected? List provision or section number for verification. Output in list.</p>
- How are SNAP programs affected? List provision or section number for verification. Output list.</p>
- What are all the environmental reductions, rescinds, and rescissions? List provisions and section number for verification. Output to list.</p>
- What are all the environmental increases, and or establishment appropriations (not rescissions)? List provisions and section number for verification. Output to list.</p>
- What are all the welfare reductions, and rescissions. List provisions and section number for verification. Output to list.</p>
- What are all the law enforcement reductions, and rescissions. List provisions and section number for verification. Output to list.</p>
- What are all the law enforcement increases and or appropriations? List provisions and section number for verification. Output to list.</p>
- What are all the welfare appropriations, and increases?. List provisions and section number for verification. Output to list.</p>
- 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>
- 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>
"""
)
#gr.Textbox(label="Query", lines=1, interactive=True, placeholder="Type something...", key="input")
#gr.Textbox(label="Response", lines=2, interactive=False, key="output")
# Bind current input/output to function
gr.Interface(fn=greet, inputs=gr.Textbox(label="Query"), outputs=gr.Textbox(label="Response"))
demo.launch(share=True)
|