I have this code for pdf_qna generator
!pip install openai pdfplumber streamlit
import openai
import pdfplumber
import streamlit as st
openai.api_key = ‘key’
def extract_text_from_pdf(pdf_file):
with pdfplumber.open(pdf_file) as pdf:
text = “”
for page in pdf.pages:
text += page.extract_text()
return text
def ask_question(text, question):
response = openai.Completion.create(
engine=“text-davinci-002”,
prompt=text,
max_tokens=100,
question=question
)
return response.choices[0].text.strip()
Streamlit app
st.title(‘PDF Question Answering App’)
uploaded_file = st.file_uploader(“Upload a PDF file”, type=“pdf”)
if uploaded_file is not None:
st.write(‘PDF file uploaded successfully!’)
text = extract_text_from_pdf(uploaded_file)
question = st.text_input("Enter your question:")
if st.button("Ask"):
if not question:
st.warning("Please enter a question.")
else:
answer = ask_question(text, question)
st.write("Answer:", answer)
!streamlit run /content/your_notebook.ipynb
but it is not running.Can someone help in debugging this.