Spaces:
Sleeping
Sleeping
Pratik Dwivedi
commited on
Commit
·
543f41b
1
Parent(s):
9694dd7
changed
Browse files
app.py
CHANGED
@@ -1,9 +1,40 @@
|
|
1 |
import streamlit as st
|
2 |
from llmware.prompts import Prompt
|
|
|
|
|
|
|
3 |
import requests
|
4 |
import io, os, re
|
5 |
import PyPDF2
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def register_gguf_model():
|
8 |
|
9 |
prompter = Prompt()
|
@@ -28,37 +59,43 @@ def register_gguf_model():
|
|
28 |
|
29 |
def main():
|
30 |
st.title("BetterZila RAG Enabled LLM")
|
31 |
-
with st.spinner("Registering Models for use..."):
|
32 |
-
|
33 |
|
34 |
data_path = "data/"
|
35 |
|
36 |
# keep the select box to llama as default but give a button right below it that says select model after which the model will be loaded
|
37 |
-
st.sidebar.subheader("Select Model")
|
38 |
-
model_name = st.sidebar.selectbox("Select Model", ["llama", "open_gpt4", "phi2", "mistral"])
|
39 |
-
with st.spinner("Loading Model..."):
|
40 |
-
|
41 |
-
st.success("Model Loaded!")
|
42 |
|
43 |
queries = ['Can you give me an example from history where the enemy was crushed totally from the book?', "What's the point of making myself less accessible?", "Can you tell me the story of Queen Elizabeth I from this 48 laws of power book?"]
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
if __name__ == "__main__":
|
64 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
from llmware.prompts import Prompt
|
3 |
+
from llmware.library import Library
|
4 |
+
from llmware.retrieval import Query
|
5 |
+
from llmware.setup import Setup
|
6 |
import requests
|
7 |
import io, os, re
|
8 |
import PyPDF2
|
9 |
|
10 |
+
def create_fin_docs_sample_library(library_name):
|
11 |
+
|
12 |
+
print(f"update: creating library - {library_name}")
|
13 |
+
|
14 |
+
library = Library().create_new_library(library_name)
|
15 |
+
sample_files_path = Setup().load_sample_files(over_write=False)
|
16 |
+
ingestion_folder_path = os.path.join(sample_files_path, "data")
|
17 |
+
parsing_output = library.add_files(ingestion_folder_path)
|
18 |
+
library.install_new_embedding(embedding_model_name="mini-lm-sbert", vector_db="faiss",batch_size=200)
|
19 |
+
return library
|
20 |
+
|
21 |
+
def basic_semantic_retrieval_example (library):
|
22 |
+
|
23 |
+
q = Query(library)
|
24 |
+
|
25 |
+
# Set the keys that should be returned - optional - full set of keys will be returned by default
|
26 |
+
q.query_result_return_keys = ["distance","file_source", "page_num", "text"]
|
27 |
+
|
28 |
+
# perform a simple query
|
29 |
+
my_query = "Elizabeth I"
|
30 |
+
query_results1 = q.semantic_query(my_query, result_count=20)
|
31 |
+
# print(query_results1)
|
32 |
+
# Iterate through query_results, which is a list of result dicts
|
33 |
+
print(f"\nQuery 1 - {my_query}")
|
34 |
+
for i, result in enumerate(query_results1):
|
35 |
+
print("results - ", i, result)
|
36 |
+
|
37 |
+
|
38 |
def register_gguf_model():
|
39 |
|
40 |
prompter = Prompt()
|
|
|
59 |
|
60 |
def main():
|
61 |
st.title("BetterZila RAG Enabled LLM")
|
62 |
+
# with st.spinner("Registering Models for use..."):
|
63 |
+
# prompter = register_gguf_model()
|
64 |
|
65 |
data_path = "data/"
|
66 |
|
67 |
# keep the select box to llama as default but give a button right below it that says select model after which the model will be loaded
|
68 |
+
# st.sidebar.subheader("Select Model")
|
69 |
+
# model_name = st.sidebar.selectbox("Select Model", ["llama", "open_gpt4", "phi2", "mistral"])
|
70 |
+
# with st.spinner("Loading Model..."):
|
71 |
+
# prompter.load_model(model_name)
|
72 |
+
# st.success("Model Loaded!")
|
73 |
|
74 |
queries = ['Can you give me an example from history where the enemy was crushed totally from the book?', "What's the point of making myself less accessible?", "Can you tell me the story of Queen Elizabeth I from this 48 laws of power book?"]
|
75 |
|
76 |
+
lib = create_fin_docs_sample_library("48laws")
|
77 |
+
res_dict=basic_semantic_retrieval_example(lib)
|
78 |
+
for i, result in enumerate(res_dict):
|
79 |
+
st.write(i, result)
|
80 |
+
# st.subheader("Query")
|
81 |
+
|
82 |
+
# for query in queries:
|
83 |
+
# st.subheader(f"Query: {query}")
|
84 |
+
# with st.spinner("Generating response..."):
|
85 |
+
# for file in os.listdir(data_path):
|
86 |
+
# if file.endswith(".pdf"):
|
87 |
+
# print("Found PDF file: ", file)
|
88 |
+
# print("loading Source...")
|
89 |
+
# source = prompter.add_source_document(data_path, file, query=None)
|
90 |
+
# print("generating response...")
|
91 |
+
# responses = prompter.prompt_with_source(query, prompt_name="just_the_facts", temperature=0.3)
|
92 |
+
# print("response generated!")
|
93 |
+
# for r, response in enumerate(responses):
|
94 |
+
# print(query, ":", re.sub("[\n]"," ", response["llm_response"]).strip())
|
95 |
+
# prompter.clear_source_materials()
|
96 |
+
# st.write(query)
|
97 |
+
# st.write(re.sub("[\n]"," ", response["llm_response"]).strip())
|
98 |
+
# st.success("Response generated!")
|
99 |
|
100 |
if __name__ == "__main__":
|
101 |
main()
|