Upload 7 files
Browse files- app.py +77 -0
- docs/chroma/47e3871d-a5de-4728-9d16-1de800020642/data_level0.bin +3 -0
- docs/chroma/47e3871d-a5de-4728-9d16-1de800020642/header.bin +3 -0
- docs/chroma/47e3871d-a5de-4728-9d16-1de800020642/length.bin +3 -0
- docs/chroma/47e3871d-a5de-4728-9d16-1de800020642/link_lists.bin +3 -0
- docs/chroma/chroma.sqlite3 +0 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import zipfile
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
from langchain_community.llms import HuggingFaceEndpoint
|
6 |
+
from langchain_community.vectorstores import Chroma # Light-weight and in memory
|
7 |
+
from langchain.chains import RetrievalQA
|
8 |
+
|
9 |
+
|
10 |
+
# Authentication for Huggingface API
|
11 |
+
|
12 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
13 |
+
os.environ["HF_TOKEN"] = HF_TOKEN
|
14 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = HF_TOKEN
|
15 |
+
|
16 |
+
|
17 |
+
# Initialization of LLM
|
18 |
+
|
19 |
+
llm = HuggingFaceEndpoint(
|
20 |
+
repo_id="HuggingFaceH4/zephyr-7b-beta",
|
21 |
+
task="text-generation",
|
22 |
+
max_new_tokens = 512,
|
23 |
+
top_k = 30,
|
24 |
+
temperature = 0.1,
|
25 |
+
repetition_penalty = 1.03,
|
26 |
+
)
|
27 |
+
|
28 |
+
## Embeddings
|
29 |
+
|
30 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
31 |
+
#modelPath = "sentence-transformers/all-MiniLM-l6-v2"
|
32 |
+
modelPath ="mixedbread-ai/mxbai-embed-large-v1"
|
33 |
+
|
34 |
+
# Create a dictionary with model configuration options, specifying to use the CPU for computations
|
35 |
+
model_kwargs = {'device':'cpu'} # cuda/cpu
|
36 |
+
|
37 |
+
# Create a dictionary with encoding options, specifically setting 'normalize_embeddings' to False
|
38 |
+
encode_kwargs = {'normalize_embeddings': False}
|
39 |
+
|
40 |
+
embedding = HuggingFaceEmbeddings(
|
41 |
+
model_name=modelPath, # Provide the pre-trained model's path
|
42 |
+
model_kwargs=model_kwargs, # Pass the model configuration options
|
43 |
+
encode_kwargs=encode_kwargs # Pass the encoding options
|
44 |
+
)
|
45 |
+
|
46 |
+
# Upload the vector db from previous step and unzip
|
47 |
+
|
48 |
+
with zipfile.ZipFile('docs.zip', 'r') as zip_ref:
|
49 |
+
zip_ref.extractall()
|
50 |
+
|
51 |
+
persist_directory = 'docs/chroma/'
|
52 |
+
|
53 |
+
vectordb = Chroma(
|
54 |
+
persist_directory=persist_directory,
|
55 |
+
embedding_function=embedding
|
56 |
+
)
|
57 |
+
|
58 |
+
|
59 |
+
title = "Q&A on enterprise data"
|
60 |
+
description = "Implementation of Open Source RAG on Private Document"
|
61 |
+
|
62 |
+
def quena(question):
|
63 |
+
qa_chain = RetrievalQA.from_chain_type(llm, retriever=vectordb.as_retriever(), return_source_documents=True)
|
64 |
+
result = qa_chain.invoke({"query": question})
|
65 |
+
return result["result"]
|
66 |
+
|
67 |
+
demo=gr.Interface(fn=quena,
|
68 |
+
inputs=gr.Textbox(lines=10,placeholder='''Write your question inside double quotation..Type the Sample Question:\n
|
69 |
+
What are the procedures to move from research to production environment?? Reply in step-wise pointers.'''),
|
70 |
+
outputs="text",
|
71 |
+
title=title,
|
72 |
+
description=description,)
|
73 |
+
# Launch the demo!
|
74 |
+
demo.launch()
|
75 |
+
|
76 |
+
|
77 |
+
|
docs/chroma/47e3871d-a5de-4728-9d16-1de800020642/data_level0.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7cb067fe33203375c131bd05e302087c445eced7f9cda517f1bfcf9ccf622bee
|
3 |
+
size 4236000
|
docs/chroma/47e3871d-a5de-4728-9d16-1de800020642/header.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fcc596bc1909f7cc610d5839236c90513b4fbad06776c253fa1b21bfd712e940
|
3 |
+
size 100
|
docs/chroma/47e3871d-a5de-4728-9d16-1de800020642/length.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cb7075a529c40ae76d21c549db27fd6b791ec42ea469cbf00ae95a9beae5de99
|
3 |
+
size 4000
|
docs/chroma/47e3871d-a5de-4728-9d16-1de800020642/link_lists.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
3 |
+
size 0
|
docs/chroma/chroma.sqlite3
ADDED
Binary file (475 kB). View file
|
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
sentence-transformers
|
2 |
+
langchain
|
3 |
+
chromadb
|
4 |
+
gradio
|