streamlit: Using Streamlit to chat with PDF document --> Segmentation fault: 11 renders Streamlit app unusable
Checklist
- I have searched the existing issues for similar issues.
- I added a very descriptive title to this issue.
- I have provided sufficient information below to help reproduce this issue.
Summary
I’m new to LangChain & Streamlit. When I run the below code, I keep getting an error once I run the Streamlit app – “Segmentation fault: 11”. I am then unable to get the app to render.
Any idea on what this segmentation fault means?
Reproducible Code Example
# file name: demo1.py
# pip install
# !pip3 install langchain
# !pip3 install streamlit
# !pip3 install streamlit_chat
# !pip3 install pypdf
# !pip3 install openai
# !pip3 install chromadb
# !pip3 install tiktoken
# imports
import os
from langchain.llms import OpenAI
from langchain.document_loaders import PyPDFLoader
from langchain.indexes import VectorstoreIndexCreator
import streamlit as st
# set API keys and the models to use
API_KEY = "<OpenAI API Key>"
# add openai api key for use
os.environ["OPENAI_API_KEY"] = API_KEY
loaders = PyPDFLoader('<PDF file>')
# create a vector representation of the loaded document
index = VectorstoreIndexCreator().from_loaders([loaders])
# setup streamlit app
st.title('🦜 Query your PDF document ')
prompt = st.text_input("Enter your question to query your PDF documents")
# display the current response. No chat history is maintained
if prompt:
response = index.query(llm=OpenAI(model_name="gpt-3.5-turbo", temperature=0.2), question = prompt, chain_type = 'stuff')
# write the results from the LLM to the UI
st.write("<b>" + prompt + "</b><br><i>" + response + "</i><hr>", unsafe_allow_html=True)
Steps To Reproduce
- Run the demo1.py file as shown in the ‘Reproducible Code Example’ section.
Expected Behavior
Streamlit UI should render as follows:
Current Behavior
Terminal output is as follows:
$ /usr/local/bin/python3 /Users/<username>/Documents/GitHub/langchain-ade-private/demo1.py 2023-10-31 16:44:34.578 Warning: to view this Streamlit app on a browser, run it with the following command:
streamlit run /Users/<username>/Documents/GitHub/langchain-ade-private/demo1.py [ARGUMENTS]
$ streamlit run /Users/<username>/Documents/GitHub/langchain-ade-private/demo1.py
You can now view your Streamlit app in your browser.
Local URL: <Local URL> Network URL: <Network URL>
For better performance, install the Watchdog module:
$ xcode-select --install $ pip install watchdog
Segmentation fault: 11
Is this a regression?
- Yes, this used to work in a previous version.
Debug info
- Streamlit version: 1.28.0
- Python version: 3.11.6
- Operating System: macOS Big Sur (version 11.7.3)
- Browser: Google Chrome (version 118.0.5993.117)
Additional Information
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 10
- Comments: 15 (1 by maintainers)
If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.
Your feedback helps us prioritize which bugs to investigate and address first.
Hey @slsu0424 we’ve seen reports of these. It seems reinstalling macos fixing it makes this seem related to the environment and less with Streamlit. Going to close unless we can figure out a reliable repro for this. Let us know if we can reliably get a repro.
why close it, i have the same problem, just cause reinstall can fix it , i spend 2 days on this pr, so let others know how to solve this issue effectively