Professional Documents
Culture Documents
RAG Multimodal Complexe Financial Reports
RAG Multimodal Complexe Financial Reports
RAG Multimodal Complexe Financial Reports
import openai
openai.api_key = OPENAI_API_KEY
Settings.llm = Gemini(api_key=GEMINI_API_KEY)
Settings.embed_model = GeminiEmbedding(
model_name="models/embedding-001", api_key=GEMINI_API_KEY
)
1
1 PDF with charts and tables as a text: JPMorgan Annual Report
[ ]: local_path='./'
file_path = local_path + 'jpmorgan_annualreport-2022-splitted.pdf'
[ ]: text_nodes = get_text_nodes(json_list)
[ ]: text_nodes
2
file_extractor = {".pdf": parser}
documents = SimpleDirectoryReader(input_files=[file_path],␣
↪file_extractor=file_extractor).load_data()
print(documents[0].text)
| |2004|2005|2006|2007|2008|2009|2010|2011|2012|2013|2014|2015|2016|2017|2018|20
19|2020|2021|2022|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---
|
| | | | | | | | | | | | | | | |Net income| | | | | | | | | | | | | | | | | | | |
|
| | | |Diluted earnings per share (EPS)| | | | | | | | | | | | | | | | | | | | |
| | | | | | | |Return on tangible common equity (ROTCE)| | | | | | | | | | | | |
| | | | | | | |
|Adjusted ROTCE| | | | | | | | | | | | | | | | | | | | |
2 Adjusted net income excludes $2.4 billion from net income in 2017 as a result
of the enactment of the Tax Cuts and Jobs Act.
An important note to describe why we are showing the table above: The loan loss
reserve accounting rules — which are life-of-loan estimated losses based upon
probability-based economic scenarios — generate huge swings in earnings that can
be unrelated to actual credit performance. This was particularly true for the
COVID-19 years when, during the first six months of the pandemic, we built
approximately $16 billion in reserves. Then in the next six quarters, we
released essentially the equivalent number. We did so only because the scenarios
used to estimate future credit losses changed dramatically. The table above
shows reported net income, with and without loan loss reserve changes.
Throughout this period, the credit portfolio was healthy, and charge-offs
remained below pre-pandemic levels. Either way, the company had strong absolute
3
and relative performance.
---
|Tangible Book Value|Average Stock Price per Share|
|---|---|
|$155.61|2004–2022|
|$110.72|$113.80|
|$128.13| |
|$106.52| |
|High: $169.81|Low: $101.28|
|$92.01| |
|$58.17|$63.83|
|$65.62| |
|$66.11|$71.53|
|$73.12| |
|$38.70|$43.93|
|$47.75| |
|$39.83|$40.36|
|$39.36|$39.22|
|$51.88|$51.44|
|$53.56|$56.33|
|$60.98| |
|$36.07| |
|$35.49| |
|$38.68|$40.72|
|$44.60|$48.13|
|$33.62| |
|$27.09|$30.12|
|$15.35|$16.45|
|$18.88|$21.96|
|$22.52| |
4
| |Five years|7.7%|9.4%|6.4%|
| |Ten years|14.9%|12.6%|12.1%|
This chart shows actual returns of the stock, with dividends reinvested, for
heritage shareholders of Bank One and JPMorgan Chase & Co. vs. the Standard &
Poor’s 500 Index (S&P 500 Index) and the Standard & Poor’s Financials Index (S&P
Financials Index).
1 On March 27, 2000, Jamie Dimon was hired as CEO of Bank One.
1.2.2 Querying
[ ]: index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
# query the engine
query = "What is the diluted EPS value in 2021 when Reported"
response = query_engine.query(query)
print(response)
$15.36
[ ]: query = "What is the diluted EPS value in 2021 when Excluding reserve release/
↪build1"
response = query_engine.query(query)
print(response)
$12.35
9.9%
[ ]: query = "What is the Compounded annual gain or loss of the SP500 Index since␣
↪JPMorgan and Bank One have merged?"
response = query_engine.query(query)
print(response)
8.9%
[ ]: query = "What is the ten years Compounded annual gain or loss of the SP500␣
↪Financials Index?"
response = query_engine.query(query)
print(response)
12.1%
5
2 PDF as images
2.1 Save each page as an Image
[ ]: local_path='./'
file_path_image = local_path + 'jpmorgan_annualreport-2022-splitted.pdf'
[ ]: import fitz
from PIL import Image
import matplotlib.pyplot as plt
import os
output_directory_path = local_path+'images2'
# Iterate through each page and convert to an image
for page_number in range(pdf_document.page_count):
page = pdf_document[page_number]
pix = page.get_pixmap()
# Create a Pillow Image object from the pixmap
image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
# Save the image
image.save(f"{output_directory_path}/page_{page_number + 1}.png")
image_paths = []
for img_path in os.listdir(f"{output_directory_path}"):
image_paths.append(str(os.path.join(f"{output_directory_path}", img_path)))
def plot_images(image_paths):
images_shown = 0
plt.figure(figsize=(16, 9))
for img_path in image_paths:
if os.path.isfile(img_path):
image = Image.open(img_path)
plt.subplot(3, 3, images_shown + 1)
plt.imshow(image)
plt.xticks([])
6
plt.yticks([])
images_shown += 1
if images_shown >= 9:
break
plot_images(image_paths[:])
output_directory_path = local_path+'images'
# Load images as ImageDocument
documents_images_v2 = SimpleDirectoryReader(f"{output_directory_path}/").
↪load_data()
Please try your best to extract the table data from the image.
If you can't extract the table data, please summarize image and return the␣
↪summary.
"""
7
response = gemini_pro.complete(
prompt="Describe the images as an alternative text",
image_documents=documents_images_v2,
)
text_node = TextNode(
text=str(response)
)
[ ]: text_node
[ ]: TextNode(id_='0b3194b4-1f14-4538-a6f0-b652bf7e08e5', embedding=None,
metadata={}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[],
relationships={}, text=' The first image is a table that shows the earnings,
diluted earnings per share, and return on tangible common equity of Bank One
from 2004 to 2022. The second image is a graph that shows the tangible book
value and average stock price of Bank One from 2004 to 2022. The third image is
a table that shows the stock total return analysis of Bank One from 2004 to
2022.', start_char_idx=None, end_char_idx=None,
text_template='{metadata_str}\n\n{content}', metadata_template='{key}: {value}',
metadata_seperator='\n')
Please try your best to extract the charts data from the images.
If you can't extract the chart data, please summarize image and return the␣
↪summary.
"""
response2 = gemini_pro.complete(
prompt=image_prompt,
image_documents=documents_images_v2,
)
text_node = TextNode(
text=str(response2)
)
[ ]: text_node
[ ]: TextNode(id_='3ab2bfcd-05dc-4bd1-a4fe-24f930e51c64', embedding=None,
metadata={}, excluded_embed_metadata_keys=[], excluded_llm_metadata_keys=[],
relationships={}, text=' ```json\n{\n "tables": [\n {\n "title":
"Earnings, Diluted Earnings per Share and Return on Tangible Common Equity",\n
8
"headers": [\n "Reported",\n "Excluding reserve release/hold"\n
],\n "rows": [\n {\n "Net income": [\n 24.83,\n
35.93,\n 39.18,\n 53.84,\n 120.29\n
],\n "Diluted EPS": [\n 1.52,\n 2.07,\n
2.26,\n 3.02,\n 6.26\n ],\n "Return on
tangible common equity": [\n 10.2%,\n 13.5%,\n
15.5%,\n 18.9%,\n 23.2%\n ]\n }\n ]\n
},\n {\n "title": "Tangible Book Value and Average Stock Price per
Share",\n "headers": [\n "Tangible book value",\n "Average
stock price"\n ],\n "rows": [\n {\n "2004": [\n
36.07,\n 35.49\n ],\n "2005": [\n
38.70,\n 42.93\n ],\n "2006": [\n
43.75,\n 43.39\n ],\n "2007": [\n
49.36,\n 39.32\n ],\n "2008": [\n
55.83,\n 44.60\n ],\n "2009": [\n
63.83,\n 58.17\n ],\n "2010": [\n
66.62,\n 65.64\n ],\n "2011": [\n
58.18,\n 55.12\n ],\n "2012": [\n
51.88,\n 35.49\n ],\n "2013": [\n
54.06,\n 44.13\n ],\n "2014": [\n
60.98,\n 66.11\n ],\n "2015": [\n
71.53,\n 73.12\n ],\n "2016": [\n
84.13,\n 92.01\n ],\n "2017": [\n
104.52,\n 113.80\n ],\n "2018": [\n
118.34,\n 128.13\n ],\n "2019": [\n
135.35,\n 155.61\n ],\n "2020": [\n
128.13,\n 109.22\n ],\n "2021": [\n
138.62,\n 120.09\n ],\n "2022": [\n
155.61,\n 132.83\n ]\n }\n ]\n }\n ],\n
"charts": [\n {\n "title": "Earnings, Diluted Earnings per Share and
Return on Tangible Common Equity",\n "data": [\n {\n
"name": "Net income",\n "values": [\n 24.83,\n
35.93,\n 39.18,\n 53.84,\n 120.29\n
]\n },\n {\n "name": "Diluted EPS",\n "values":
[\n 1.52,\n 2.07,\n 2.26,\n 3.02,\n
6.26\n ]\n },\n {\n "name": "Return on tangible
common equity",\n "values": [\n 10.2,\n 13.5,\n
15.5,\n 18.9,\n 23.2', start_char_idx=None,
end_char_idx=None, text_template='{metadata_str}\n\n{content}',
metadata_template='{key}: {value}', metadata_seperator='\n')
[ ]: response2.text
9
35.93,\n 39.18,\n 53.84,\n 120.29\n
],\n "Diluted EPS": [\n 1.52,\n 2.07,\n
2.26,\n 3.02,\n 6.26\n ],\n "Return on
tangible common equity": [\n 10.2%,\n 13.5%,\n
15.5%,\n 18.9%,\n 23.2%\n ]\n }\n ]\n
},\n {\n "title": "Tangible Book Value and Average Stock Price per
Share",\n "headers": [\n "Tangible book value",\n "Average
stock price"\n ],\n "rows": [\n {\n "2004": [\n
36.07,\n 35.49\n ],\n "2005": [\n
38.70,\n 42.93\n ],\n "2006": [\n
43.75,\n 43.39\n ],\n "2007": [\n
49.36,\n 39.32\n ],\n "2008": [\n
55.83,\n 44.60\n ],\n "2009": [\n
63.83,\n 58.17\n ],\n "2010": [\n
66.62,\n 65.64\n ],\n "2011": [\n
58.18,\n 55.12\n ],\n "2012": [\n
51.88,\n 35.49\n ],\n "2013": [\n
54.06,\n 44.13\n ],\n "2014": [\n
60.98,\n 66.11\n ],\n "2015": [\n
71.53,\n 73.12\n ],\n "2016": [\n
84.13,\n 92.01\n ],\n "2017": [\n
104.52,\n 113.80\n ],\n "2018": [\n
118.34,\n 128.13\n ],\n "2019": [\n
135.35,\n 155.61\n ],\n "2020": [\n
128.13,\n 109.22\n ],\n "2021": [\n
138.62,\n 120.09\n ],\n "2022": [\n
155.61,\n 132.83\n ]\n }\n ]\n }\n ],\n
"charts": [\n {\n "title": "Earnings, Diluted Earnings per Share and
Return on Tangible Common Equity",\n "data": [\n {\n
"name": "Net income",\n "values": [\n 24.83,\n
35.93,\n 39.18,\n 53.84,\n 120.29\n
]\n },\n {\n "name": "Diluted EPS",\n "values":
[\n 1.52,\n 2.07,\n 2.26,\n 3.02,\n
6.26\n ]\n },\n {\n "name": "Return on tangible
common equity",\n "values": [\n 10.2,\n 13.5,\n
15.5,\n 18.9,\n 23.2'
[ ]: image_prompt = """
Please load the charts and table data from the images and output it in a␣
↪json format .
Please try your best to extract the charts data from the images.
If you can't extract the chart data, please summarize image and return the␣
↪summary.
"""
response_gemini = gemini_pro.complete(
prompt=image_prompt,
10
image_documents=documents_images_v2,
)
# text_node_gmeini = TextNode(
# text=str(response_gemini)
# )
[ ]: response_gemini.text
[ ]: response_gemini
11
[ ]: CompletionResponse(text=' ```json\n{\n "Earnings per share": [\n {\n
"year": 2004,\n "reported": 4.52,\n "excluding reserve release":
4.52\n },\n {\n "year": 2005,\n "reported": 5.06,\n
"excluding reserve release": 5.06\n },\n {\n "year": 2006,\n
"reported": 6.14,\n "excluding reserve release": 6.14\n },\n {\n
"year": 2007,\n "reported": 7.04,\n "excluding reserve release":
7.04\n },\n {\n "year": 2008,\n "reported": 16.45,\n
"excluding reserve release": 1.44\n },\n {\n "year": 2009,\n
"reported": -1.32,\n "excluding reserve release": -1.32\n },\n {\n
"year": 2010,\n "reported": 2.96,\n "excluding reserve release":
2.96\n },\n {\n "year": 2011,\n "reported": 5.26,\n
"excluding reserve release": 5.26\n },\n {\n "year": 2012,\n
"reported": 10.92,\n "excluding reserve release": 10.92\n },\n {\n
"year": 2013,\n "reported": 18.38,\n "excluding reserve release":
18.38\n },\n {\n "year": 2014,\n "reported": 21.09,\n
"excluding reserve release": 21.09\n },\n {\n "year": 2015,\n
"reported": 15.52,\n "excluding reserve release": 15.52\n },\n {\n
"year": 2016,\n "reported": 22.93,\n "excluding reserve release":
22.93\n },\n {\n "year": 2017,\n "reported": 27.09,\n
"excluding reserve release": 27.09\n },\n {\n "year": 2018,\n
"reported": 25.12,\n "excluding reserve release": 25.12\n },\n {\n
"year": 2019,\n "reported": 35.49,\n "excluding reserve release":
35.49\n },\n {\n "year": 2020,\n "reported": 21.62,\n
"excluding reserve release": 21.62\n },\n {\n "year": 2021,\n
"reported": 33.84,\n "excluding reserve release": 33.84\n },\n {\n
"year": 2022,\n "reported": 29.22,\n "excluding reserve release":
29.22\n }\n ],\n "Return on tangible common equity": [\n {\n
"year": 2004,\n "reported": 19%,\n "excluding reserve release": 19%\n
},\n {\n "year": 2005,\n "reported": 22%,\n "excluding reserve
release": 22%\n },\n {\n "year": 2006,\n "reported": 26%,\n
"excluding reserve release": 26%\n },\n {\n "year": 2007,\n
"reported": 27%,\n "excluding reserve release": 27%\n },\n {\n
"year": 2008,\n "reported": -10%,\n "excluding reserve release": 6%\n
},\n {\n "year": 2009,\n "reported": -11%,\n "excluding
reserve release": -', additional_kwargs={}, raw={'content': {'parts': [{'text':
' ```json\n{\n "Earnings per share": [\n {\n "year": 2004,\n
"reported": 4.52,\n "excluding reserve release": 4.52\n },\n {\n
"year": 2005,\n "reported": 5.06,\n "excluding reserve release":
5.06\n },\n {\n "year": 2006,\n "reported": 6.14,\n
"excluding reserve release": 6.14\n },\n {\n "year": 2007,\n
"reported": 7.04,\n "excluding reserve release": 7.04\n },\n {\n
"year": 2008,\n "reported": 16.45,\n "excluding reserve release":
1.44\n },\n {\n "year": 2009,\n "reported": -1.32,\n
"excluding reserve release": -1.32\n },\n {\n "year": 2010,\n
"reported": 2.96,\n "excluding reserve release": 2.96\n },\n {\n
"year": 2011,\n "reported": 5.26,\n "excluding reserve release":
5.26\n },\n {\n "year": 2012,\n "reported": 10.92,\n
12
"excluding reserve release": 10.92\n },\n {\n "year": 2013,\n
"reported": 18.38,\n "excluding reserve release": 18.38\n },\n {\n
"year": 2014,\n "reported": 21.09,\n "excluding reserve release":
21.09\n },\n {\n "year": 2015,\n "reported": 15.52,\n
"excluding reserve release": 15.52\n },\n {\n "year": 2016,\n
"reported": 22.93,\n "excluding reserve release": 22.93\n },\n {\n
"year": 2017,\n "reported": 27.09,\n "excluding reserve release":
27.09\n },\n {\n "year": 2018,\n "reported": 25.12,\n
"excluding reserve release": 25.12\n },\n {\n "year": 2019,\n
"reported": 35.49,\n "excluding reserve release": 35.49\n },\n {\n
"year": 2020,\n "reported": 21.62,\n "excluding reserve release":
21.62\n },\n {\n "year": 2021,\n "reported": 33.84,\n
"excluding reserve release": 33.84\n },\n {\n "year": 2022,\n
"reported": 29.22,\n "excluding reserve release": 29.22\n }\n ],\n
"Return on tangible common equity": [\n {\n "year": 2004,\n
"reported": 19%,\n "excluding reserve release": 19%\n },\n {\n
"year": 2005,\n "reported": 22%,\n "excluding reserve release": 22%\n
},\n {\n "year": 2006,\n "reported": 26%,\n "excluding reserve
release": 26%\n },\n {\n "year": 2007,\n "reported": 27%,\n
"excluding reserve release": 27%\n },\n {\n "year": 2008,\n
"reported": -10%,\n "excluding reserve release": 6%\n },\n {\n
"year": 2009,\n "reported": -11%,\n "excluding reserve release": -'}],
'role': 'model'}, 'finish_reason': 1, 'index': 0, 'safety_ratings':
[{'category': 9, 'probability': 1, 'blocked': False}, {'category': 8,
'probability': 1, 'blocked': False}, {'category': 7, 'probability': 1,
'blocked': False}, {'category': 10, 'probability': 1, 'blocked': False}],
'token_count': 0, 'grounding_attributions': [], 'block_reason': 0},
logprobs=None, delta=None)
[ ]:
output_directory_path = local_path+'images'
# Load images as ImageDocument
documents_images_v2 = SimpleDirectoryReader(f"{output_directory_path}/").
↪load_data()
Please try your best to extract the charts data from the images.
13
If you can't extract the chart data, please summarize image and return the␣
↪summary.
"""
response2 = gemini_pro.complete(
prompt=image_prompt,
image_documents=documents_images_v2,
)
text_node = TextNode(
text=str(response2)
)
[ ]: response2
14
|\n| 2009 | 11.33 B | 13.5 B | 2.76 | 3.29 |\n| 2008 | 10.67 B | 12.7 B | 2.62 |
3.12 |\n| 2007 | 16.45 B | 18.8 B | 4.03 | 4.62 |\n| 2006 | 13.57 B | 15.2 B |
3.31 | 3.73 |\n| 2005 | 11.34 B | 13.2 B | 2.79 | 3.26 |\n| 2004 | 8.53 B | 10.2
B | 2.13 | 2.56 |\n\n\n| Year | Tangible book value | Average stock price
|\n|---|---|---|\n| 2022 | 73.12 B | 67.92 |\n| 2021 | 65.62 B | 55.18 |\n| 2020
| 58.13 B | 44.10 |\n| 2019 | 51.88 B | 66.41 |\n| 2018 | 43.83 B | 71.53 |\n|
2017 | 35.98 B | 63.64 |\n| 2016 | 33.83 B | 58.23 |\n| 2015 | 32.09 B | 48.13
|\n| 2014 | 29.36 B | 40.36 |\n| 2013 | 27.09 B | 39.32 |\n| 2012 | 25.18 B |
32.12 |\n| 2011 | 22.96 B | 33.49 |\n| 2010 | 21.09 B | 27.09 |\n| 2009 | '}],
'role': 'model'}, 'finish_reason': 1, 'index': 0, 'safety_ratings':
[{'category': 9, 'probability': 1, 'blocked': False}, {'category': 8,
'probability': 1, 'blocked': False}, {'category': 7, 'probability': 1,
'blocked': False}, {'category': 10, 'probability': 1, 'blocked': False}],
'token_count': 0, 'grounding_attributions': [], 'block_reason': 0},
logprobs=None, delta=None)
2.5 GPT-4-Vision
2.5.1 Prompt1: format markdown
[ ]: image_prompt = """
Please load the charts data from the images and output it in markdown␣
↪format .
Please try your best to extract the charts data from the images.
If you can't extract the chart data, please summarize image and return the␣
↪summary.
"""
response_gpt= openai_mm_llm.complete(
prompt=image_prompt,
image_documents=documents_images_v2,
)
text_node_gpt = TextNode(
text=str(response_gpt)
)
[ ]: response_gpt
15
over the years, with a dip around 2020, which could be attributed to the
COVID-19 impact. The ROTCE also shows an upward trend with some fluctuations,
peaking in the most recent year displayed.\n\n### Image 2 Summary:\nThe second
image is another financial chart titled "Tangible Book Value and Average Stock
Price per Share" from 2004 to 2022. This chart includes two line graphs, one
representing the tangible book value per share and the other showing the average
stock price per share. Both metrics show a general upward trend over the years.
The tangible book value per share starts at around $35 in 2004 and increases to
over $80 by 2022. The average stock price per share begins at approximately $50
in 2004 and grows to over $150 by 2022, with some volatility in between.\n\nBoth
images are part of a financial analysis and are likely intended to communicate
the company\'s financial performance and growth to stakeholders.',
additional_kwargs={}, raw={'id': 'chatcmpl-93iQszYjzt8LiZeslSMlWLOADY7IN',
'choices': [Choice(finish_reason='stop', index=0, logprobs=None,
message=ChatCompletionMessage(content='I\'m unable to extract the exact
numerical data from the images to output in markdown format. However, I can
provide a summary of the content depicted in the images.\n\n### Image 1
Summary:\nThe first image appears to be a financial chart from a corporate
report, showing "Earnings, Diluted Earnings per Share and Return on Tangible
Common Equity" from 2012 to 2022. The chart is a combination of bar and line
graphs. The bar graph shows earnings in billions of dollars, while the line
graph indicates the return on tangible common equity (ROTCE) as a percentage.
The earnings are shown to be increasing over the years, with a dip around 2020,
which could be attributed to the COVID-19 impact. The ROTCE also shows an upward
trend with some fluctuations, peaking in the most recent year displayed.\n\n###
Image 2 Summary:\nThe second image is another financial chart titled "Tangible
Book Value and Average Stock Price per Share" from 2004 to 2022. This chart
includes two line graphs, one representing the tangible book value per share and
the other showing the average stock price per share. Both metrics show a general
upward trend over the years. The tangible book value per share starts at around
$35 in 2004 and increases to over $80 by 2022. The average stock price per share
begins at approximately $50 in 2004 and grows to over $150 by 2022, with some
volatility in between.\n\nBoth images are part of a financial analysis and are
likely intended to communicate the company\'s financial performance and growth
to stakeholders.', role='assistant', function_call=None, tool_calls=None))],
'created': 1710672810, 'model': 'gpt-4-1106-vision-preview', 'object':
'chat.completion', 'system_fingerprint': None, 'usage':
CompletionUsage(completion_tokens=326, prompt_tokens=226, total_tokens=552)},
logprobs=None, delta=None)
[ ]: print(response_gpt.text)
I'm unable to extract the exact numerical data from the images to output in
markdown format. However, I can provide a summary of the content depicted in the
images.
16
The first image appears to be a financial chart from a corporate report, showing
"Earnings, Diluted Earnings per Share and Return on Tangible Common Equity" from
2012 to 2022. The chart is a combination of bar and line graphs. The bar graph
shows earnings in billions of dollars, while the line graph indicates the return
on tangible common equity (ROTCE) as a percentage. The earnings are shown to be
increasing over the years, with a dip around 2020, which could be attributed to
the COVID-19 impact. The ROTCE also shows an upward trend with some
fluctuations, peaking in the most recent year displayed.
Both images are part of a financial analysis and are likely intended to
communicate the company's financial performance and growth to stakeholders.
[ ]: # I'm unable to extract the exact numerical data from the images to output in␣
↪markdown format. However, I can provide a summary of the content depicted in␣
↪the images.
# The earnings are shown to be increasing over the years, with a dip around␣
↪2020, which could be attributed to the COVID-19 impact.
# The ROTCE also shows an upward trend with some fluctuations, peaking in the␣
↪most recent year displayed.
# This chart includes two line graphs, one representing the tangible book value␣
↪per share and the other showing the average stock price per share.
# Both metrics show a general upward trend over the years. The tangible book␣
↪value per share starts at around $35 in 2004 and increases to over $80 by␣
↪2022.
17
# The average stock price per share begins at approximately $50 in 2004 and␣
↪grows to over $150 by 2022, with some volatility in between.
# Both images are part of a financial analysis and are likely intended to␣
↪communicate the company's financial performance and growth to stakeholders.
[ ]: image_prompt = """
Please load the charts data from the images and output it in markdown␣
↪format .
Please try your best to extract the charts data from the images.
If you can't extract the chart data, please summarize image and return the␣
↪summary.
"""
response_gpt2= openai_mm_llm.complete(
prompt=image_prompt,
image_documents=documents_images_v2,
)
[ ]: response_gpt2
18
raw={'id': 'chatcmpl-93iYC1g3XesZcyYMbiqgMIAufPWmI', 'choices':
[Choice(finish_reason='stop', index=0, logprobs=None,
message=ChatCompletionMessage(content="I'm sorry, but I'm unable to extract
specific chart data from images. However, I can provide a summary of the content
depicted in the images.\n\nThe first image appears to be a financial chart
showing Earnings, Diluted Earnings per Share, and Return on Tangible Common
Equity (ROTCE) from 2012 to 2022. The chart is divided into three sections, each
representing a different metric. The top section shows net income in billions,
the middle section shows diluted earnings per share, and the bottom section
shows ROTCE percentages. The chart includes blue and white bars, with the blue
bars representing the actual figures and the white bars possibly representing
adjusted figures or projections. There are also annotations on the chart that
provide additional context or explanations for certain years' figures.\n\nThe
second image is another financial chart that presents the Tangible Book Value
and Average Stock Price per Share from 2004 to 2022. The chart shows two lines:
one for the tangible book value per share and another for the average stock
price. The chart indicates a general upward trend in both metrics over the
years.\n\nRegarding the specific question about the percentage of the Return on
Tangible Common Equity (ROTCE) in 2012, the chart in the first image should
contain this information. However, due to the limitations of my current
capabilities, I cannot extract the exact percentage from the image. To obtain
this information, you would need to refer to the source of the financial data or
the original document from which the image was taken.", role='assistant',
function_call=None, tool_calls=None))], 'created': 1710673264, 'model':
'gpt-4-1106-vision-preview', 'object': 'chat.completion', 'system_fingerprint':
None, 'usage': CompletionUsage(completion_tokens=307, prompt_tokens=257,
total_tokens=564)}, logprobs=None, delta=None)
[ ]: image_prompt = """
Please load the charts data from the images and output it in a json format .
Please try your best to extract the charts data from the images.
If you can't extract the chart data, please summarize image and return the␣
↪summary.
"""
response_gpt3= openai_mm_llm.complete(
prompt=image_prompt,
image_documents=documents_images_v2,
)
response_gpt3
19
[ ]: CompletionResponse(text='I\'m sorry, but I\'m unable to directly extract data
from images or convert them into a JSON format. However, I can provide a summary
of the images you\'ve provided.\n\nThe first image appears to be a financial
chart showing "Earnings, Diluted Earnings per Share and Return on Tangible
Common Equity (ROTCE)" from 2012 to 2022. The chart includes bar graphs and line
graphs that represent various financial metrics such as net income, diluted EPS
(earnings per share), and ROTCE. The specific percentage value for ROTCE in 2012
is not clearly visible in the image provided, so I cannot accurately report that
figure.\n\nThe second image is another financial chart titled "Tangible Book
Value and Average Stock Price per Share" from 2004 to 2022. It shows the growth
of tangible book value and average stock price over the years with a line graph.
The chart also includes a "stock total return analysis" comparing the
performance of the company\'s stock with the S&P 500 Financials Index and the
S&P 500 Index over different time periods.\n\nTo answer your question about the
percentage of the return on tangible common equity (ROTCE) in 2012, I would need
a clearer image or additional data as the specific percentage is not discernible
from the image provided. If you have the data in text form or can provide a
clearer image, I could attempt to give you the specific figure.',
additional_kwargs={}, raw={'id': 'chatcmpl-93jneFyrlcHrNxCwACaWD6IIr6JSg',
'choices': [Choice(finish_reason='stop', index=0, logprobs=None,
message=ChatCompletionMessage(content='I\'m sorry, but I\'m unable to directly
extract data from images or convert them into a JSON format. However, I can
provide a summary of the images you\'ve provided.\n\nThe first image appears to
be a financial chart showing "Earnings, Diluted Earnings per Share and Return on
Tangible Common Equity (ROTCE)" from 2012 to 2022. The chart includes bar graphs
and line graphs that represent various financial metrics such as net income,
diluted EPS (earnings per share), and ROTCE. The specific percentage value for
ROTCE in 2012 is not clearly visible in the image provided, so I cannot
accurately report that figure.\n\nThe second image is another financial chart
titled "Tangible Book Value and Average Stock Price per Share" from 2004 to
2022. It shows the growth of tangible book value and average stock price over
the years with a line graph. The chart also includes a "stock total return
analysis" comparing the performance of the company\'s stock with the S&P 500
Financials Index and the S&P 500 Index over different time periods.\n\nTo answer
your question about the percentage of the return on tangible common equity
(ROTCE) in 2012, I would need a clearer image or additional data as the specific
percentage is not discernible from the image provided. If you have the data in
text form or can provide a clearer image, I could attempt to give you the
specific figure.', role='assistant', function_call=None, tool_calls=None))],
'created': 1710678066, 'model': 'gpt-4-1106-vision-preview', 'object':
'chat.completion', 'system_fingerprint': None, 'usage':
CompletionUsage(completion_tokens=293, prompt_tokens=258, total_tokens=551)},
logprobs=None, delta=None)
20
[2]: from PIL import Image
import matplotlib.pyplot as plt
import os
image = Image.open(img_path)
plt.imshow(image)
output_directory_path = local_path+'images2'
# Load images as ImageDocument
documents_images_v3 = SimpleDirectoryReader(f"{output_directory_path}/").
↪load_data()
[ ]: image_prompt = """
Please load the charts data from the images and output it in a json format .
Please try your best to extract the charts data from the images.
21
If you can't extract the chart data, please summarize image and return the␣
↪summary.
Additionnaly, answer to this question: What was the percentage of the␣
↪return on tangible common equity (ROTCE) in in 2012"
"""
response_gpt4= openai_mm_llm.complete(
prompt=image_prompt,
image_documents=documents_images_v3,
)
# text_node_gpt = TextNode(
# text=str(response_gpt)
# )
response_gpt4
22
chart includes a note that the financial results from 2005-2007 have been
revised due to the adoption of the 2010 GAAP financial measures.\n\nRegarding
the specific question about the percentage of the Return on Tangible Common
Equity (ROTCE) in 2012, the image shows that the reported ROTCE was
approximately 14%, and the adjusted ROTCE (excluding notable items) was slightly
higher, around 15%. Please note that these percentages are estimated based on
the visual representation in the chart, as I cannot extract the exact numerical
values.", role='assistant', function_call=None, tool_calls=None))], 'created':
1710678391, 'model': 'gpt-4-1106-vision-preview', 'object': 'chat.completion',
'system_fingerprint': None, 'usage': CompletionUsage(completion_tokens=288,
prompt_tokens=173, total_tokens=461)}, logprobs=None, delta=None)
[ ]: # Regarding the specific question about the percentage of the Return on␣
↪Tangible Common Equity (ROTCE) in 2012, the image shows that the reported␣
↪ROTCE was approximately 14%, and the adjusted ROTCE (excluding notable␣
[ ]: image_prompt = """
Please load the charts data from the images and output it in a json format .
Please try your best to extract the charts data from the images.
If you can't extract the chart data, please summarize image and return the␣
↪summary.
"""
response_gpt4= openai_mm_llm.complete(
prompt=image_prompt,
image_documents=documents_images_v3,
)
# text_node_gpt = TextNode(
# text=str(response_gpt)
# )
response_gpt4
23
fluctuate year over year, with some years showing significant increases and
others showing decreases.\n\nRegarding your specific question about the
percentage of the Return on Tangible Common Equity (ROTCE) in 2011, the chart
indicates that the ROTCE for that year is approximately 10%. Please note that
this is an estimation based on the visual representation in the chart, and the
exact figure should be verified with the original data source.',
additional_kwargs={}, raw={'id': 'chatcmpl-93jvQ0s0dcgUylFx1HBXgq4IzxuHV',
'choices': [Choice(finish_reason='stop', index=0, logprobs=None,
message=ChatCompletionMessage(content='The image you\'ve provided appears to be
a complex financial chart titled "Earnings, Diluted Earnings per Share and
Return on Tangible Common Equity (in billions, except per share and ratio data)"
covering the years 2004-2022. The chart includes several data points such as Net
Income, Adjusted Net Income, Diluted EPS, Adjusted Diluted EPS, ROTCE, and
Adjusted ROTCE.\n\nUnfortunately, I\'m unable to extract the exact numerical
data from the image to convert it into JSON format. However, I can provide a
summary of the visual information:\n\n- The chart shows a general upward trend
in both net income and adjusted net income over the years, with some
fluctuations.\n- Diluted EPS and Adjusted Diluted EPS also generally increase
over the period, with some years showing declines.\n- ROTCE and Adjusted ROTCE
percentages fluctuate year over year, with some years showing significant
increases and others showing decreases.\n\nRegarding your specific question
about the percentage of the Return on Tangible Common Equity (ROTCE) in 2011,
the chart indicates that the ROTCE for that year is approximately 10%. Please
note that this is an estimation based on the visual representation in the chart,
and the exact figure should be verified with the original data source.',
role='assistant', function_call=None, tool_calls=None))], 'created': 1710678548,
'model': 'gpt-4-1106-vision-preview', 'object': 'chat.completion',
'system_fingerprint': None, 'usage': CompletionUsage(completion_tokens=260,
prompt_tokens=173, total_tokens=433)}, logprobs=None, delta=None)
[ ]: # Regarding your specific question about the percentage of the Return on␣
↪Tangible Common Equity (ROTCE) in 2011, the chart indicates that the ROTCE␣
# Please note that this is an estimation based on the visual representation in␣
↪the chart, and the exact figure should be verified with the original data␣
↪source.
[ ]: image_prompt = """
Please load the charts data from the images and output it in a json format .
Please try your best to extract the charts data from the images.
If you can't extract the chart data, please summarize image and return the␣
↪summary.
"""
response_gpt5= openai_mm_llm.complete(
24
prompt=image_prompt,
image_documents=documents_images_v3,
)
response_gpt5
[ ]: # Regarding the specific question about the percentage of the Return on␣
↪Tangible Common Equity (ROTCE) in 2006, the chart shows that the ROTCE was␣
↪approximately 20%.
# Please note that the exact values cannot be determined from the image, and␣
↪the ROTCE percentage for 2006 is an estimate based on the visual␣
25