Document parsing endpoint. Request: { "images": ["url1", "url2", ...], # image URLs (http/https/file/data) } Response: { "json_result": {...}, "markdown_result": "..." }
()
| 74 | |
| 75 | @app.route("/glmocr/parse", methods=["POST"]) |
| 76 | def parse(): |
| 77 | """Document parsing endpoint. |
| 78 | |
| 79 | Request: |
| 80 | { |
| 81 | "images": ["url1", "url2", ...], # image URLs (http/https/file/data) |
| 82 | } |
| 83 | |
| 84 | Response: |
| 85 | { |
| 86 | "json_result": {...}, |
| 87 | "markdown_result": "..." |
| 88 | } |
| 89 | """ |
| 90 | # Validate Content-Type |
| 91 | if request.headers.get("Content-Type") != "application/json": |
| 92 | return ( |
| 93 | jsonify( |
| 94 | {"error": "Invalid Content-Type. Expected 'application/json'."} |
| 95 | ), |
| 96 | 400, |
| 97 | ) |
| 98 | |
| 99 | # Parse JSON payload |
| 100 | try: |
| 101 | data = request.json |
| 102 | except Exception: |
| 103 | return jsonify({"error": "Invalid JSON payload"}), 400 |
| 104 | |
| 105 | images = data.get("images", []) |
| 106 | if isinstance(images, str): |
| 107 | images = [images] |
| 108 | |
| 109 | # Compatibility: MaaS client uses "file" field instead of "images" |
| 110 | if not images and "file" in data: |
| 111 | file_val = data["file"] |
| 112 | if isinstance(file_val, str) and file_val: |
| 113 | images = [file_val] |
| 114 | |
| 115 | if not images: |
| 116 | return jsonify({"error": "No images provided"}), 400 |
| 117 | |
| 118 | # Build pipeline request |
| 119 | messages = [{"role": "user", "content": []}] |
| 120 | for image_url in images: |
| 121 | messages[0]["content"].append( |
| 122 | {"type": "image_url", "image_url": {"url": image_url}} |
| 123 | ) |
| 124 | |
| 125 | request_data = {"messages": messages} |
| 126 | |
| 127 | try: |
| 128 | # Pipeline.process() yields one result per input unit; merge for single response |
| 129 | results = list( |
| 130 | pipeline.process( |
| 131 | request_data, |
| 132 | save_layout_visualization=False, |
| 133 | ) |
nothing calls this directly
no test coverage detected