Spaces:
Running
Running
File size: 1,224 Bytes
c53b292 96cc1ef c53b292 fb55ffe 99200ee 9e8393f 96cc1ef fb55ffe c53b292 f10c908 96cc1ef 4197760 f10c908 4197760 c53b292 5d3eaef c53b292 fb55ffe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import os
import sys
cur_dir = os.getcwd()
parent_dir = os.path.realpath(os.path.join(os.path.dirname(cur_dir)))
if parent_dir not in sys.path:
sys.path.append(parent_dir)
sys.path.append(cur_dir)
sys.path.insert(1, ".")
from fastapi import FastAPI, UploadFile, File
from extraction import process_document
from fastapi.responses import JSONResponse
from app.config import *
import tempfile
import shutil
import json
import uvicorn
app = FastAPI(
title="PDF Processor API",
description="Upload a PDF and get structured document data",
version="1.0.0",
docs_url="/docs",
redoc_url="/redoc",
openapi_url="/openapi.json",
root_path="/spaces/mussie1212/melhiq_ocr"
)
@app.get("/")
def root():
return {"status": "ok", "routes": [str(r.path) for r in app.routes]}
@app.post("/ocr")
async def process_pdf(file: UploadFile = File(...)):
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
shutil.copyfileobj(file.file, tmp)
tmp_path = tmp.name
result = process_document(tmp_path, api_key=ConfigStaticFiles.gemini_api_key)
if isinstance(result, str):
result = json.loads(result)
return JSONResponse(content=result) |