54
38

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MarkItDownでひたすらいろんなファイルをmarkdownにしてみた

Last updated at Posted at 2024-12-16

MarkItDownという「なんでもMarkdownにしてくれるライブラリ」が話題になっています。

先日の記事にも書いたんですが、内製チャットボットでは外部ファイルをどうAIが解釈可能な文字列として読み込ませるか悩むことが多いです。

すでにQiitaにも記事はあって若干煎じなんですが、もう少し社内のユースケースにありそうなものを試してみようと思います。

先にまとめ

Unstructuredではライブラリそのものや機械学習モデルのサイズが大きいのに対して、MarkItDownでは一般的なライブラリのみです。画像や音声はOpenAI APIに頼っています。

Unstructuredを使っているとどうしてもデプロイに時間がかかったり、モデルダウンロード時の問題が発生したり困ることが多かったので。 pdfminer内でOCRモデル使っていたのでこのメリットは小さそうでした🥺

また、HTMLの構造化にも使えて、MSオフィス系はかなり理想的なmarkdownに直してくれそうです。

軽く試した限りでは、想定されるユースケースで大きな不満はありません。強いていうなら、FastAPIで利用したいのでOpenAIへの通信時にasync対応しておいてほしかったというのはあります。

ファイルをどれだけ構造化してくれるのか

pdfファイル

というわけで弊社のIR資料を入れてみます。まずは文字が多い資料。

from markitdown import MarkItDown

markitdown = MarkItDown()
result = markitdown.convert("https://lifull.com/doc/2024/11/20241114_-youshiQA-.pdf")
print(result.text_content)

結果

冒頭がこちらです。markdownっぽくはないですが、きちんと文字列として出力できてます。

株式会社 LIFULL  (2120)

2024 年9月期  決算説明会[会場とオンラインによるハイブリッド方式で開催]  質疑応答

日時・場所:

2024 年 11 月 14 日(木)  午前 11:00~12:00

次はもっとスライド風のものをやってみます。

from markitdown import MarkItDown

markitdown = MarkItDown()
result = markitdown.convert("https://lifull.com/doc/2024/11/20241128PresentationJP.pdf")
print(result.text_content)

結果

冒頭を表示します。

決算説明資料  IFRS

2024年9月期(2023年10月~2024年9月)

2024年11月28日 改訂
※2024年11月13日公表の「2024年9月期決算短信〔IFRS〕(連結)」を
訂正いたしました。本説明資料は訂正後の数値データを反映しております。

免責事項

本資料に記載された意見や予測等は資料作成時点での当社の判断であり、その情報の正確性を保証するものではありません。様々な要因の変化により実際の業績や結果とは大きく異なる可能性があることをご

承知おき下さい。また、本資料に記載されている当社及び当社グループ以外の企業に関わる情報は、公開されている情報などから引用しており、その情報の正確性などについて保証するものではありません。

Copyright (c) LIFULL Co., Ltd. All Rights Reserved.

ちなみに「You can also configure markitdown to use Large Language Models to describe images.」と言ってjpgを読み込ませる例が紹介されていて、pdfでもOCRモデルが動くことを期待したのですが結果は変わりませんでした。

from markitdown import MarkItDown
from openai import OpenAI

client = OpenAI()
markitdown = MarkItDown(mlm_client=client, mlm_model="gpt-4o")
result = markitdown.convert("https://lifull.com/doc/2024/11/20241128PresentationJP.pdf")
print(result.text_content)

HTML

というわけで弊社のニュースページ(LIFULL Tech Vietnamが「VIETNAM 100 BEST PLACES TO WORK® 2024」に選出)を取り入れてみます。

from markitdown import MarkItDown

markitdown = MarkItDown()
result = markitdown.convert("https://lifull.com/news/39889/")
print(result.text_content)

結果

冒頭がこちらです。ヘッダーが表示されてます。

