v3:추출 파이프라인_260122
This commit is contained in:
89
app.py
89
app.py
@@ -13,8 +13,13 @@ from flask import Flask, render_template, request, jsonify, Response, session
|
||||
from datetime import datetime
|
||||
import io
|
||||
import re
|
||||
from flask import send_file
|
||||
from datetime import datetime
|
||||
import tempfile
|
||||
from converters.pipeline.router import process_document
|
||||
from api_config import API_KEYS
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max
|
||||
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'geulbeot-light-secret-key-v2')
|
||||
@@ -81,7 +86,6 @@ def get_refine_prompt():
|
||||
|
||||
위 피드백을 반영하여 수정된 완전한 HTML을 출력하세요."""
|
||||
|
||||
|
||||
# ============== API 호출 함수 ==============
|
||||
|
||||
def call_claude(system_prompt, user_message, max_tokens=8000):
|
||||
@@ -479,6 +483,45 @@ def hwp_script():
|
||||
"""HWP 변환 스크립트 안내"""
|
||||
return render_template('hwp_guide.html')
|
||||
|
||||
@app.route('/generate-report', methods=['POST'])
|
||||
def generate_report_api():
|
||||
"""보고서 생성 API (router 기반)"""
|
||||
try:
|
||||
data = request.get_json() or {}
|
||||
|
||||
# HTML 내용 (폴더에서 읽거나 직접 입력)
|
||||
content = data.get('content', '')
|
||||
|
||||
# 옵션
|
||||
options = {
|
||||
'folder_path': data.get('folder_path', ''),
|
||||
'cover': data.get('cover', False),
|
||||
'toc': data.get('toc', False),
|
||||
'divider': data.get('divider', False),
|
||||
'instruction': data.get('instruction', '')
|
||||
}
|
||||
|
||||
if not content.strip():
|
||||
return jsonify({'error': '내용이 비어있습니다.'}), 400
|
||||
|
||||
# router로 처리
|
||||
result = process_document(content, options)
|
||||
|
||||
if result.get('success'):
|
||||
return jsonify(result)
|
||||
else:
|
||||
return jsonify({'error': result.get('error', '처리 실패')}), 500
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
return jsonify({'error': str(e), 'trace': traceback.format_exc()}), 500
|
||||
|
||||
@app.route('/assets/<path:filename>')
|
||||
def serve_assets(filename):
|
||||
"""로컬 assets 폴더 서빙"""
|
||||
assets_dir = r"D:\for python\geulbeot-light\geulbeot-light\output\assets"
|
||||
return send_file(os.path.join(assets_dir, filename))
|
||||
|
||||
|
||||
@app.route('/health')
|
||||
def health():
|
||||
@@ -486,6 +529,50 @@ def health():
|
||||
return jsonify({'status': 'healthy', 'version': '2.0.0'})
|
||||
|
||||
|
||||
# ===== HWP 변환 =====
|
||||
@app.route('/export-hwp', methods=['POST'])
|
||||
def export_hwp():
|
||||
try:
|
||||
data = request.get_json()
|
||||
html_content = data.get('html', '')
|
||||
doc_type = data.get('doc_type', 'briefing')
|
||||
|
||||
if not html_content:
|
||||
return jsonify({'error': 'HTML 내용이 없습니다'}), 400
|
||||
|
||||
# 임시 파일 생성
|
||||
temp_dir = tempfile.gettempdir()
|
||||
html_path = os.path.join(temp_dir, 'geulbeot_temp.html')
|
||||
hwp_path = os.path.join(temp_dir, 'geulbeot_output.hwp')
|
||||
|
||||
# HTML 저장
|
||||
with open(html_path, 'w', encoding='utf-8') as f:
|
||||
f.write(html_content)
|
||||
|
||||
# 변환기 import 및 실행
|
||||
if doc_type == 'briefing':
|
||||
from converters.html_to_hwp_briefing import HtmlToHwpConverter
|
||||
else:
|
||||
from converters.html_to_hwp import HtmlToHwpConverter
|
||||
|
||||
converter = HtmlToHwpConverter(visible=False)
|
||||
converter.convert(html_path, hwp_path)
|
||||
converter.close()
|
||||
|
||||
# 파일 전송
|
||||
return send_file(
|
||||
hwp_path,
|
||||
as_attachment=True,
|
||||
download_name=f'report_{datetime.now().strftime("%Y%m%d_%H%M%S")}.hwp',
|
||||
mimetype='application/x-hwp'
|
||||
)
|
||||
|
||||
except ImportError as e:
|
||||
return jsonify({'error': f'pyhwpx 필요: {str(e)}'}), 500
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
port = int(os.environ.get('PORT', 5000))
|
||||
debug = os.environ.get('FLASK_DEBUG', 'False').lower() == 'true'
|
||||
|
||||
Reference in New Issue
Block a user