Я пытаюсь извлечь таблицы и текст из PDF-файла, а они задают вопросы относительно PDF-файлов с помощью llms. Однако, когда я запускаю код, он показывает ошибку 10061. Я думаю, это потому, что я использую Camelot для извлечения таблиц, раньше была ошибка Ghostscript, а теперь появляется вот это.
st.title("Chat with Your PDF Documents - Enhanced Edition")
# Initialize embeddings in session state
if "vector" not in st.session_state:
st.session_state.embeddings = OllamaEmbeddings(model='nomic-embed-text')
uploaded_file = st.file_uploader("Upload a PDF document", type=["pdf"])
if uploaded_file is not None:
with open("uploaded_document.pdf", "wb") as f:
f.write(uploaded_file.read())
try:
loader = PyPDFLoader("uploaded_document.pdf")
docs = loader.load()
text_content = "\n\n".join([doc.page_content for doc in docs])
except Exception as e:
st.error(f"Failed to extract text from PDF: {e}")
text_content = ""
# **Extract Tables**
try:
tables = camelot.read_pdf("uploaded_document.pdf", pages="all")
table_content = ""
if tables:
for i, table in enumerate(tables):
table_content += f"\n\nTable {i + 1}:\n{table.df.to_string(index=False)}"
else:
st.warning("No tables found in the PDF.")
except Exception as e:
st.error(f"Failed to extract tables from PDF: {e}")
table_content = ""
combined_content = text_content + table_content
st.session_state.text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
st.session_state.documents = st.session_state.text_splitter.split_text(combined_content)
st.session_state.vector = FAISS.from_texts(st.session_state.documents, st.session_state.embeddings)
else:
# Fallback to directory loading
directory_path = st.text_input("Enter the path of your local document directory")
if directory_path:
loader = DirectoryLoader(directory_path, glob="*.txt")
st.session_state.docs = loader.load()
Подробнее здесь: https://stackoverflow.com/questions/792 ... n-could-be
Извлечение текста из PDF, ConnectError: [WinError 10061] Не удалось установить соединение, поскольку целевой компьютер а ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Осколок pytest-bdd Не удалось установить новое соединение: [WinError 10061]
Anonymous » » в форуме Python - 0 Ответы
- 32 Просмотры
-
Последнее сообщение Anonymous
-