Spaces:
Paused
Paused
Rahul Bhoyar
commited on
Commit
·
72c4532
1
Parent(s):
0541d4f
Updated file
Browse files
app.py
CHANGED
|
@@ -15,40 +15,39 @@ def read_pdf(uploaded_file):
|
|
| 15 |
return text
|
| 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 |
-
main()
|
|
|
|
| 15 |
return text
|
| 16 |
|
| 17 |
|
| 18 |
+
|
| 19 |
+
st.title("PdfQuerier using LLAMA by Rahul Bhoyar")
|
| 20 |
+
hf_token = st.text_input("Enter your Hugging Face token:")
|
| 21 |
+
llm = HuggingFaceInferenceAPI(model_name="HuggingFaceH4/zephyr-7b-alpha", token=hf_token)
|
| 22 |
+
st.markdown("Query your pdf file data with using this chatbot.")
|
| 23 |
+
uploaded_file = st.file_uploader("Choose a PDF file", type=["pdf"])
|
| 24 |
+
|
| 25 |
+
# Creation of Embedding model
|
| 26 |
+
embed_model_uae = HuggingFaceEmbedding(model_name="WhereIsAI/UAE-Large-V1")
|
| 27 |
+
service_context = ServiceContext.from_defaults(llm=llm, chunk_size=800, chunk_overlap=20, embed_model=embed_model_uae)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
file_contents = read_pdf(uploaded_file)
|
| 31 |
+
documents = Document(text=file_contents)
|
| 32 |
+
documents = [documents]
|
| 33 |
+
st.success("Documents loaded successfully!")
|
| 34 |
+
|
| 35 |
+
# Indexing the documents
|
| 36 |
+
progress_container = st.empty()
|
| 37 |
+
progress_container.text("Creating VectorStoreIndex...")
|
| 38 |
+
# Code to create VectorStoreIndex
|
| 39 |
+
index = VectorStoreIndex.from_documents(documents, service_context=service_context, show_progress=True)
|
| 40 |
+
# Persist Storage Context
|
| 41 |
+
index.storage_context.persist()
|
| 42 |
+
st.success("VectorStoreIndex created successfully!")
|
| 43 |
+
# Create Query Engine
|
| 44 |
+
query = st.text_input("Ask a question:")
|
| 45 |
+
query_engine = index.as_query_engine()
|
| 46 |
+
|
| 47 |
+
if query:
|
| 48 |
+
# Run Query
|
| 49 |
+
progress_container.text("Fetching the response...")
|
| 50 |
+
response = query_engine.query(query)
|
| 51 |
+
st.markdown(f"**Response:** {response}")
|
| 52 |
+
|
| 53 |
+
|
|
|