Spaces:
Paused
Paused
Rahul Bhoyar
commited on
Commit
·
cba56a4
1
Parent(s):
b4fe0a7
Files Updated
Browse files- .gitignore +3 -1
- app.py +11 -23
.gitignore
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
venv/
|
2 |
-
data/*
|
|
|
|
|
|
1 |
venv/
|
2 |
+
data/*
|
3 |
+
app2.py
|
4 |
+
app3.py
|
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import copy
|
2 |
import streamlit as st
|
3 |
from llama_index import VectorStoreIndex
|
4 |
from llama_index import ServiceContext
|
@@ -9,12 +8,13 @@ from PyPDF2 import PdfReader
|
|
9 |
|
10 |
# Streamlit title and description
|
11 |
st.title("PDF querying using Llama-Index by Rahul Bhoyar")
|
12 |
-
st.write("Base Model
|
13 |
-
st.write("Embedding Model
|
14 |
-
st.write("This app allows you to upload your own
|
15 |
|
16 |
hf_token = st.text_input("Enter your Hugging Face token:")
|
17 |
|
|
|
18 |
def read_pdf(uploaded_file):
|
19 |
pdf_reader = PdfReader(uploaded_file)
|
20 |
text = ""
|
@@ -22,6 +22,7 @@ def read_pdf(uploaded_file):
|
|
22 |
text += pdf_reader.pages[page_num].extract_text()
|
23 |
return text
|
24 |
|
|
|
25 |
# Streamlit input for user file upload
|
26 |
success = False
|
27 |
query_engine_creation = False
|
@@ -34,12 +35,11 @@ if uploaded_pdf is not None:
|
|
34 |
documents = [documents]
|
35 |
st.success("Documents loaded successfully!")
|
36 |
|
37 |
-
|
|
|
|
|
38 |
with st.spinner('Creating Vector Embeddings...'):
|
39 |
-
llm = HuggingFaceInferenceAPI(model_name="HuggingFaceH4/zephyr-7b-alpha", token=hf_token)
|
40 |
embed_model_uae = HuggingFaceEmbedding(model_name="WhereIsAI/UAE-Large-V1")
|
41 |
-
|
42 |
-
|
43 |
service_context = ServiceContext.from_defaults(
|
44 |
llm=llm, chunk_size=800, chunk_overlap=20, embed_model=embed_model_uae
|
45 |
)
|
@@ -50,19 +50,10 @@ if uploaded_pdf is not None:
|
|
50 |
# Display the result of the task
|
51 |
st.success("Vector embeddings created.")
|
52 |
success = True
|
53 |
-
# # Streamlit input for user query
|
54 |
-
# user_query = st.text_input("Enter your query:")
|
55 |
-
|
56 |
-
# # Query engine with user input
|
57 |
-
# if user_query:
|
58 |
-
# with st.spinner('Fetching the response...'):
|
59 |
-
# response = query_engine.query(user_query)
|
60 |
-
|
61 |
-
# st.markdown(f"**Response:** {response}")
|
62 |
else:
|
63 |
st.write("Please upload a file first.")
|
64 |
-
|
65 |
-
if query_engine_creation:
|
66 |
QUERY_ENGINE = query_engine
|
67 |
|
68 |
# Streamlit input for user query
|
@@ -73,8 +64,5 @@ if query_engine_creation:
|
|
73 |
if user_query:
|
74 |
with st.spinner('Fetching the response...'):
|
75 |
response = QUERY_ENGINE.query(user_query)
|
76 |
-
|
77 |
-
st.markdown(f"**Response:** {response}")
|
78 |
|
79 |
-
|
80 |
-
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from llama_index import VectorStoreIndex
|
3 |
from llama_index import ServiceContext
|
|
|
8 |
|
9 |
# Streamlit title and description
|
10 |
st.title("PDF querying using Llama-Index by Rahul Bhoyar")
|
11 |
+
st.write("Base Model: **HuggingFaceH4/zephyr-7b-alpha (open-source from HuggingFace)**")
|
12 |
+
st.write("Embedding Model: **WhereIsAI/UAE-Large-V1 (open-source from HuggingFace)**")
|
13 |
+
st.write("This app allows you to upload your own PDF and query your document.")
|
14 |
|
15 |
hf_token = st.text_input("Enter your Hugging Face token:")
|
16 |
|
17 |
+
|
18 |
def read_pdf(uploaded_file):
|
19 |
pdf_reader = PdfReader(uploaded_file)
|
20 |
text = ""
|
|
|
22 |
text += pdf_reader.pages[page_num].extract_text()
|
23 |
return text
|
24 |
|
25 |
+
|
26 |
# Streamlit input for user file upload
|
27 |
success = False
|
28 |
query_engine_creation = False
|
|
|
35 |
documents = [documents]
|
36 |
st.success("Documents loaded successfully!")
|
37 |
|
38 |
+
model = st.selectbox('Select the model', ('google/flan-t5-xxl','HuggingFaceH4/zephyr-7b-alpha'), index=0)
|
39 |
+
llm = HuggingFaceInferenceAPI(model_name=model, token=hf_token)
|
40 |
+
|
41 |
with st.spinner('Creating Vector Embeddings...'):
|
|
|
42 |
embed_model_uae = HuggingFaceEmbedding(model_name="WhereIsAI/UAE-Large-V1")
|
|
|
|
|
43 |
service_context = ServiceContext.from_defaults(
|
44 |
llm=llm, chunk_size=800, chunk_overlap=20, embed_model=embed_model_uae
|
45 |
)
|
|
|
50 |
# Display the result of the task
|
51 |
st.success("Vector embeddings created.")
|
52 |
success = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
else:
|
54 |
st.write("Please upload a file first.")
|
55 |
+
|
56 |
+
if query_engine_creation:
|
57 |
QUERY_ENGINE = query_engine
|
58 |
|
59 |
# Streamlit input for user query
|
|
|
64 |
if user_query:
|
65 |
with st.spinner('Fetching the response...'):
|
66 |
response = QUERY_ENGINE.query(user_query)
|
|
|
|
|
67 |
|
68 |
+
st.markdown(f"**Response:** {response}")
|
|