Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when make outline summary. #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project_explainer_ui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def summarize(summarization_type, github_project_url, github_project_branch="mai
gptExplainer = Explainer(huggingface_model_id)
if summarization_type == "brief":
return gptExplainer.brief(github_url=github_project_url, branch=github_project_branch)["summary"]
return gptExplainer.outline(github_url=github_project_url, branch=github_project_branch)["summary"]
return gptExplainer.outline(github_url=github_project_url, branch=github_project_branch)

demo = gr.Interface(
fn=summarize,
Expand Down
66 changes: 9 additions & 57 deletions project_processor/gh_processor/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,120 +398,72 @@ def get_elements_from_markdown_file(file_path: str, elements: List[str]) -> Dict
return result


def remove_images_from_markdown(file_path: str) -> str:
def remove_images_from_markdown(markdown_content: str) -> str:
"""
Removes image tags from a Markdown file and returns the updated content without images.

Args:
file_path: The path to the Markdown file.
markdown_content: The Markdown content that will be processed.

Returns:
The Markdown content without images.

Raises:
ValueError: If the provided file is not a Markdown file or if the file does not exist.
"""

if not file_path.lower().endswith('.md'):
raise ValueError(
"Invalid file. Only Markdown files (.md) are supported.")

if not os.path.isfile(file_path):
raise ValueError("File not found.")

with open(file_path, 'r') as f:
markdown_content = f.read()


markdown_content_without_images = re.sub(
'!\[.*?\]\(.*?\)', '', markdown_content)

return markdown_content_without_images


def remove_links_from_markdown(file_path: str) -> str:
def remove_links_from_markdown(markdown_content: str) -> str:
"""
Removes link tags from a Markdown file and returns the updated content.

Args:
file_path: The path to the Markdown file.
markdown_content: The Markdown content that will be processed.

Returns:
The Markdown content without links.

Raises:
ValueError: If the provided file is not a Markdown file or if the file does not exist.
"""

if not file_path.lower().endswith('.md'):
raise ValueError(
"Invalid file. Only Markdown files (.md) are supported.")

if not os.path.isfile(file_path):
raise ValueError("File not found.")

with open(file_path, 'r') as f:
markdown_content = f.read()

markdown_content_without_links = re.sub(
'\[.*?\]\(.*?\)', '', markdown_content)

return markdown_content_without_links


def remove_code_blocks_from_markdown(file_path: str) -> str:
def remove_code_blocks_from_markdown(markdown_content: str) -> str:
"""
Removes code blocks from a Markdown file and returns the updated content.

Args:
file_path: The path to the Markdown file.
markdown_content: The Markdown content that will be processed.

Returns:
The Markdown content without code blocks.

Raises:
ValueError: If the provided file is not a Markdown file or if the file does not exist.
"""

if not file_path.lower().endswith('.md'):
raise ValueError(
"Invalid file. Only Markdown files (.md) are supported.")

if not os.path.isfile(file_path):
raise ValueError("File not found.")

with open(file_path, 'r') as f:
markdown_content = f.read()

markdown_content_without_code_blocks = re.sub(
'```[\s\S]*?```', '', markdown_content)

return markdown_content_without_code_blocks


def remove_tables_from_markdown(file_path: str) -> str:
def remove_tables_from_markdown(markdown_content: str) -> str:
"""
Removes tables from a Markdown file and returns the updated content.

Args:
file_path: The path to the Markdown file.
markdown_content: The Markdown content that will be processed.

Returns:
The Markdown content without tables.

Raises:
ValueError: If the provided file is not a Markdown file or if the file does not exist.
"""

if not file_path.lower().endswith('.md'):
raise ValueError(
"Invalid file. Only Markdown files (.md) are supported.")

if not os.path.isfile(file_path):
raise ValueError("File not found.")

with open(file_path, 'r') as f:
markdown_content = f.read()

markdown_content_without_tables = re.sub(
r'\n\|.*\|\n\|.*\|\n(\|.*\|)+', '', markdown_content)

Expand Down