Skip to content

myhency/markitdown-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MarkItDown File Converter Server

Microsoft์˜ MarkItDown ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์–‘ํ•œ ํŒŒ์ผ ํ˜•์‹์„ Markdown์œผ๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ๋Š” Python Flask ์„œ๋ฒ„์ž…๋‹ˆ๋‹ค.

๐Ÿ“‹ ๋ชฉ์ฐจ

๐Ÿ—๏ธ ์•„ํ‚คํ…์ฒ˜

์ด ํ”„๋กœ์ ํŠธ๋Š” Feature-based Hexagonal Architecture๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค:

  • src/features/: ๊ธฐ๋Šฅ๋ณ„๋กœ ๊ตฌ์„ฑ๋œ ๋ชจ๋“ˆ๋“ค
    • file_conversion/: ์ผ๋ฐ˜ ํŒŒ์ผ ๋ณ€ํ™˜ ๊ธฐ๋Šฅ
    • image_conversion/: ์ด๋ฏธ์ง€ AI ๋ณ€ํ™˜ ๊ธฐ๋Šฅ
    • ai_conversion/: ๋ฌธ์„œ์˜ AI ๋ณ€ํ™˜ ๊ธฐ๋Šฅ
    • health/: ํ—ฌ์Šค์ฒดํฌ ๊ธฐ๋Šฅ
  • src/shared/: ๊ณตํ†ต ๊ธฐ๋Šฅ (์„ค์ •, ์œ ํ‹ธ๋ฆฌํ‹ฐ, ๊ณตํ†ต ๋ชจ๋ธ)
  • src/web/: ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํŒฉํ† ๋ฆฌ ๋ฐ ์˜์กด์„ฑ ์ฃผ์ž…

๊ฐ ๊ธฐ๋Šฅ์€ ๋…๋ฆฝ์ ์ธ application, domain, infrastructure ๋ ˆ์ด์–ด๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค.

๐Ÿš€ ์ฃผ์š” ๊ธฐ๋Šฅ

  • ๋‹ค์–‘ํ•œ ํŒŒ์ผ ํ˜•์‹ ์ง€์›: Office ๋ฌธ์„œ, PDF, ์ด๋ฏธ์ง€, ์˜ค๋””์˜ค, ํ…์ŠคํŠธ ํŒŒ์ผ ๋“ฑ
  • REST API: ๊ฐ„๋‹จํ•œ HTTP POST ์š”์ฒญ์œผ๋กœ ํŒŒ์ผ ๋ณ€ํ™˜
  • ๋‘ ๊ฐ€์ง€ ์‘๋‹ต ํ˜•์‹: JSON ๋˜๋Š” ์ˆœ์ˆ˜ ํ…์ŠคํŠธ
  • ์‹ค์‹œ๊ฐ„ ์ŠคํŠธ๋ฆฌ๋ฐ: SSE(Server-Sent Events)๋ฅผ ํ†ตํ•œ ์‹ค์‹œ๊ฐ„ ์ง„ํ–‰์ƒํ™ฉ ๋ฐ AI ์‘๋‹ต ์ŠคํŠธ๋ฆฌ๋ฐ
  • ๋งˆํฌ๋‹ค์šด ๊ตฌ์กฐ ๊ฐœ์„ : ํ…์ŠคํŠธ๋ฅผ ๋” ์ฝ๊ธฐ ์ข‹์€ ๋งˆํฌ๋‹ค์šด์œผ๋กœ ํ›„์ฒ˜๋ฆฌ
  • AI ์ด๋ฏธ์ง€ ์„ค๋ช…: Azure OpenAI๋ฅผ ์‚ฌ์šฉํ•œ ์ด๋ฏธ์ง€ ๋‚ด์šฉ ๋ถ„์„ ๋ฐ ๋งˆํฌ๋‹ค์šด ๋ณ€ํ™˜
  • ์—๋Ÿฌ ์ฒ˜๋ฆฌ: ์ž์„ธํ•œ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€์™€ ์ƒํƒœ ์ฝ”๋“œ
  • Docker ์ง€์›: ์ปจํ…Œ์ด๋„ˆํ™”๋œ ๋ฐฐํฌ

๐Ÿ“ ์ง€์›ํ•˜๋Š” ํŒŒ์ผ ํ˜•์‹

  • Office ๋ฌธ์„œ: .docx, .doc, .pptx, .ppt, .xlsx, .xls
  • PDF: .pdf
  • ์ด๋ฏธ์ง€: .jpg, .jpeg, .png, .gif, .bmp, .tiff, .webp
  • ์˜ค๋””์˜ค: .wav, .mp3
  • ํ…์ŠคํŠธ: .txt, .csv, .json, .xml, .html, .htm
  • ์•„์นด์ด๋ธŒ: .zip
  • ์ „์ž์ฑ…: .epub
  • Outlook: .msg

๐Ÿ› ๏ธ ์„ค์น˜ ๋ฐ ์‹คํ–‰

๋กœ์ปฌ ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰

  1. ์ €์žฅ์†Œ ํด๋ก  ๋ฐ ์˜์กด์„ฑ ์„ค์น˜
git clone <repository-url>
cd markitdown-server
pip install -r requirements.txt
  1. ์„œ๋ฒ„ ์‹คํ–‰
python main.py

์„œ๋ฒ„๊ฐ€ http://localhost:5001์—์„œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

