Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -121,10 +121,17 @@ def upload():
|
|
| 121 |
if filename.lower().endswith(".pdf"):
|
| 122 |
chunks = split_pdf_into_chunks(path, chunk_size=2)
|
| 123 |
merged_results = []
|
| 124 |
-
for chunk_file in chunks:
|
|
|
|
| 125 |
op_location = submit_read_api(chunk_file)
|
| 126 |
chunk_text = poll_read_result(op_location)
|
| 127 |
merged_results.append(chunk_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
extracted_text = "\n\n".join(merged_results)
|
| 129 |
else:
|
| 130 |
op_location = submit_read_api(path)
|
|
@@ -139,6 +146,7 @@ def upload():
|
|
| 139 |
return jsonify({"text": extracted_text})
|
| 140 |
|
| 141 |
|
|
|
|
| 142 |
# Health check
|
| 143 |
@app.route("/ping-azure")
|
| 144 |
def ping_azure():
|
|
|
|
| 121 |
if filename.lower().endswith(".pdf"):
|
| 122 |
chunks = split_pdf_into_chunks(path, chunk_size=2)
|
| 123 |
merged_results = []
|
| 124 |
+
for i, chunk_file in enumerate(chunks):
|
| 125 |
+
print(f"📄 Processing chunk {i+1}/{len(chunks)}")
|
| 126 |
op_location = submit_read_api(chunk_file)
|
| 127 |
chunk_text = poll_read_result(op_location)
|
| 128 |
merged_results.append(chunk_text)
|
| 129 |
+
|
| 130 |
+
# ⏳ wait 2 seconds before next request to avoid 429 errors
|
| 131 |
+
if i < len(chunks) - 1:
|
| 132 |
+
print("⏳ Sleeping 2s before next chunk...")
|
| 133 |
+
time.sleep(2)
|
| 134 |
+
|
| 135 |
extracted_text = "\n\n".join(merged_results)
|
| 136 |
else:
|
| 137 |
op_location = submit_read_api(path)
|
|
|
|
| 146 |
return jsonify({"text": extracted_text})
|
| 147 |
|
| 148 |
|
| 149 |
+
|
| 150 |
# Health check
|
| 151 |
@app.route("/ping-azure")
|
| 152 |
def ping_azure():
|