Microsoft์ MarkItDown ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ ๋ค์ํ ํ์ผ ํ์์ Markdown์ผ๋ก ๋ณํํด์ฃผ๋ Python Flask ์๋ฒ์ ๋๋ค.
- ๐๏ธ ์ํคํ ์ฒ
- ๐ ์ฃผ์ ๊ธฐ๋ฅ
- ๐ ์ง์ํ๋ ํ์ผ ํ์
- ๐ ๏ธ ์ค์น ๋ฐ ์คํ
- ๐ API ์ฌ์ฉ๋ฒ
- โก Quick Start Examples
- ๐ Python ํด๋ผ์ด์ธํธ ์์
- ๐ API Reference
- ๐ง ๊ณ ๊ธ ์ค์
- ๐งช ํ ์คํธ
- ๐ ์๋ฌ ์ฒ๋ฆฌ
์ด ํ๋ก์ ํธ๋ 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
- ์ ์ฅ์ ํด๋ก ๋ฐ ์์กด์ฑ ์ค์น
git clone <repository-url>
cd markitdown-server
pip install -r requirements.txt- ์๋ฒ ์คํ
python main.py์๋ฒ๊ฐ http://localhost:5001์์ ์คํ๋ฉ๋๋ค.
- Docker ์ด๋ฏธ์ง ๋น๋
docker build -t markitdown-server .- ์ปจํ ์ด๋ ์คํ
docker run -p 5001:5001 markitdown-servercurl http://localhost:5001/healthcurl http://localhost:5001/curl -X POST \
-F "file=@example.pdf" \
-F "format=json" \
-F "enhance_markdown=true" \
http://localhost:5001/convertcurl -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-imagecurl -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/streamSSE ์ด๋ฒคํธ ํ์ :
connection: ์ฐ๊ฒฐ ํ๋ฆฝprogress: ์งํ์ํฉ ์ ๋ฐ์ดํธai_chunk: ์ค์๊ฐ AI ์๋ต ์ฒญํฌresult: ์ต์ข ๊ฒฐ๊ณผerror: ์ค๋ฅ ๋ฐ์
# ์๋ฒ๊ฐ ์คํ ์ค์ธ์ง ํ์ธ
curl http://localhost:5001/health
# ์ง์ํ๋ ํ์ผ ํ์๊ณผ ๋ชจ๋ ์๋ํฌ์ธํธ ์ ๋ณด ํ์ธ
curl http://localhost:5001/# 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# ์ ํต์ ์ธ 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# ๋ฌธ์๋ฅผ ์ด๋ฏธ์ง๋ก ๋ณํํ ํ 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| ํ์ผ ํ์ | ๊ถ์ฅ ์๋ํฌ์ธํธ | ์ด์ |
|---|---|---|
ํ
์คํธ ํ์ผ (.txt, .csv, .json) |
/convert |
๋น ๋ฅด๊ณ ์ ํํ ์ผ๋ฐ ๋ณํ |
Office ๋ฌธ์ (.docx, .pptx, .xlsx) |
/convert ๋๋ /convert_with_ai |
์ผ๋ฐ ๋ณํ์ผ๋ก ์ถฉ๋ถํ๋, ๋ณต์กํ ๋ ์ด์์์ AI ๋ถ์ ๊ถ์ฅ |
/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/convertimport 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()}")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()}")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}")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 ์๋น์ค๊ฐ ํ์ํฉ๋๋ค:
์ง์ํ๋ ๋ชจ๋ธ:
gpt-4o(๊ถ์ฅ)gpt-4-vision-previewgpt-4o-mini(์ ํ์ ์ง์)
ํ์ ๋งค๊ฐ๋ณ์:
azure_endpoint: Azure OpenAI ์๋ํฌ์ธํธ URLapi_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์์ ์์ปค ์, ํ์์์, ๋ก๊น
๋ฑ์ ์กฐ์ ํ ์ ์์ต๋๋ค.
์ ๊ณต๋ ํด๋ผ์ด์ธํธ ์์ ๋ฅผ ์ฌ์ฉํ์ฌ ์๋ฒ๋ฅผ ํ ์คํธํ ์ ์์ต๋๋ค:
python client_example.py๋ธ๋ผ์ฐ์ ์์ SSE ์คํธ๋ฆฌ๋ฐ์ ํ ์คํธํ ์ ์๋ HTML ํ์ผ์ด ์ ๊ณต๋ฉ๋๋ค:
# ์๋ฒ ์คํ ํ
open sse_test.html์ด ํ์ด์ง์์๋ ๋ค์์ ํ ์คํธํ ์ ์์ต๋๋ค:
- ์ค์๊ฐ ์ด๋ฏธ์ง ๋ถ์ ์งํ์ํฉ
- AI ์๋ต ์คํธ๋ฆฌ๋ฐ
- ์ ํต์ ์ธ REST 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/streamhttp://localhost:5001
- No authentication required for basic file conversion
- Azure OpenAI API key required for AI-powered features
| 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 | 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 |
์๋ฒ ์ ๋ณด ๋ฐ ์ง์ ํ์ ์กฐํ
{
"status": "MarkItDown File Converter Server",
"version": "1.0.0",
"supported_formats": [".docx", ".pdf", ".jpg", ...],
"endpoints": { ... }
}์๋ฒ ์ํ ํ์ธ
{
"status": "healthy",
"service": "markitdown-server"
}์ผ๋ฐ ํ์ผ์ ๋งํฌ๋ค์ด์ผ๋ก ๋ณํ
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
file |
File | Yes | - | ๋ณํํ ํ์ผ |
format |
String | No | "json" |
์๋ต ํ์: "json" ๋๋ "text" |
enhance_markdown |
String | No | "true" |
๋งํฌ๋ค์ด ๊ตฌ์กฐ ๊ฐ์ : "true" ๋๋ "false" |
curl -X POST \
-F "file=@example.pdf" \
-F "format=json" \
-F "enhance_markdown=true" \
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": "๋ฌธ์ ์ ๋ชฉ"
}
}# ๋ฌธ์ ์ ๋ชฉ
**๋ด์ฉ**...
์ด๋ฏธ์ง๋ฅผ AI๋ก ๋ถ์ํ์ฌ ๋งํฌ๋ค์ด์ผ๋ก ๋ณํ (REST API)
| 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" |
๋งํฌ๋ค์ด ๊ตฌ์กฐ ๊ฐ์ ์ฌ๋ถ |
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{
"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"
}
}์ด๋ฏธ์ง๋ฅผ AI๋ก ๋ถ์ํ์ฌ ๋งํฌ๋ค์ด์ผ๋ก ๋ณํ (SSE ์คํธ๋ฆฌ๋ฐ)
๋์ผํ parameters๋ฅผ /convert-image์ ๋์ผํ๊ฒ ์ฌ์ฉ
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/streamevent: connection
data: {"status": "connected", "message": "Connection established"}
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"}
event: ai_chunk
data: {"status": "streaming", "message": "AI analyzing...", "chunk": "# ์ด๋ฏธ์ง"}
event: ai_chunk
data: {"status": "streaming", "message": "AI analyzing...", "chunk": " ๋ถ์"}
event: progress
data: {"status": "processing", "message": "AI analysis complete, post-processing...", "step": "post_processing"}
event: result
data: {
"status": "completed",
"message": "Conversion completed successfully",
"result": {
"markdown": "# ์ด๋ฏธ์ง ๋ถ์\n\n[Image: ์์ธํ ์ค๋ช
...]",
"original_markdown": "์ด๋ฏธ์ง ๋ถ์\n\n[Image: ์์ธํ ์ค๋ช
...]",
"title": null,
"metadata": { ... }
}
}
event: error
data: {"status": "error", "message": "Error description"}
๋ ๊ฑฐ์ ์ด๋ฏธ์ง ๋ณํ ์๋ํฌ์ธํธ
๋์ผํ parameters๋ฅผ /convert-image์ ๋์ผํ๊ฒ ์ฌ์ฉํ์ง๋ง, ๋ด๋ถ์ ์ผ๋ก ๋ค๋ฅธ ๊ตฌํ์ ์ฌ์ฉํฉ๋๋ค.
๋ฌธ์๋ฅผ ์ด๋ฏธ์ง๋ก ๋ณํํ ํ AI๋ก ๋ถ์
| 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" |
๋งํฌ๋ค์ด ๊ตฌ์กฐ ๊ฐ์ ์ฌ๋ถ |
- PDF:
.pdf - PowerPoint:
.pptx,.ppt - Word:
.docx,.doc - Excel:
.xlsx,.xls
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{
"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
}
}๋ฌธ์๋ฅผ ์ด๋ฏธ์ง๋ก ๋ณํํ ํ AI๋ก ๋ถ์ (SSE ์คํธ๋ฆฌ๋ฐ)
๋์ผํ parameters๋ฅผ /convert_with_ai์ ๋์ผํ๊ฒ ์ฌ์ฉ
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/streamevent: connection
data: {"status": "connected", "message": "Connection established"}
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"}
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์ด ํ์ด์ง๋..."}
event: page_result
data: {"status": "page_completed", "message": "Page 1 analysis completed", "page": 1, "content_length": 156, "progress": "1/3"}
event: progress
data: {"status": "processing", "message": "All pages processed. Finalizing document...", "step": "post_processing", "pages_processed": 3, "successful_pages": 3, "failed_pages": 0}
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
}
}
}
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": "No file provided"
}{
"error": "File size exceeds maximum limit"
}{
"error": "Internal server error description",
"success": false
}| Category | Extensions |
|---|---|
| Office Documents | .docx, .doc, .pptx, .ppt, .xlsx, .xls |
.pdf |
|
| Images | .jpg, .jpeg, .png, .gif, .bmp, .tiff, .webp |
| Audio | .wav, .mp3 |
| Text | .txt, .csv, .json, .xml, .html, .htm |
| Archive | .zip |
| E-book | .epub |
.msg |
| 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
- 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: ๋ด๋ถ ์๋ฒ ์ค๋ฅ
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
์ด ํ๋ก์ ํธ๋ MIT ๋ผ์ด์ ์ค ํ์ ๋ฐฐํฌ๋ฉ๋๋ค.
์ด ํ๋ก์ ํธ๋ Microsoft์ MarkItDown ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํฉ๋๋ค.