Docker๋ฅผ ์‚ฌ์šฉํ•œ ์‹คํ–‰

  1. Docker ์ด๋ฏธ์ง€ ๋นŒ๋“œ
docker build -t markitdown-server .
  1. ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰
docker run -p 5001:5001 markitdown-server

๐Ÿ“– API ์‚ฌ์šฉ๋ฒ•

1. ์„œ๋ฒ„ ์ƒํƒœ ํ™•์ธ

curl http://localhost:5001/health

2. ์„œ๋ฒ„ ์ •๋ณด ๋ฐ ์ง€์› ํ˜•์‹ ํ™•์ธ

curl http://localhost:5001/

3. ํŒŒ์ผ ๋ณ€ํ™˜

JSON ํ˜•์‹์œผ๋กœ ์‘๋‹ต๋ฐ›๊ธฐ (๊ธฐ๋ณธ๊ฐ’, ๋งˆํฌ๋‹ค์šด ๊ตฌ์กฐ ๊ฐœ์„  ์ ์šฉ)

curl -X POST \
  -F "file=@example.pdf" \
  -F "format=json" \
  -F "enhance_markdown=true" \
  http://localhost:5001/convert

4. ์ด๋ฏธ์ง€ ๋ณ€ํ™˜ (Azure OpenAI)

์ „ํ†ต์ ์ธ REST API

curl -X POST \
  -F "file=@example.jpg" \
  -F "azure_endpoint=https://your-resource.openai.azure.com" \
  -F "api_key=your-api-key" \
  -F "deployment_name=gpt-4o" \
  -F "api_version=2024-10-21" \
  -F "enhance_markdown=true" \
  http://localhost:5001/convert-image

SSE ์ŠคํŠธ๋ฆฌ๋ฐ API (์‹ค์‹œ๊ฐ„ AI ์‘๋‹ต)

curl -N -X POST \
  -F "file=@example.jpg" \
  -F "azure_endpoint=https://your-resource.openai.azure.com" \
  -F "api_key=your-api-key" \
  -F "deployment_name=gpt-4o" \
  -F "api_version=2024-10-21" \
  -F "enhance_markdown=true" \
  http://localhost:5001/convert-image/stream

SSE ์ด๋ฒคํŠธ ํƒ€์ž…:

  • connection: ์—ฐ๊ฒฐ ํ™•๋ฆฝ
  • progress: ์ง„ํ–‰์ƒํ™ฉ ์—…๋ฐ์ดํŠธ
  • ai_chunk: ์‹ค์‹œ๊ฐ„ AI ์‘๋‹ต ์ฒญํฌ
  • result: ์ตœ์ข… ๊ฒฐ๊ณผ
  • error: ์˜ค๋ฅ˜ ๋ฐœ์ƒ

โšก Quick Start Examples

1. ์„œ๋ฒ„ ์ƒํƒœ ํ™•์ธ

# ์„œ๋ฒ„๊ฐ€ ์‹คํ–‰ ์ค‘์ธ์ง€ ํ™•์ธ
curl http://localhost:5001/health

# ์ง€์›ํ•˜๋Š” ํŒŒ์ผ ํ˜•์‹๊ณผ ๋ชจ๋“  ์—”๋“œํฌ์ธํŠธ ์ •๋ณด ํ™•์ธ
curl http://localhost:5001/

2. ๊ฐ„๋‹จํ•œ ํŒŒ์ผ ๋ณ€ํ™˜

# PDF๋ฅผ ๋งˆํฌ๋‹ค์šด์œผ๋กœ ๋ณ€ํ™˜ (๊ตฌ์กฐํ™” ์ ์šฉ)
curl -X POST \
  -F "file=@example.pdf" \
  http://localhost:5001/convert

# ์›๋ณธ ํ…์ŠคํŠธ๋งŒ ๋ณ€ํ™˜ (๊ตฌ์กฐํ™” ์—†์ด)
curl -X POST \
  -F "file=@example.pdf" \
  -F "enhance_markdown=false" \
  http://localhost:5001/convert

# ํ…์ŠคํŠธ ํŒŒ์ผ๋กœ ์‘๋‹ต๋ฐ›๊ธฐ
curl -X POST \
  -F "file=@example.pdf" \
  -F "format=text" \
  http://localhost:5001/convert

3. AI ์ด๋ฏธ์ง€ ๋ถ„์„ (Azure OpenAI ํ•„์š”)

# ์ „ํ†ต์ ์ธ REST API
curl -X POST \
  -F "file=@screenshot.png" \
  -F "azure_endpoint=https://your-resource.openai.azure.com" \
  -F "api_key=your-api-key" \
  -F "deployment_name=gpt-4o" \
  http://localhost:5001/convert-image

# ์‹ค์‹œ๊ฐ„ ์ŠคํŠธ๋ฆฌ๋ฐ (์ง„ํ–‰์ƒํ™ฉ๊ณผ AI ์‘๋‹ต์„ ์‹ค์‹œ๊ฐ„์œผ๋กœ ํ™•์ธ)
curl -N -X POST \
  -F "file=@screenshot.png" \
  -F "azure_endpoint=https://your-resource.openai.azure.com" \
  -F "api_key=your-api-key" \
  -F "deployment_name=gpt-4o" \
  http://localhost:5001/convert-image/stream

