исправь ошибку C:\Users\1thes\.virtualenvs\1thes-z4jNhpVC\Scripts\python.exe…
- User
исправь ошибку C:\Users\1thes.virtualenvs\1thes-z4jNhpVC\Scripts\python.exe C:\Users\1thes\PycharmProjects\pythonProject\main.py Traceback (most recent call last): File "C:\Users\1thes\PycharmProjects\pythonProject\main.py", line 6, in from gensim.summarization import summarize File "C:\Users\1thes.virtualenvs\1thes-z4jNhpVC\lib\site-packages\gensim_init_.py", line 11, in from gensim import parsing, corpora, matutils, interfaces, models, similarities, utils # noqa:F401 File "C:\Users\1thes.virtualenvs\1thes-z4jNhpVC\lib\site-packages\gensim\corpora_init_.py", line 6, in from .indexedcorpus import IndexedCorpus # noqa:F401 must appear before the other classes File "C:\Users\1thes.virtualenvs\1thes-z4jNhpVC\lib\site-packages\gensim\corpora\indexedcorpus.py", line 14, in from gensim import interfaces, utils File "C:\Users\1thes.virtualenvs\1thes-z4jNhpVC\lib\site-packages\gensim\interfaces.py", line 19, in from gensim import utils, matutils File "C:\Users\1thes.virtualenvs\1thes-z4jNhpVC\lib\site-packages\gensim\matutils.py", line 20, in from scipy.linalg import get_blas_funcs, triu ImportError: cannot import name 'triu' from 'scipy.linalg' (C:\Users\1thes.virtualenvs\1thes-z4jNhpVC\lib\site-packages\scipy\linalg_init_.py) в коде: import os import re from PyPDF2 import PdfReader # Используем PdfReader вместо PdfFileReader from pathlib import Path from gensim.summarization import summarize
def extract_text_from_pdf(filepath): try: with open(filepath, 'rb') as file: reader = PdfReader(file) text = "" for page in reader.pages: text += page.extract_text() return text except Exception as e: print(f"Ошибка при извлечении текста из PDF: {e}") return None
def split_text_into_paragraphs(text): paragraphs = re.split(r'\n\s*\n', text) # Разделение по двум и более пустым строкам paragraphs = [p.strip() for p in paragraphs if p.strip()] # Удаление пустых строк return paragraphs
def summarize_heading(paragraph, heading_limit=50): # Используем библиотеку gensim для суммаризации summary = summarize(paragraph, word_count=heading_limit) if not summary: # Если суммаризация неуспешна, возьмем первые несколько слов words = paragraph.split() summary = ' '.join(words[:heading_limit]) return summary.strip()
def generate_chatgpt_prompts(paragraphs): prompts = {} for i, paragraph in enumerate(paragraphs): summary = summarize_heading(paragraph) prompt_text = paragraph.strip() if 'карты' in summary.lower(): prompt = f"Опиши формат данных для карт в игре Babylon5 CCG, используя этот текст: {prompt_text}" elif 'правила' in summary.lower(): prompt = f"Используя этот текст, обобщи и опиши основные правила игры Babylon5 CCG: {prompt_text}" else: prompt = f"Используя этот текст, создай соответствующий программный код на Python: {prompt_text}" heading = clean_filename(f"{i+1}{summary}") prompts[heading] = prompt return prompts
def clean_filename(filename): # Заменяем недопустимые символы и убираем переводы строк для имен файлов return re.sub(r'[/*?:"<>|]', "", filename).strip()
- Assistant