Hi, I have a problem with my app, So its an NLP app that accepts files in pdf format, the app fits on the document the takes user input and I have to grab the text and query the Pre-trained bert model , but upon the user pressing the predict button after writing the query the app reruns all over again, here is my code
import streamlit as st
import pandas as pd
import joblib
import cdqa
import tabula
import docx2txt
from PyPDF2 import PdfFileReader
import os
import pandas as pd
from ast import literal_eval
import urllib.request
from cdqa.utils.converters import pdf_converter
from cdqa.utils.filters import filter_paragraphs
from cdqa.pipeline import QAPipeline
from cdqa.utils.download import download_model
def read_pdf(directory_path='./tempDir/'):
df = pdf_converter(directory_path)
return df
#def load model
def load_model():
model = joblib.load('models/bert_qa.joblib')
cdqa_pipeline = QAPipeline(reader=model, max_df=1.0, )
return cdqa_pipeline
st.subheader("Home")
docx_file = st.file_uploader("Upload Document",type=["pdf"])
if st.button("Process"):
# text = st.text_input("input your query")
if docx_file is not None:
#see details of the file
file_details = {"filename":docx_file.name,
"filetype":docx_file.type,
"filesize":docx_file.size}
st.json(file_details)
with open(os.path.join("tempDir",docx_file.name),"wb") as f:
f.write(docx_file.getbuffer())
df = read_pdf()
with st.spinner("fitting the model...."):
pipeline = load_model()
pipeline.fit_retriever(df=df)
st.write(type(docx_file))
st.success("model has been fitted")
text = st.text_input("Query Model",placeholder="Type your query")
if st.button("Predict"):
if text is not None:
prediction = pipeline.predict(text)
res = { "Query" : text,
"Answer": prediction[0],
"Title" : prediction[1],
"Paragraph":prediction[2]}
st.write(res)
st.json(res)
else:
st.warning("you have not typed your query")