4. AI ๋ฌธ์„œ ๋ถ„์„ (Azure OpenAI ํ•„์š”)

# ๋ฌธ์„œ๋ฅผ ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜ํ•œ ํ›„ AI๋กœ ๋ถ„์„
curl -X POST \
  -F "file=@presentation.pptx" \
  -F "azure_endpoint=https://your-resource.openai.azure.com" \
  -F "api_key=your-api-key" \
  -F "deployment_name=gpt-4o" \
  -F "dpi=300" \
  http://localhost:5001/convert_with_ai

# ์‹ค์‹œ๊ฐ„ ์ŠคํŠธ๋ฆฌ๋ฐ์œผ๋กœ ๊ฐ ํŽ˜์ด์ง€ ๋ถ„์„ ๊ณผ์ • ํ™•์ธ
curl -N -X POST \
  -F "file=@presentation.pptx" \
  -F "azure_endpoint=https://your-resource.openai.azure.com" \
  -F "api_key=your-api-key" \
  -F "deployment_name=gpt-4o" \
  -F "dpi=300" \
  http://localhost:5001/convert_with_ai/stream

5. ํŒŒ์ผ ํƒ€์ž…๋ณ„ ์ตœ์  ์„ ํƒ

ํŒŒ์ผ ํƒ€์ž… ๊ถŒ์žฅ ์—”๋“œํฌ์ธํŠธ ์ด์œ 
ํ…์ŠคํŠธ ํŒŒ์ผ (.txt, .csv, .json) /convert ๋น ๋ฅด๊ณ  ์ •ํ™•ํ•œ ์ผ๋ฐ˜ ๋ณ€ํ™˜
Office ๋ฌธ์„œ (.docx, .pptx, .xlsx) /convert ๋˜๋Š” /convert_with_ai ์ผ๋ฐ˜ ๋ณ€ํ™˜์œผ๋กœ ์ถฉ๋ถ„ํ•˜๋‚˜, ๋ณต์žกํ•œ ๋ ˆ์ด์•„์›ƒ์€ AI ๋ถ„์„ ๊ถŒ์žฅ
PDF /convert ๋˜๋Š” /convert_with_ai ํ…์ŠคํŠธ ๊ธฐ๋ฐ˜ PDF๋Š” ์ผ๋ฐ˜ ๋ณ€ํ™˜, ์ด๋ฏธ์ง€/ํ‘œ ์ค‘์‹ฌ์€ AI ๋ถ„์„
์ด๋ฏธ์ง€ (.jpg, .png) /convert-image ์ด๋ฏธ์ง€ ๋‚ด์šฉ ๋ถ„์„ ํ•„์š”
๋ณต์žกํ•œ ๋ฌธ์„œ /convert_with_ai/stream ์‹ค์‹œ๊ฐ„ ์ง„ํ–‰์ƒํ™ฉ ํ™•์ธ ๊ฐ€๋Šฅ

์›๋ณธ ํ…์ŠคํŠธ๋งŒ (๋งˆํฌ๋‹ค์šด ๊ตฌ์กฐํ™” ์—†์ด)

curl -X POST \
  -F "file=@example.pdf" \
  -F "format=json" \
  -F "enhance_markdown=false" \
  http://localhost:5001/convert

์‘๋‹ต ์˜ˆ์‹œ:

{
    "success": true,
    "markdown": "# ๋ฌธ์„œ ์ œ๋ชฉ\n\n**์ค‘์š” ์ •๋ณด**: ๋‚ด์šฉ...",
    "original_markdown": "๋ฌธ์„œ ์ œ๋ชฉ\n\n์ค‘์š” ์ •๋ณด: ๋‚ด์šฉ...",
    "file_info": {
        "filename": "example.pdf",
        "extension": ".pdf",
        "mimetype": "application/pdf",
        "supported": true
    },
    "processing_info": {
        "enhanced": true
    },
    "metadata": {
        "original_filename": "example.pdf",
        "converted_size": 1456,
        "original_size": 1234,
        "title": "๋ฌธ์„œ ์ œ๋ชฉ"
    }
}

์ˆœ์ˆ˜ ํ…์ŠคํŠธ๋กœ ์‘๋‹ต๋ฐ›๊ธฐ

curl -X POST \
  -F "file=@example.pdf" \
  -F "format=text" \
  http://localhost:5001/convert

๐Ÿ Python ํด๋ผ์ด์–ธํŠธ ์˜ˆ์ œ

์ผ๋ฐ˜ ํŒŒ์ผ ๋ณ€ํ™˜

import requests

# ํŒŒ์ผ ๋ณ€ํ™˜ (๋งˆํฌ๋‹ค์šด ๊ตฌ์กฐ ๊ฐœ์„  ์ ์šฉ)
with open('example.pdf', 'rb') as file:
    files = {'file': ('example.pdf', file)}
    data = {'format': 'json', 'enhance_markdown': 'true'}

    response = requests.post('http://localhost:5001/convert',
                           files=files, data=data)

    if response.status_code == 200:
        result = response.json()
        enhanced_markdown = result['markdown']
        original_markdown = result['original_markdown']
        print("Enhanced:", enhanced_markdown)
        print("Original:", original_markdown)
    else:
        print(f"Error: {response.json()}")

์ด๋ฏธ์ง€ ๋ณ€ํ™˜ (Azure OpenAI ์‚ฌ์šฉ)

