-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
47 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ error.txt | |
|
||
# C extensions | ||
*.so | ||
.ruff_cache | ||
|
||
|
||
errors.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,35 @@ | ||
# !pip install --upgrade swarms==2.0.6 | ||
|
||
from swarms.models import BioGPT | ||
import re | ||
from swarms.models.nougat import Nougat | ||
from swarms.structs import Flow | ||
from swarms.models import OpenAIChat | ||
from swarms.models import LayoutLMDocumentQA | ||
|
||
# # URL of the image of the financial document | ||
IMAGE_OF_FINANCIAL_DOC_URL = "bank_statement_2.jpg" | ||
|
||
# Example usage | ||
api_key = "" # Your actual API key here | ||
|
||
# Initialize the OCR model | ||
|
||
api_key = "" | ||
|
||
# Initialize the language flow | ||
llm = BioGPT() | ||
|
||
|
||
# Create a prompt for the language model | ||
def summary_agent_prompt(analyzed_doc: str): | ||
model = Nougat( | ||
max_new_tokens=5000, | ||
) | ||
|
||
out = model(analyzed_doc) | ||
|
||
return f""" | ||
Generate an actionable summary of this financial document, provide bulletpoints: | ||
llm = OpenAIChat( | ||
openai_api_key=api_key, | ||
) | ||
|
||
Here is the Analyzed Document: | ||
--- | ||
{out} | ||
""" | ||
# LayoutLM Document QA | ||
pdf_analyzer = LayoutLMDocumentQA() | ||
|
||
question = "What is the total amount of expenses?" | ||
answer = pdf_analyzer( | ||
question, | ||
IMAGE_OF_FINANCIAL_DOC_URL, | ||
) | ||
|
||
# Initialize the Flow with the language flow | ||
flow1 = Flow(llm=llm, max_loops=1, dashboard=False) | ||
|
||
# Create another Flow for a different task | ||
flow2 = Flow(llm=llm, max_loops=1, dashboard=False) | ||
|
||
agent = Flow(llm=llm) | ||
SUMMARY_AGENT_PROMPT = f""" | ||
Generate an actionable summary of this financial document be very specific and precise, provide bulletpoints be very specific provide methods of lowering expenses: {answer}" | ||
""" | ||
|
||
# Add tasks to the workflow | ||
summary_agent = flow1.run(summary_agent_prompt(IMAGE_OF_FINANCIAL_DOC_URL)) | ||
|
||
# Suppose the next task takes the output of the first task as input | ||
out = flow2.run( | ||
f"Provide an actionable step by step plan on how to cut costs from the analyzed financial document. {summary_agent}" | ||
) | ||
summary_agent = agent.run(SUMMARY_AGENT_PROMPT) | ||
print(summary_agent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters