Spaces:
Paused
Paused
Rahul Bhoyar
commited on
Commit
·
0cec20e
1
Parent(s):
08728cc
Updated files
Browse files- .DS_Store +0 -0
- app.py +23 -8
- requirements.txt +2 -1
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
app.py
CHANGED
|
@@ -61,7 +61,8 @@ from llama_index import SimpleDirectoryReader, VectorStoreIndex
|
|
| 61 |
from llama_index import ServiceContext
|
| 62 |
from llama_index.embeddings import HuggingFaceEmbedding
|
| 63 |
from llama_index.llms import HuggingFaceInferenceAPI
|
| 64 |
-
import
|
|
|
|
| 65 |
|
| 66 |
# os.environ["GOOGLE_API_KEY"]="AIzaSyBYrZpUdTc4rumhdHajlKfwY4Kq0u6vFDs"
|
| 67 |
|
|
@@ -73,19 +74,33 @@ hf_token = st.text_input("Enter your Hugging Face token:")
|
|
| 73 |
|
| 74 |
|
| 75 |
#function to save a file
|
| 76 |
-
def save_uploadedfile(uploadedfile):
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
# Streamlit input for user file upload
|
| 82 |
uploaded_pdf = st.file_uploader("Upload your PDF", type=['pdf'])
|
| 83 |
|
| 84 |
# Load data and configure the index
|
| 85 |
if uploaded_pdf is not None:
|
| 86 |
-
input_file = save_uploadedfile(uploaded_pdf)
|
| 87 |
-
st.write("File uploaded successfully!")
|
| 88 |
-
documents = SimpleDirectoryReader("data").load_data()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
llm = HuggingFaceInferenceAPI(model_name="HuggingFaceH4/zephyr-7b-alpha", token=hf_token)
|
| 90 |
embed_model_uae = HuggingFaceEmbedding(model_name="WhereIsAI/UAE-Large-V1")
|
| 91 |
|
|
|
|
| 61 |
from llama_index import ServiceContext
|
| 62 |
from llama_index.embeddings import HuggingFaceEmbedding
|
| 63 |
from llama_index.llms import HuggingFaceInferenceAPI
|
| 64 |
+
from llama_index.schema import Document
|
| 65 |
+
from PyPDF2 import PdfReader
|
| 66 |
|
| 67 |
# os.environ["GOOGLE_API_KEY"]="AIzaSyBYrZpUdTc4rumhdHajlKfwY4Kq0u6vFDs"
|
| 68 |
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
#function to save a file
|
| 77 |
+
# def save_uploadedfile(uploadedfile):
|
| 78 |
+
# with open(os.path.join("data",uploadedfile.name),"wb") as f:
|
| 79 |
+
# f.write(uploadedfile.getbuffer())
|
| 80 |
+
# return st.success("Saved File:{} to directory".format(uploadedfile.name))
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def read_pdf(uploaded_file):
|
| 84 |
+
pdf_reader = PdfReader(uploaded_file)
|
| 85 |
+
text = ""
|
| 86 |
+
for page_num in range(len(pdf_reader.pages)):
|
| 87 |
+
text += pdf_reader.pages[page_num].extract_text()
|
| 88 |
+
return text
|
| 89 |
|
| 90 |
# Streamlit input for user file upload
|
| 91 |
uploaded_pdf = st.file_uploader("Upload your PDF", type=['pdf'])
|
| 92 |
|
| 93 |
# Load data and configure the index
|
| 94 |
if uploaded_pdf is not None:
|
| 95 |
+
# input_file = save_uploadedfile(uploaded_pdf)
|
| 96 |
+
# st.write("File uploaded successfully!")
|
| 97 |
+
# documents = SimpleDirectoryReader("data").load_data()
|
| 98 |
+
|
| 99 |
+
file_contents = read_pdf(uploaded_pdf)
|
| 100 |
+
documents = Document(text=file_contents)
|
| 101 |
+
documents = [documents]
|
| 102 |
+
st.success("Documents loaded successfully!")
|
| 103 |
+
|
| 104 |
llm = HuggingFaceInferenceAPI(model_name="HuggingFaceH4/zephyr-7b-alpha", token=hf_token)
|
| 105 |
embed_model_uae = HuggingFaceEmbedding(model_name="WhereIsAI/UAE-Large-V1")
|
| 106 |
|
requirements.txt
CHANGED
|
@@ -4,4 +4,5 @@ streamlit
|
|
| 4 |
huggingface_hub[inference]>=0.19.0
|
| 5 |
transformers
|
| 6 |
torch
|
| 7 |
-
watchdog
|
|
|
|
|
|
| 4 |
huggingface_hub[inference]>=0.19.0
|
| 5 |
transformers
|
| 6 |
torch
|
| 7 |
+
watchdog
|
| 8 |
+
PyPDF2
|