์ „ํ†ต์ ์ธ REST API ๋ฐฉ์‹

import requests

# ์ด๋ฏธ์ง€๋ฅผ LLM์œผ๋กœ ๋ถ„์„ํ•˜์—ฌ ๋งˆํฌ๋‹ค์šด ๋ณ€ํ™˜
with open('example.jpg', 'rb') as file:
    files = {'file': ('example.jpg', file)}
    data = {
        'azure_endpoint': 'https://your-resource.openai.azure.com/',
        'api_key': 'your-api-key',
        'deployment_name': 'gpt-4o',
        'api_version': '2024-10-21',
        'enhance_markdown': 'true'
    }

    response = requests.post('http://localhost:5001/convert-image',
                           files=files, data=data)

    if response.status_code == 200:
        result = response.json()
        llm_description = result['markdown']
        print("LLM-generated description:", llm_description)
    else:
        print(f"Error: {response.json()}")

SSE ์ŠคํŠธ๋ฆฌ๋ฐ ๋ฐฉ์‹ (์‹ค์‹œ๊ฐ„ ์ง„ํ–‰์ƒํ™ฉ ๋ฐ AI ์‘๋‹ต)

import requests
import json

# SSE ์ŠคํŠธ๋ฆฌ๋ฐ์œผ๋กœ ์‹ค์‹œ๊ฐ„ AI ์‘๋‹ต ๋ฐ›๊ธฐ
with open('example.jpg', 'rb') as file:
    files = {'file': ('example.jpg', file)}
    data = {
        'azure_endpoint': 'https://your-resource.openai.azure.com/',
        'api_key': 'your-api-key',
        'deployment_name': 'gpt-4o',
        'api_version': '2024-10-21',
        'enhance_markdown': 'true'
    }

    response = requests.post('http://localhost:5001/convert-image/stream',
                           files=files, data=data, stream=True)

    if response.status_code == 200:
        ai_content = ""
        for line in response.iter_lines():
            if line:
                line = line.decode('utf-8')
                if line.startswith('data: '):
                    try:
                        event_data = json.loads(line[6:])
                        status = event_data.get('status')
                        
                        if status == 'streaming':
                            # ์‹ค์‹œ๊ฐ„ AI ์‘๋‹ต ์ฒญํฌ
                            chunk = event_data.get('chunk', '')
                            ai_content += chunk
                            print(chunk, end='', flush=True)
                        elif status == 'completed':
                            # ์ตœ์ข… ๊ฒฐ๊ณผ
                            result = event_data.get('result', {})
                            print(f"\n\n์™„๋ฃŒ! ์ตœ์ข… ๋งˆํฌ๋‹ค์šด:\n{result.get('markdown')}")
                        elif status == 'error':
                            print(f"Error: {event_data.get('message')}")
                            break
                        else:
                            # ์ง„ํ–‰์ƒํ™ฉ ์—…๋ฐ์ดํŠธ
                            print(f"Status: {event_data.get('message')}")
                    except json.JSONDecodeError:
                        continue
    else:
        print(f"Error: {response.status_code}")

๋ฌธ์„œ์˜ AI ๋ณ€ํ™˜ (Azure OpenAI ์‚ฌ์šฉ)

import requests

# ๋ฌธ์„œ๋ฅผ ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜ํ•œ ํ›„ AI๋กœ ๋ถ„์„
with open('example.pdf', 'rb') as file:
    files = {'file': ('example.pdf', file)}
    data = {
        'azure_endpoint': 'https://your-resource.openai.azure.com/',
        'api_key': 'your-api-key',
        'deployment_name': 'gpt-4o',
        'dpi': '200',
        'format': 'json',
        'enhance_markdown': 'true'
    }

    response = requests.post('http://localhost:5001/convert_with_ai',
                           files=files, data=data)

    if response.status_code == 200:
        result = response.json()
        ai_analysis = result['markdown']
        print("AI-analyzed content:", ai_analysis)
        print(f"Pages processed: {result['metadata']['pages_processed']}")
    else:
        print(f"Error: {response.json()}")

๐Ÿ”ง ๊ณ ๊ธ‰ ์„ค์ •

ํ™˜๊ฒฝ ๋ณ€์ˆ˜

  • FLASK_ENV: ๊ฐœ๋ฐœ/ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ ์„ค์ •
  • MAX_CONTENT_LENGTH: ์ตœ๋Œ€ ํŒŒ์ผ ํฌ๊ธฐ (๊ธฐ๋ณธ๊ฐ’: 100MB)

Azure OpenAI ์„ค์ •

์ด๋ฏธ์ง€ ๋ถ„์„ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด Azure OpenAI ์„œ๋น„์Šค๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค:

์ง€์›ํ•˜๋Š” ๋ชจ๋ธ:

  • gpt-4o (๊ถŒ์žฅ)
  • gpt-4-vision-preview
  • gpt-4o-mini (์ œํ•œ์  ์ง€์›)

ํ•„์ˆ˜ ๋งค๊ฐœ๋ณ€์ˆ˜:

  • azure_endpoint: Azure OpenAI ์—”๋“œํฌ์ธํŠธ URL
  • api_key: Azure OpenAI API ํ‚ค
  • deployment_name: ๋ฐฐํฌ๋œ ๋ชจ๋ธ ์ด๋ฆ„
  • api_version: API ๋ฒ„์ „ (์˜ˆ: 2024-10-21)

์ฐธ๊ณ : gpt-4o-mini๋Š” ์ด๋ฏธ์ง€ ๋ถ„์„์„ ์ง€์›ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ตœ์ ์˜ ์„ฑ๋Šฅ์„ ์œ„ํ•ด gpt-4o ์‚ฌ์šฉ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.

ํ”„๋กœ๋•์…˜ ๋ฐฐํฌ

ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ์—์„œ๋Š” Gunicorn WSGI ์„œ๋ฒ„๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค:

๊ฐœ๋ฐœ ํ™˜๊ฒฝ

python main.py

ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ

# Gunicorn ์„ค์น˜ (์ด๋ฏธ requirements.txt์— ํฌํ•จ๋จ)
pip install gunicorn

# ๊ฐ„๋‹จํ•œ ์‹คํ–‰
gunicorn main:app

# ๋˜๋Š” ์ œ๊ณต๋œ ์Šคํฌ๋ฆฝํŠธ ์‚ฌ์šฉ
./start.sh

# ๋˜๋Š” ์„ค์ • ํŒŒ์ผ๊ณผ ํ•จ๊ป˜ ์‹คํ–‰
gunicorn --config gunicorn.conf.py main:app

์„ค์ • ํŒŒ์ผ gunicorn.conf.py์—์„œ ์›Œ์ปค ์ˆ˜, ํƒ€์ž„์•„์›ƒ, ๋กœ๊น… ๋“ฑ์„ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿงช ํ…Œ์ŠคํŠธ

CLI ํ…Œ์ŠคํŠธ

์ œ๊ณต๋œ ํด๋ผ์ด์–ธํŠธ ์˜ˆ์ œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„œ๋ฒ„๋ฅผ ํ…Œ์ŠคํŠธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

python client_example.py

SSE ์ŠคํŠธ๋ฆฌ๋ฐ ํ…Œ์ŠคํŠธ

๋ธŒ๋ผ์šฐ์ €์—์„œ SSE ์ŠคํŠธ๋ฆฌ๋ฐ์„ ํ…Œ์ŠคํŠธํ•  ์ˆ˜ ์žˆ๋Š” HTML ํŒŒ์ผ์ด ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค:

# ์„œ๋ฒ„ ์‹คํ–‰ ํ›„
open sse_test.html

์ด ํŽ˜์ด์ง€์—์„œ๋Š” ๋‹ค์Œ์„ ํ…Œ์ŠคํŠธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

  • ์‹ค์‹œ๊ฐ„ ์ด๋ฏธ์ง€ ๋ถ„์„ ์ง„ํ–‰์ƒํ™ฉ
  • AI ์‘๋‹ต ์ŠคํŠธ๋ฆฌ๋ฐ
  • ์ „ํ†ต์ ์ธ REST API์™€์˜ ๋น„๊ต
  • ๋‹ค์–‘ํ•œ ์ด๋ฒคํŠธ ํƒ€์ž… ํ™•์ธ

API ํ…Œ์ŠคํŠธ ์˜ˆ์ œ

# ์ผ๋ฐ˜ ํŒŒ์ผ ๋ณ€ํ™˜
curl -X POST -F "file=@example.pdf" http://localhost:5001/convert

# ์ด๋ฏธ์ง€ ๋ถ„์„ (REST)
curl -X POST \
  -F "file=@example.jpg" \
  -F "azure_endpoint=https://your-endpoint.openai.azure.com" \
  -F "api_key=your-key" \
  -F "deployment_name=gpt-4o" \
  http://localhost:5001/convert-image

# ์ด๋ฏธ์ง€ ๋ถ„์„ (SSE ์ŠคํŠธ๋ฆฌ๋ฐ)
curl -N -X POST \
  -F "file=@example.jpg" \
  -F "azure_endpoint=https://your-endpoint.openai.azure.com" \
  -F "api_key=your-key" \
  -F "deployment_name=gpt-4o" \
  http://localhost:5001/convert-image/stream

๐Ÿ“š API Reference

Base URL

http://localhost:5001

Authentication

  • No authentication required for basic file conversion
  • Azure OpenAI API key required for AI-powered features

๐Ÿ“‹ Endpoint Summary

Endpoint Method Type Description AI Required
/ GET Info ์„œ๋ฒ„ ์ •๋ณด ๋ฐ ์ง€์› ํ˜•์‹ ์กฐํšŒ โŒ
/health GET Health ์„œ๋ฒ„ ์ƒํƒœ ํ™•์ธ โŒ
/convert POST Conversion ์ผ๋ฐ˜ ํŒŒ์ผ์„ ๋งˆํฌ๋‹ค์šด์œผ๋กœ ๋ณ€ํ™˜ โŒ
/convert_image POST AI Conversion ์ด๋ฏธ์ง€ AI ๋ถ„์„ (Legacy) โœ…
/convert-image POST AI Conversion ์ด๋ฏธ์ง€ AI ๋ถ„์„ (REST) โœ…
/convert-image/stream POST AI Streaming ์ด๋ฏธ์ง€ AI ๋ถ„์„ (SSE) โœ…
/convert_with_ai POST AI Conversion ๋ฌธ์„œ AI ๋ถ„์„ โœ…
/convert_with_ai/stream POST AI Streaming ๋ฌธ์„œ AI ๋ถ„์„ (SSE) โœ…

