Mrigank005 commited on
Commit
66bfcea
·
verified ·
1 Parent(s): 5412061

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +18 -0
  2. main.py +25 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use official lightweight Python image
2
+ FROM python:3.9-slim
3
+
4
+ # Set working directory
5
+ WORKDIR /app
6
+
7
+ # Copy requirements and install
8
+ COPY requirements.txt .
9
+ RUN pip install --no-cache-dir -r requirements.txt
10
+
11
+ # Copy application code
12
+ COPY . .
13
+
14
+ # Expose port 7860 (Hugging Face default)
15
+ EXPOSE 7860
16
+
17
+ # Command to run the app (Adjust 'main:app' to your file name, e.g., 'app:app')
18
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File
2
+ from pypdf import PdfReader
3
+ from io import BytesIO
4
+ import uvicorn
5
+
6
+ app = FastAPI()
7
+
8
+ @app.post("/extract-text")
9
+ async def extract_text(file: UploadFile = File(...)):
10
+ try:
11
+ print(f"📄 Parsing: {file.filename}")
12
+ content = await file.read()
13
+ pdf_reader = PdfReader(BytesIO(content))
14
+
15
+ text = ""
16
+ for page in pdf_reader.pages:
17
+ text += page.extract_text() + "\n"
18
+
19
+ return {"status": "success", "text": text}
20
+ except Exception as e:
21
+ print(f"❌ Error: {str(e)}")
22
+ return {"status": "error", "error": str(e)}
23
+
24
+ if __name__ == "__main__":
25
+ uvicorn.run(app, host="127.0.0.1", port=8000)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ pypdf
4
+ python-multipart