Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,48 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import os
|
3 |
-
from src.utils.ingest_text import create_vector_database
|
4 |
-
from src.utils.ingest_image import extract_and_store_images
|
5 |
-
from src.utils.text_qa import qa_bot
|
6 |
-
from src.utils.image_qa import query_and_print_results
|
7 |
-
import nest_asyncio
|
8 |
-
nest_asyncio.apply()
|
9 |
-
|
10 |
-
from dotenv import load_dotenv
|
11 |
-
load_dotenv()
|
12 |
-
|
13 |
-
def get_answer(query,chain):
|
14 |
-
response = chain.invoke(query)
|
15 |
-
return response['result']
|
16 |
-
|
17 |
-
st.title("MULTIMODAL DOC QA")
|
18 |
-
uploaded_file = st.file_uploader("File upload",type="pdf")
|
19 |
-
if uploaded_file is not None:
|
20 |
-
# Save the uploaded file to a temporary location
|
21 |
-
with open(uploaded_file.name, "wb") as f:
|
22 |
-
f.write(uploaded_file.getbuffer())
|
23 |
-
|
24 |
-
# Get the absolute path of the saved file
|
25 |
-
path = os.path.abspath(uploaded_file.name)
|
26 |
-
st.write(f"File saved to: {path}")
|
27 |
-
print(path)
|
28 |
-
|
29 |
-
st.write("Document uploaded successfuly!")
|
30 |
-
|
31 |
-
|
32 |
-
if st.button("Start Processing"):
|
33 |
-
with st.spinner("Processing"):
|
34 |
-
client = create_vector_database(path)
|
35 |
-
image_vdb = extract_and_store_images(path)
|
36 |
-
chain = qa_bot(client)
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
from src.utils.ingest_text import create_vector_database
|
4 |
+
from src.utils.ingest_image import extract_and_store_images
|
5 |
+
from src.utils.text_qa import qa_bot
|
6 |
+
from src.utils.image_qa import query_and_print_results
|
7 |
+
import nest_asyncio
|
8 |
+
nest_asyncio.apply()
|
9 |
+
|
10 |
+
from dotenv import load_dotenv
|
11 |
+
load_dotenv()
|
12 |
+
|
13 |
+
def get_answer(query,chain):
|
14 |
+
response = chain.invoke(query)
|
15 |
+
return response['result']
|
16 |
+
|
17 |
+
st.title("MULTIMODAL DOC QA")
|
18 |
+
uploaded_file = st.file_uploader("File upload",type="pdf")
|
19 |
+
if uploaded_file is not None:
|
20 |
+
# Save the uploaded file to a temporary location
|
21 |
+
with open(uploaded_file.name, "wb") as f:
|
22 |
+
f.write(uploaded_file.getbuffer())
|
23 |
+
|
24 |
+
# Get the absolute path of the saved file
|
25 |
+
path = os.path.abspath(uploaded_file.name)
|
26 |
+
st.write(f"File saved to: {path}")
|
27 |
+
print(path)
|
28 |
+
|
29 |
+
st.write("Document uploaded successfuly!")
|
30 |
+
|
31 |
+
|
32 |
+
if st.button("Start Processing"):
|
33 |
+
with st.spinner("Processing"):
|
34 |
+
client = create_vector_database(path)
|
35 |
+
image_vdb = extract_and_store_images(path)
|
36 |
+
chain = qa_bot(client)
|
37 |
+
|
38 |
+
|
39 |
+
if user_input := st.chat_input("User Input"):
|
40 |
+
with st.chat_message("user"):
|
41 |
+
st.markdown(user_input)
|
42 |
+
|
43 |
+
with st.spinner("Generating Response..."):
|
44 |
+
response = get_answer(chain,user_input)
|
45 |
+
answer = response['result']
|
46 |
+
st.markdown(answer)
|
47 |
+
query_and_print_results(image_vdb,user_input)
|
48 |
|