๐Ÿ”„ Feature Comparison

Feature Basic Conversion Image AI Document AI Streaming
Endpoints /convert /convert-image
/convert_image
/convert_with_ai /convert-image/stream
/convert_with_ai/stream
File Types All supported formats Images only Office docs + PDF Same as non-streaming
AI Required โŒ โœ… Azure OpenAI โœ… Azure OpenAI โœ… Azure OpenAI
Real-time Updates โŒ โŒ โŒ โœ… SSE
Response Type JSON/Text JSON JSON/Text Server-Sent Events
Use Case Fast file conversion Image description Document analysis Real-time AI analysis

Detailed Endpoint Documentation

1. GET /

์„œ๋ฒ„ ์ •๋ณด ๋ฐ ์ง€์› ํ˜•์‹ ์กฐํšŒ

Response

{
  "status": "MarkItDown File Converter Server",
  "version": "1.0.0",
  "supported_formats": [".docx", ".pdf", ".jpg", ...],
  "endpoints": { ... }
}

2. GET /health

์„œ๋ฒ„ ์ƒํƒœ ํ™•์ธ

Response

{
  "status": "healthy",
  "service": "markitdown-server"
}

3. POST /convert

์ผ๋ฐ˜ ํŒŒ์ผ์„ ๋งˆํฌ๋‹ค์šด์œผ๋กœ ๋ณ€ํ™˜

Parameters

Parameter Type Required Default Description
file File Yes - ๋ณ€ํ™˜ํ•  ํŒŒ์ผ
format String No "json" ์‘๋‹ต ํ˜•์‹: "json" ๋˜๋Š” "text"
enhance_markdown String No "true" ๋งˆํฌ๋‹ค์šด ๊ตฌ์กฐ ๊ฐœ์„ : "true" ๋˜๋Š” "false"

Request Example

curl -X POST \
  -F "file=@example.pdf" \
  -F "format=json" \
  -F "enhance_markdown=true" \
  http://localhost:5001/convert

Response (JSON)

{
  "success": true,
  "markdown": "# ๋ฌธ์„œ ์ œ๋ชฉ\n\n**๋‚ด์šฉ**...",
  "original_markdown": "๋ฌธ์„œ ์ œ๋ชฉ\n\n๋‚ด์šฉ...",
  "file_info": {
    "filename": "example.pdf",
    "extension": ".pdf",
    "mimetype": "application/pdf",
    "supported": true
  },
  "processing_info": {
    "enhanced": true
  },
  "metadata": {
    "original_filename": "example.pdf",
    "converted_size": 1456,
    "original_size": 1234,
    "title": "๋ฌธ์„œ ์ œ๋ชฉ"
  }
}

Response (Text)

# ๋ฌธ์„œ ์ œ๋ชฉ

**๋‚ด์šฉ**...

4. POST /convert-image

์ด๋ฏธ์ง€๋ฅผ AI๋กœ ๋ถ„์„ํ•˜์—ฌ ๋งˆํฌ๋‹ค์šด์œผ๋กœ ๋ณ€ํ™˜ (REST API)

Parameters

Parameter Type Required Default Description
file File Yes - ๋ถ„์„ํ•  ์ด๋ฏธ์ง€ ํŒŒ์ผ
azure_endpoint String Yes - Azure OpenAI ์—”๋“œํฌ์ธํŠธ URL
api_key String Yes - Azure OpenAI API ํ‚ค
deployment_name String Yes - Azure OpenAI ๋ฐฐํฌ ์ด๋ฆ„
api_version String No "2024-02-01" Azure OpenAI API ๋ฒ„์ „
enhance_markdown String No "true" ๋งˆํฌ๋‹ค์šด ๊ตฌ์กฐ ๊ฐœ์„  ์—ฌ๋ถ€

Request Example

curl -X POST \
  -F "file=@image.jpg" \
  -F "azure_endpoint=https://your-resource.openai.azure.com" \
  -F "api_key=your-api-key" \
  -F "deployment_name=gpt-4o" \
  -F "api_version=2024-10-21" \
  -F "enhance_markdown=true" \
  http://localhost:5001/convert-image

Response

{
  "success": true,
  "markdown": "# ์ด๋ฏธ์ง€ ๋ถ„์„\n\n[Image: ๋ผ์ง€ ์–ผ๊ตด ๊ทธ๋ฆผ...]",
  "original_markdown": "์ด๋ฏธ์ง€ ๋ถ„์„\n\n[Image: ๋ผ์ง€ ์–ผ๊ตด ๊ทธ๋ฆผ...]",
  "title": null,
  "metadata": {
    "original_filename": "image.jpg",
    "converted_size": 123,
    "original_size": 123,
    "enhanced": true,
    "llm_used": true,
    "llm_model": "gpt-4o",
    "azure_endpoint": "https://your-resource.openai.azure.com"
  }
}

5. POST /convert-image/stream

์ด๋ฏธ์ง€๋ฅผ AI๋กœ ๋ถ„์„ํ•˜์—ฌ ๋งˆํฌ๋‹ค์šด์œผ๋กœ ๋ณ€ํ™˜ (SSE ์ŠคํŠธ๋ฆฌ๋ฐ)

Parameters

