Vladyslav Nalyvaiko commited on
Commit
7b36638
·
1 Parent(s): ca05b65

Fast API update 2

Browse files
Files changed (3) hide show
  1. Dockerfile +26 -0
  2. app.py +16 -2
  3. requirements.txt +4 -1
Dockerfile ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ # Install system dependencies
6
+ RUN apt-get update && apt-get install -y \
7
+ build-essential \
8
+ curl \
9
+ software-properties-common \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ # Copy requirements first to leverage Docker cache
13
+ COPY ./requirements.txt /code/requirements.txt
14
+ RUN pip install --no-cache-dir -r requirements.txt
15
+
16
+ # Copy the rest of the application
17
+ COPY . /code/
18
+
19
+ # Make sure the inbox and output directories exist
20
+ RUN mkdir -p /code/inbox /code/output
21
+
22
+ # Expose the port
23
+ EXPOSE 7860
24
+
25
+ # Command to run the application
26
+ CMD ["python", "app.py"]
app.py CHANGED
@@ -3,8 +3,8 @@ import os
3
  import shutil
4
  import logging
5
  import uvicorn
6
- from fastapi import FastAPI, File, UploadFile, BackgroundTasks
7
- from typing import List, Optional
8
 
9
  # This ensures our models are downloaded and config is set before anything
10
  # Alternatively you can do this in a "startup" event handler
@@ -16,11 +16,25 @@ from mineru_single import to_markdown
16
  app = FastAPI()
17
  logging.basicConfig(level=logging.INFO)
18
 
 
 
 
 
 
 
 
 
 
19
  INBOX_DIR = "./inbox"
20
  OUTPUT_DIR = "./output"
21
  os.makedirs(INBOX_DIR, exist_ok=True)
22
  os.makedirs(OUTPUT_DIR, exist_ok=True)
23
 
 
 
 
 
 
24
  @app.post("/process")
25
  async def process_pdf(file: UploadFile = File(...)):
26
 
 
3
  import shutil
4
  import logging
5
  import uvicorn
6
+ from fastapi import FastAPI, File, UploadFile
7
+ from fastapi.middleware.cors import CORSMiddleware
8
 
9
  # This ensures our models are downloaded and config is set before anything
10
  # Alternatively you can do this in a "startup" event handler
 
16
  app = FastAPI()
17
  logging.basicConfig(level=logging.INFO)
18
 
19
+ # Add CORS middleware to allow requests from any origin
20
+ app.add_middleware(
21
+ CORSMiddleware,
22
+ allow_origins=["*"], # Allows all origins
23
+ allow_credentials=True,
24
+ allow_methods=["*"], # Allows all methods
25
+ allow_headers=["*"], # Allows all headers
26
+ )
27
+
28
  INBOX_DIR = "./inbox"
29
  OUTPUT_DIR = "./output"
30
  os.makedirs(INBOX_DIR, exist_ok=True)
31
  os.makedirs(OUTPUT_DIR, exist_ok=True)
32
 
33
+ @app.get("/")
34
+ async def root():
35
+ """Health check endpoint"""
36
+ return {"status": "ok", "message": "API is running"}
37
+
38
  @app.post("/process")
39
  async def process_pdf(file: UploadFile = File(...)):
40
 
requirements.txt CHANGED
@@ -23,4 +23,7 @@ rapid-table>=1.0.3,<2.0.0
23
  rapidocr-paddle
24
  rapidocr-onnxruntime
25
  gradio-pdf>=0.0.21
26
- openai
 
 
 
 
23
  rapidocr-paddle
24
  rapidocr-onnxruntime
25
  gradio-pdf>=0.0.21
26
+ openai
27
+ fastapi
28
+ uvicorn
29
+ python-multipart