Spaces:
Sleeping
Sleeping
File size: 1,494 Bytes
91c7e66 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 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 |
import streamlit as st
import os
from src.utils.ingest_text import create_vector_database
from src.utils.ingest_image import extract_and_store_images
from src.utils.text_qa import qa_bot
from src.utils.image_qa import query_and_print_results
import nest_asyncio
nest_asyncio.apply()
from dotenv import load_dotenv
load_dotenv()
def get_answer(query,chain):
response = chain.invoke(query)
return response['result']
st.title("MULTIMODAL DOC QA")
uploaded_file = st.file_uploader("File upload",type="pdf")
if uploaded_file is not None:
# Save the uploaded file to a temporary location
with open(uploaded_file.name, "wb") as f:
f.write(uploaded_file.getbuffer())
# Get the absolute path of the saved file
path = os.path.abspath(uploaded_file.name)
st.write(f"File saved to: {path}")
print(path)
st.write("Document uploaded successfuly!")
if st.button("Start Processing"):
with st.spinner("Processing"):
client = create_vector_database(path)
image_vdb = extract_and_store_images(path)
chain = qa_bot(client)
if user_input := st.chat_input("User Input"):
with st.chat_message("user"):
st.markdown(user_input)
with st.spinner("Generating Response..."):
response = get_answer(chain,user_input)
answer = response['result']
st.markdown(answer)
query_and_print_results(image_vdb,user_input)
|