๋™์ผํ•œ parameters๋ฅผ /convert-image์™€ ๋™์ผํ•˜๊ฒŒ ์‚ฌ์šฉ

Request Example

curl -N -X POST \
  -F "file=@image.jpg" \
  -F "azure_endpoint=https://your-resource.openai.azure.com" \
  -F "api_key=your-api-key" \
  -F "deployment_name=gpt-4o" \
  -F "api_version=2024-10-21" \
  -F "enhance_markdown=true" \
  http://localhost:5001/convert-image/stream

Response (Server-Sent Events)

Connection Event
event: connection
data: {"status": "connected", "message": "Connection established"}
Progress Events
event: progress
data: {"status": "processing", "message": "File uploaded successfully, starting conversion...", "filename": "image.jpg"}

event: progress
data: {"status": "processing", "message": "Initializing AI client...", "step": "ai_init"}

event: progress
data: {"status": "processing", "message": "Sending image to AI for analysis...", "step": "ai_processing"}
AI Streaming Events
event: ai_chunk
data: {"status": "streaming", "message": "AI analyzing...", "chunk": "# ์ด๋ฏธ์ง€"}

event: ai_chunk
data: {"status": "streaming", "message": "AI analyzing...", "chunk": " ๋ถ„์„"}
Post-processing Event
event: progress
data: {"status": "processing", "message": "AI analysis complete, post-processing...", "step": "post_processing"}
Final Result Event
event: result
data: {
  "status": "completed",
  "message": "Conversion completed successfully",
  "result": {
    "markdown": "# ์ด๋ฏธ์ง€ ๋ถ„์„\n\n[Image: ์ƒ์„ธํ•œ ์„ค๋ช…...]",
    "original_markdown": "์ด๋ฏธ์ง€ ๋ถ„์„\n\n[Image: ์ƒ์„ธํ•œ ์„ค๋ช…...]",
    "title": null,
    "metadata": { ... }
  }
}
Error Event
event: error
data: {"status": "error", "message": "Error description"}

6. POST /convert_image (Legacy)

๋ ˆ๊ฑฐ์‹œ ์ด๋ฏธ์ง€ ๋ณ€ํ™˜ ์—”๋“œํฌ์ธํŠธ

๋™์ผํ•œ parameters๋ฅผ /convert-image์™€ ๋™์ผํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜์ง€๋งŒ, ๋‚ด๋ถ€์ ์œผ๋กœ ๋‹ค๋ฅธ ๊ตฌํ˜„์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.


7. POST /convert_with_ai

๋ฌธ์„œ๋ฅผ ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜ํ•œ ํ›„ AI๋กœ ๋ถ„์„

Parameters

Parameter Type Required Default Description
file File Yes - ๋ณ€ํ™˜ํ•  ๋ฌธ์„œ ํŒŒ์ผ
azure_endpoint String Yes - Azure OpenAI ์—”๋“œํฌ์ธํŠธ URL
api_key String Yes - Azure OpenAI API ํ‚ค
deployment_name String Yes - Azure OpenAI ๋ฐฐํฌ ์ด๋ฆ„
api_version String No "2024-02-01" Azure OpenAI API ๋ฒ„์ „
dpi String No "200" PDF ๋ณ€ํ™˜ ์‹œ DPI ์„ค์ •
format String No "json" ์‘๋‹ต ํ˜•์‹: "json" ๋˜๋Š” "text"
enhance_markdown String No "true" ๋งˆํฌ๋‹ค์šด ๊ตฌ์กฐ ๊ฐœ์„  ์—ฌ๋ถ€

Supported File Types

  • PDF: .pdf
  • PowerPoint: .pptx, .ppt
  • Word: .docx, .doc
  • Excel: .xlsx, .xls

Request Example

curl -X POST \
  -F "file=@document.pdf" \
  -F "azure_endpoint=https://your-resource.openai.azure.com" \
  -F "api_key=your-api-key" \
  -F "deployment_name=gpt-4o" \
  -F "dpi=200" \
  http://localhost:5001/convert_with_ai

Response

{
  "success": true,
  "markdown": "# ๋ฌธ์„œ ๋ถ„์„ ๊ฒฐ๊ณผ\n\n## ํŽ˜์ด์ง€ 1\n...",
  "file_info": {
    "filename": "document.pdf",
    "extension": ".pdf",
    "mimetype": "application/pdf",
    "supported": true
  },
  "processing_info": {
    "enhanced": true,
    "method": "ai_image_analysis",
    "llm_model": "gpt-4o",
    "azure_endpoint": "https://your-resource.openai.azure.com",
    "dpi": 200
  },
  "analysis_results": [
    {
      "page": 1,
      "status": "success",
      "content_length": 156
    }
  ],
  "metadata": {
    "original_filename": "document.pdf",
    "converted_size": 1456,
    "pages_processed": 3,
    "successful_pages": 3,
    "failed_pages": 0
  }
}

8. POST /convert_with_ai/stream

๋ฌธ์„œ๋ฅผ ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜ํ•œ ํ›„ AI๋กœ ๋ถ„์„ (SSE ์ŠคํŠธ๋ฆฌ๋ฐ)

Parameters

๋™์ผํ•œ parameters๋ฅผ /convert_with_ai์™€ ๋™์ผํ•˜๊ฒŒ ์‚ฌ์šฉ

Request Example

