Deplot 阅读器演示¶
在这个 notebook 中,我们展示了 ImageTabularChartReader 的功能,它由 DePlot 模型提供支持 https://arxiv.org/abs/2212.10505。
In [ ]
已复制!
%pip install llama-index-readers-file
%pip install llama-index-readers-file
In [ ]
已复制!
from llama_index.readers.file import ImageTabularChartReader
from llama_index.core import SummaryIndex
from llama_index.core.response.notebook_utils import display_response
from pathlib import Path
from llama_index.readers.file import ImageTabularChartReader from llama_index.core import SummaryIndex from llama_index.core.response.notebook_utils import display_response from pathlib import Path
In [ ]
已复制!
loader = ImageTabularChartReader(keep_image=True)
loader = ImageTabularChartReader(keep_image=True)
加载受保护水域图表¶
此图表显示了每个国家受保护海洋领海的百分比。
In [ ]
已复制!
documents = loader.load_data(file=Path("./marine_chart.png"))
documents = loader.load_data(file=Path("./marine_chart.png"))
In [ ]
已复制!
print(documents[0].text)
print(documents[0].text)
Figure or chart with tabular data: Country | Share of marine territorial waters that are protected, 2016 <0x0A> Greenland | 4.52 <0x0A> Mauritania | 4.15 <0x0A> Indonesia | 2.88 <0x0A> Ireland | 2.33
In [ ]
已复制!
summary_index = SummaryIndex.from_documents(documents)
response = summary_index.as_query_engine().query(
"What is the difference between the shares of Greenland and the share of"
" Mauritania?"
)
summary_index = SummaryIndex.from_documents(documents) response = summary_index.as_query_engine().query( "What is the difference between the shares of Greenland and the share of" " Mauritania?" )
Retrying langchain.llms.openai.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised APIConnectionError: Error communicating with OpenAI: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')).
In [ ]
已复制!
display_response(response, show_source=True)
display_response(response, show_source=True)
加载皮尤研究图表¶
这里我们加载一个皮尤研究图表,显示国际上对美国/拜登的看法。
来源:https://www.pewresearch.org/global/2023/06/27/international-views-of-biden-and-u-s-largely-positive/
In [ ]
已复制!
documents = loader.load_data(file=Path("./pew1.png"))
documents = loader.load_data(file=Path("./pew1.png"))
In [ ]
已复制!
print(documents[0].text)
print(documents[0].text)
Figure or chart with tabular data: Entity | Values <0x0A> Does not | 50.0 <0x0A> % who say the U.S take into account the interests of countries like theirs | 49.0 <0x0A> Does not | 38.0 <0x0A> % who say the U.S contribute to peace and stability around the world | 61.0 <0x0A> Does not | 15.0 <0x0A> % who say the U.S interfere in the affairs of other countries | 15.0 <0x0A>% who have confidence | 54.0 <0x0A> Views of President Biden | 30.0 <0x0A> Favorable | 59.0 <0x0A> Views of the U.S. | 9.0
In [ ]
已复制!
summary_index = SummaryIndex.from_documents(documents)
response = summary_index.as_query_engine().query(
"What percentage says that the US contributes to peace and stability?"
)
summary_index = SummaryIndex.from_documents(documents) response = summary_index.as_query_engine().query( "What percentage says that the US contributes to peace and stability?" )
In [ ]
已复制!
display_response(response, show_source=True)
display_response(response, show_source=True)