#!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: One Big Beautiful Bill Act 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.

- How are SNAP programs affected? List provision or section number for verification. Output list.

- What are all the environmental reductions, rescinds, and rescissions? List provisions and section number for verification. Output to list.

- What are all the environmental increases, and or establishment appropriations (not rescissions)? List provisions and section number for verification. Output to list.

- What are all the welfare reductions, and rescissions. List provisions and section number for verification. Output to list.

- What are all the law enforcement reductions, and rescissions. List provisions and section number for verification. Output to list.

- What are all the law enforcement increases and or appropriations? List provisions and section number for verification. Output to list.

- What are all the welfare appropriations, and increases?. List provisions and section number for verification. Output to list.

- 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?

- 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?

""" ) #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)