curl -N -X POST \
  -F "file=@document.pdf" \
  -F "azure_endpoint=https://your-resource.openai.azure.com" \
  -F "api_key=your-api-key" \
  -F "deployment_name=gpt-4o" \
  -F "dpi=200" \
  http://localhost:5001/convert_with_ai/stream

Response (Server-Sent Events)

Connection Event
event: connection
data: {"status": "connected", "message": "Connection established"}
Progress Events
event: progress
data: {"status": "processing", "message": "File uploaded successfully, starting AI conversion...", "filename": "document.pdf", "file_info": {...}}

event: progress
data: {"status": "processing", "message": "Converting .pdf document to images...", "step": "document_conversion"}

event: progress
data: {"status": "processing", "message": "Document converted to 3 images. Starting AI analysis...", "total_pages": 3, "step": "ai_processing_start"}

event: progress
data: {"status": "processing", "message": "Analyzing page 1 of 3...", "current_page": 1, "total_pages": 3, "step": "ai_page_processing"}
AI Streaming Events (per page)
event: ai_chunk
data: {"status": "streaming", "message": "AI analyzing page 1...", "page": 1, "chunk": "# ํŽ˜์ด์ง€ 1"}

event: ai_chunk
data: {"status": "streaming", "message": "AI analyzing page 1...", "page": 1, "chunk": "\n\n์ด ํŽ˜์ด์ง€๋Š”..."}
Page Completion Events
event: page_result
data: {"status": "page_completed", "message": "Page 1 analysis completed", "page": 1, "content_length": 156, "progress": "1/3"}
Post-processing Event
event: progress
data: {"status": "processing", "message": "All pages processed. Finalizing document...", "step": "post_processing", "pages_processed": 3, "successful_pages": 3, "failed_pages": 0}
Final Result Event
event: result
data: {
  "status": "completed",
  "message": "AI conversion completed successfully",
  "result": {
    "success": true,
    "markdown": "# ๋ฌธ์„œ ๋ถ„์„ ๊ฒฐ๊ณผ\n\n## ํŽ˜์ด์ง€ 1\n...",
    "file_info": {...},
    "analysis_results": [...],
    "metadata": {
      "original_filename": "document.pdf",
      "converted_size": 1456,
      "pages_processed": 3,
      "successful_pages": 3,
      "failed_pages": 0,
      "enhanced": true,
      "method": "ai_image_analysis_streaming",
      "llm_model": "gpt-4o",
      "azure_endpoint": "https://your-resource.openai.azure.com",
      "dpi": 200
    }
  }
}
Error Events
event: error
data: {"status": "error", "message": "Error description"}

event: page_error
data: {"status": "page_error", "message": "Failed to analyze page 2", "page": 2, "error": "Error details", "progress": "2/3"}

Error Responses

๋ชจ๋“  ์—”๋“œํฌ์ธํŠธ๋Š” ์˜ค๋ฅ˜ ์‹œ ๋‹ค์Œ ํ˜•์‹์œผ๋กœ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค:

400 Bad Request

{
  "error": "No file provided"
}

413 Payload Too Large

{
  "error": "File size exceeds maximum limit"
}

500 Internal Server Error

{
  "error": "Internal server error description",
  "success": false
}

Supported File Formats

Category Extensions
Office Documents .docx, .doc, .pptx, .ppt, .xlsx, .xls
PDF .pdf
Images .jpg, .jpeg, .png, .gif, .bmp, .tiff, .webp
Audio .wav, .mp3
Text .txt, .csv, .json, .xml, .html, .htm
Archive .zip
E-book .epub
Email .msg

Azure OpenAI Model Requirements

Feature Supported Models Recommended
Image Analysis gpt-4o, gpt-4-vision-preview, gpt-4o-mini* gpt-4o
Document AI gpt-4o, gpt-4-vision-preview gpt-4o

*gpt-4o-mini has limited vision capabilities


Rate Limits

  • No built-in rate limiting on the server
  • Rate limits may apply based on Azure OpenAI service limits
  • Maximum file size: 100MB (configurable)

๐Ÿ“ ์—๋Ÿฌ ์ฒ˜๋ฆฌ

์„œ๋ฒ„๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ HTTP ์ƒํƒœ ์ฝ”๋“œ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค:

  • 200: ์„ฑ๊ณต
  • 400: ์ž˜๋ชป๋œ ์š”์ฒญ (ํŒŒ์ผ ์—†์Œ, ์ง€์›ํ•˜์ง€ ์•Š๋Š” ํ˜•์‹ ๋“ฑ)
  • 413: ํŒŒ์ผ ํฌ๊ธฐ ์ดˆ๊ณผ
  • 500: ๋‚ด๋ถ€ ์„œ๋ฒ„ ์˜ค๋ฅ˜

๐Ÿค ๊ธฐ์—ฌํ•˜๊ธฐ

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

๐Ÿ“„ ๋ผ์ด์„ ์Šค

์ด ํ”„๋กœ์ ํŠธ๋Š” MIT ๋ผ์ด์„ ์Šค ํ•˜์— ๋ฐฐํฌ๋ฉ๋‹ˆ๋‹ค.

๐Ÿ™ ๊ฐ์‚ฌ์˜ ๋ง

์ด ํ”„๋กœ์ ํŠธ๋Š” Microsoft์˜ MarkItDown ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages