parent
4af1cb42fe
commit
cc96496754
@ -1,50 +1,35 @@
|
|||||||
# !pip install --upgrade swarms==2.0.6
|
import re
|
||||||
|
|
||||||
from swarms.models import BioGPT
|
|
||||||
from swarms.models.nougat import Nougat
|
from swarms.models.nougat import Nougat
|
||||||
from swarms.structs import Flow
|
from swarms.structs import Flow
|
||||||
|
from swarms.models import OpenAIChat
|
||||||
|
from swarms.models import LayoutLMDocumentQA
|
||||||
|
|
||||||
# # URL of the image of the financial document
|
# # URL of the image of the financial document
|
||||||
IMAGE_OF_FINANCIAL_DOC_URL = "bank_statement_2.jpg"
|
IMAGE_OF_FINANCIAL_DOC_URL = "bank_statement_2.jpg"
|
||||||
|
|
||||||
# Example usage
|
# Example usage
|
||||||
api_key = "" # Your actual API key here
|
api_key = ""
|
||||||
|
|
||||||
# Initialize the OCR model
|
|
||||||
|
|
||||||
|
|
||||||
# Initialize the language flow
|
# Initialize the language flow
|
||||||
llm = BioGPT()
|
llm = OpenAIChat(
|
||||||
|
openai_api_key=api_key,
|
||||||
|
)
|
||||||
# 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:
|
|
||||||
|
|
||||||
Here is the Analyzed Document:
|
# LayoutLM Document QA
|
||||||
---
|
pdf_analyzer = LayoutLMDocumentQA()
|
||||||
{out}
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
question = "What is the total amount of expenses?"
|
||||||
|
answer = pdf_analyzer(
|
||||||
|
question,
|
||||||
|
IMAGE_OF_FINANCIAL_DOC_URL,
|
||||||
|
)
|
||||||
|
|
||||||
# Initialize the Flow with the language flow
|
# Initialize the Flow with the language flow
|
||||||
flow1 = Flow(llm=llm, max_loops=1, dashboard=False)
|
agent = Flow(llm=llm)
|
||||||
|
SUMMARY_AGENT_PROMPT = f"""
|
||||||
# Create another Flow for a different task
|
Generate an actionable summary of this financial document be very specific and precise, provide bulletpoints be very specific provide methods of lowering expenses: {answer}"
|
||||||
flow2 = Flow(llm=llm, max_loops=1, dashboard=False)
|
"""
|
||||||
|
|
||||||
|
|
||||||
# Add tasks to the workflow
|
# Add tasks to the workflow
|
||||||
summary_agent = flow1.run(summary_agent_prompt(IMAGE_OF_FINANCIAL_DOC_URL))
|
summary_agent = agent.run(SUMMARY_AGENT_PROMPT)
|
||||||
|
print(summary_agent)
|
||||||
# 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}"
|
|
||||||
)
|
|
||||||
|
Loading…
Reference in new issue