Skip to content
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 agents/crypto_trader_bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Inspired by [How to build your own Add Liquidity Signal Telegram Bot for Solana
1. Clone the repository:
```bash
git clone https://github.com/swarmzero/examples.git
cd examples/agents/crypto-trader-bot
cd examples/agents/crypto_trader_bot
```

2. Install dependencies using Poetry:
Expand Down
6 changes: 6 additions & 0 deletions workflows/pdf_summarizer_tex_workflow/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MODEL=gpt-4o-mini
ENVIRONMENT=dev
OPENAI_API_KEY=
OPENROUTER_MODEL=gryphe/mythomax-l2-13b
SWARMZERO_LOG_LEVEL=INFO
LANGTRACE_API_KEY=
3 changes: 3 additions & 0 deletions workflows/pdf_summarizer_tex_workflow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.venv
swarmzero-data
.env
39 changes: 39 additions & 0 deletions workflows/pdf_summarizer_tex_workflow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# PDF Summarizer to Tex Workflow

A sequential workflow built using SwarmZero framework that enables concise summarization of large pdf's to be outputted in a tex file

## Description

This workflow utilizes PyMuPDF for extracting text out of a pdf and is built on top fo the SwarmZero framework, providing enhanced summarization cpabilities wiht AI-powered processing.

## Prerequisites

- Python 3.11 or higher
- Poetry package manager
- OpenAI API Key
- Langtrace API Key

## Installation

1. Clone the repository:
```bash
git clone https://github.com/swarmzero/examples.git
cd examples/workflows/pdf_summarizer_tex_workflow
```

2. Install dependencies using Poetry:
```bash
poetry install --no-root
```

3. Set up environment variables:
Create a `.env` file in the root directory and add your API keys based on the .env.example file
## Usage

Run the workflow on a pdf like so:
``` bash
python main.py path/to/pdf/text.pdf
```

## Learn more
Visit [SwarmZero](https://swarmzero.ai) to learn more about the SwarmZero framework.
4 changes: 4 additions & 0 deletions workflows/pdf_summarizer_tex_workflow/agents/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .formatter_agent import formatter_agent
from .summarizer_agent import summarizer_agent

__all__ = ["formatter_agent", "summarizer_agent"]
20 changes: 20 additions & 0 deletions workflows/pdf_summarizer_tex_workflow/agents/formatter_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from swarmzero.agent import Agent, SDKContext
import os
from tools import format_latex

CONFIG_PATH = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
os.pardir,
"swarmzero_config.toml"
)
)
sdk_context = SDKContext(CONFIG_PATH)
formatter_agent = Agent(
name="formatter",
functions=[format_latex],
instruction="Format bullet points into LaTeX.",
description="Wraps bullets into a LaTeX itemize document.",
sdk_context=sdk_context,
chat_only_mode=True,
)
20 changes: 20 additions & 0 deletions workflows/pdf_summarizer_tex_workflow/agents/summarizer_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from swarmzero.agent import Agent, SDKContext
import os
from tools import summarize_bullets

CONFIG_PATH = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
os.pardir,
"swarmzero_config.toml"
)
)
sdk_context = SDKContext(CONFIG_PATH)
summarizer_agent = Agent(
name="summarizer",
functions=[summarize_bullets],
instruction="Summarize text into bullet points.",
description="Returns bullet-point summary for a given text chunk.",
sdk_context=sdk_context,
chat_only_mode=True,
)
66 changes: 66 additions & 0 deletions workflows/pdf_summarizer_tex_workflow/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import asyncio
import os
import sys
from typing import List

from swarmzero.sdk_context import SDKContext
from swarmzero.workflow import Workflow, WorkflowStep, StepMode

from agents import formatter_agent, summarizer_agent
from util import extract_text_from_pdf, chunk_text

CONFIG_PATH = os.path.join(os.path.dirname(__file__), "swarmzero_config.toml")
sdk_context = SDKContext(CONFIG_PATH)

async def run_summarizer(chunk: str, **kwargs) -> str:
return await summarizer_agent.chat(chunk)

async def run_formatter(bullets: str, **kwargs) -> str:
return await formatter_agent.chat(bullets)

workflow = Workflow(
name="pdf_latex_summary",
instruction="Summarize PDF and convert to LaTeX.",
description="Runs summarizer then formatter agents sequentially.",
steps=[
WorkflowStep(name="SummarizeBullets",
runner=run_summarizer,
mode=StepMode.SEQUENTIAL),

WorkflowStep(name="FormatLatex",
runner=run_formatter,
mode=StepMode.SEQUENTIAL),
],
sdk_context=sdk_context,
)

async def main():
pdf_path = sys.argv[1] if len(sys.argv) > 1 else "sample.pdf"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include a sample pdf under a new 'data' folder

text = extract_text_from_pdf(pdf_path)
chunks = chunk_text(text)

all_items: List[str] = []
for idx, chunk in enumerate(chunks, start=1):
print(f"Chunk {idx}/{len(chunks)} → processing…")
latex_doc = await workflow.run(chunk)
all_items += [line.strip() for line in latex_doc.splitlines() if line.strip().startswith("\\item")]

final = (
"\\documentclass{article}\n"
"\\usepackage[utf8]{inputenc}\n"
"\\usepackage{enumitem}\n"
"\\begin{document}\n"
"\\section*{Summary Notes}\n"
"\\begin{itemize}[leftmargin=*, label=--]\n"
+ "\n".join(all_items) +
"\n\\end{itemize}\n"
"\\end{document}"
)

out_file = os.path.splitext(os.path.basename(pdf_path))[0] + "_summary.tex"
with open(out_file, "w", encoding="utf-8") as f:
f.write(final)
print(f"Written LaTeX summary to {out_file}")

if __name__ == "__main__":
asyncio.run(main())
Loading