[株式会社LIFULL](https://lifull.com)

* [採用サイト](https://recruit.lifull.com/)

* JAJapanese
* [ENEnglish](https://lifull.com/en/)

* 企業情報
  ![](https://lifull.com/wp-content/themes/lifull/assets/img/common/img_nav01.png)

  [1ページでわかるLIFULL](/company/onepage-lifull/)

  ![](https://lifull.com/wp-content/themes/lifull/assets/img/common/img_nav_number.png)

  [数字で見るLIFULL](/company/numbers-lifull/)

記事の本文っぽいところがこちらです。おお、ちゃんとmarkdownになってる!

2024.11.29

その他グループ会社
お知らせ・その他

# LIFULL Tech Vietnamが「VIETNAM 100 BEST PLACES TO WORK® 2024」に選出

事業を通して社会課題解決に取り組む株式会社LIFULLのグループ会社の、LIFULL Tech Vietnam Co.,Ltd(本社:ベトナム ホーチミン、代表取締役社長:加藤 雄太、以下「LIFULL Tech Vietnam」)は、Anphabeが主催する「VIETNAM 100 BEST PLACES TO WORK® 2024」において、IT/ソフトウェア・アプリケーション/eコマース業界の中規模企業ランキングで8位を獲得しました。

![](https://lifull.com/doc/2024/11/49001f9a04fbbf873bcb2b558af111ce-scaled.jpg)

### 受賞の背景

「VIETNAM 100 BEST PLACES TO WORK®」は、ベトナムにおける働きがいのある企業ランキングとして、高い信頼を得ています。2024年の調査では、全国18業界、65,000人以上の従業員と人事担当者、そして253人の有職者が参加し、700社以上を評価しました。

この度の受賞は、社員一人ひとりがプロフェッショナル意識を持ち、ダイナミックかつ一体感のある職場環境を築くことに尽力した結果です。特に、会社の理念実現と社員エンゲージメント向上に向けた取り組みが評価されました。

LIFULL Tech Vietnamでは、「Make every LIFE FULL.」というビジョンのもと、社員が働きがいを感じ、能力を最大限に発揮できる環境づくりに尽力しています。

例えば、社員のモチベーションアップにつながる報酬体系や充実した福利厚生に加え、社員一人ひとりの成長を支援する多様な研修プログラムや柔軟な働き方などを提供しています。

2017年の設立以来、LIFULL Tech Vietnamは、不動産関連アプリケーション開発や社会課題解決型のサービス開発に注力し、世界中の「LIFE」を安心と喜びで「FULL」にする革新的な取り組みを続けています。

今後も、「One Team」の精神のもと、社会に貢献できる製品やサービスの創出に邁進してまいります。

詳細は[こちら](https://vietnambestplacestowork.com/top-100-noi-lam-viec-tot-nhat-viet-nam-2024-doanh-nghiep-vua.html)からご確認ください。

### LIFULL Tech Vietnam Co., Ltdについて(<https://lifull-tech.vn/>)

この手の実装をすると、外部サイトを開くときにHTMLの大きなファイルをそのまま読み込むとtokenを大幅に使ってしまうし、ちゃんとした回答をさせるにはリンクなどの最低限の構造は残す必要があるしでけっこう悩むと思います。それが簡易な実装で済んでしまうのは助かります!

MSオフィス

GitHubリポジトリのテスト用ディレクトリにあるものを試した。きちんと読み込めていますね。

<!-- Slide number: 1 -->
# AutoGen: Enabling Next-Gen LLM Applications via Multi-Agent Conversation
Qingyun Wu , Gagan Bansal , Jieyu Zhang, Yiran Wu, Beibin Li, Erkang Zhu, Li Jiang, Xiaoyun Zhang, Shaokun Zhang, Jiale Liu, Ahmed Awadallah, Ryen W. White, Doug Burger, Chi Wang

<!-- Slide number: 2 -->
# 2cdda5c8-e50e-4db4-b5f0-9722a649f455
AutoGen is an open-source framework that allows developers to build LLM applications via multiple agents that can converse with each other to accomplish tasks. AutoGen agents are customizable, conversable, and can operate in various modes that employ combinations of LLMs, human inputs, and tools. Using AutoGen, developers can also flexibly define agent interaction behaviors. Both natural language and 04191ea8-5c73-4215-a1d3-1cfb43aaaf12 can be used to program flexible conversation patterns for different applications. AutoGen serves as a generic framework for building diverse applications of various complexities and LLM capacities. Empirical studies demonstrate the effectiveness of the framework in many example applications, with domains ranging from mathematics, coding, question answering, operations research, online decision-making, entertainment, etc.

![The first page of the AutoGen ArXiv paper.  44bf7d06-5e7a-4a40-a2e1-a2e42ef28c8a](Picture4.jpg)

<!-- Slide number: 3 -->
# A table to test parsing:

| ColA | ColB | ColC | ColD | ColE | ColF |
| --- | --- | --- | --- | --- | --- |
| 1 | 2 | 3 | 4 | 5 | 6 |
| 7 | 8 | 9 | 1b92870d-e3b5-4e65-8153-919f4ff45592 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 |

社内のパワーポイント資料でも試したんですが、かなり良いです。Notesまできちんと読み込めていますね。

<!-- Slide number: 4 -->
# まさに日進月歩・・・
ChatGPT 公式プラグイン
「Code interpreter」
 α版が終わり、7/8 より徐々に展開

Excelをアップロードすれば
・分析してくれる
・グラフも描画してくれる
・PPTも作ってくれる

![図 5](図5.jpg)
https://openai.com/blog/chatgpt-plugins

### Notes:
https://qiita.com/ot12/items/39ff4264e0f13209ba62

https://lifull.slack.com/archives/C02JZ5S4TUN/p1689061682234869

画像

こちらのサンプルのファイルを読み込んでいます。

from markitdown import MarkItDown
from openai import OpenAI

client = OpenAI()
markitdown = MarkItDown(mlm_client=client, mlm_model="gpt-4o")
# markitdown = MarkItDown()
result = markitdown.convert("https://github.com/microsoft/markitdown/blob/main/tests/test_files/test.jpg")
print(result.text_content)

中身がちゃんと構造化されて表示されますね。

[Skip to content](#start-of-content)

## Navigation Menu

Toggle navigation

[Sign in](/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fmarkitdown%2Fblob%2Fmain%2Ftests%2Ftest_files%2Ftest.jpg)

* Product

  + [GitHub Copilot
    Write better code with AI](https://github.com/features/copilot)
  + [Security
    Find and fix vulnerabilities](https://github.com/features/security)
  + [Actions
    Automate any workflow](https://github.com/features/actions)
  + [Codespaces
    Instant dev environments](https://github.com/features/codespaces)

次に、画像生成で作ったかわいい犬の画像を入れてみます。

dog.png

from markitdown import MarkItDown
from openai import OpenAI

client = OpenAI()
markitdown = MarkItDown(mlm_client=client, mlm_model="gpt-4o")
result = markitdown.convert("dog.png")
print(result.text_content)

次のようなログが表示され、

MLM Prompt:
Write a detailed caption for this image.

descriptionに変換されました。

# Description:
A playful golden retriever puppy sits eagerly on a lush, green lawn, radiating joy and energy under the warm glow of the sun. Its fluffy coat gleams, catching the sunlight, while a blue frisbee rests beneath its paws, hinting at a recent game or one about to begin. The garden backdrop bursts with vibrant flowers, adding to the idyllic scene. The sun shines brightly, casting a warm halo around the puppy, highlighting its cheerful expression and creating a picture-perfect moment of outdoor bliss.
54
38
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
54
38

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?