You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
852 B
Python
30 lines
852 B
Python
from flask import Flask, request, jsonify
|
|
import requests
|
|
from pipeline import pdf2markdown_pipeline
|
|
import concurrent.futures
|
|
from loguru import logger
|
|
|
|
|
|
app = Flask(__name__)
|
|
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
|
|
|
|
|
|
def pdf2markdown_task(pdf_paths, callback_url):
|
|
for pdf_path in pdf_paths:
|
|
process_status, pdf_id = pdf2markdown_pipeline(pdf_path)
|
|
requests.post(callback_url, json={'pdfId': pdf_id, 'processStatus': process_status})
|
|
|
|
|
|
@app.route('/pdf-qa-server/pdf-to-md', methods=['POST'])
|
|
def pdf2markdown():
|
|
data = request.json
|
|
logger.info(f'request params: {data}')
|
|
pdf_paths = data['pathList']
|
|
callback_url = data['webhookUrl']
|
|
executor.submit(pdf2markdown_task, pdf_paths, callback_url)
|
|
return jsonify({})
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host='0.0.0.0', port=8000)
|