ibsmiro commited on
Commit
1f4b45b
·
verified ·
1 Parent(s): c474abf

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile.txt +17 -0
  2. app.py +39 -0
  3. requirements.txt +5 -0
Dockerfile.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.13
2
+
3
+ WORKDIR /app
4
+
5
+ RUN apt-get update && apt-get install -y \
6
+ poppler-utils \
7
+ && rm -rf /var/lib/apt/lists/*
8
+
9
+ COPY requirements.txt .
10
+
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ COPY . .
14
+
15
+ EXPOSE 7860
16
+
17
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File
2
+ from fastapi.responses import Response, JSONResponse
3
+ from pdf2image import convert_from_bytes
4
+ import io
5
+
6
+ app = FastAPI()
7
+
8
+
9
+ @app.get("/")
10
+ def root():
11
+ return {"status": "running"}
12
+
13
+
14
+ @app.post("/pdf-to-image")
15
+ async def pdf_to_image(file: UploadFile = File(...)):
16
+ try:
17
+ pdf_bytes = await file.read()
18
+
19
+ pages = convert_from_bytes(pdf_bytes)
20
+
21
+ if not pages:
22
+ return JSONResponse(
23
+ {"error": "No pages found"},
24
+ status_code=400
25
+ )
26
+
27
+ buffer = io.BytesIO()
28
+ pages[0].save(buffer, format="JPEG")
29
+
30
+ return Response(
31
+ content=buffer.getvalue(),
32
+ media_type="image/jpeg"
33
+ )
34
+
35
+ except Exception as e:
36
+ return JSONResponse(
37
+ {"error": str(e)},
38
+ status_code=500
39
+ )
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ pdf2image
4
+ pillow
5
+ python-multipart