Skip to content

Commit 11ea903

Browse files
authored
Merge pull request #21 from KKU-NoteFlow/fix/ocr
0914 01:00
2 parents 7598009 + 8cc2056 commit 11ea903

File tree

10 files changed

+747
-103
lines changed

10 files changed

+747
-103
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
push:
7+
branches: [ main ]
8+
paths:
9+
- '**/*.py'
10+
- 'requirements.txt'
11+
- '.github/workflows/ci.yml'
12+
13+
jobs:
14+
lint-test:
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 10
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.11'
23+
cache: 'pip'
24+
25+
- name: Install deps
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -r requirements.txt
29+
30+
- name: Syntax check
31+
run: |
32+
python -m py_compile $(git ls-files '*.py' | tr '\n' ' ')
33+
34+
- name: Import smoke
35+
run: |
36+
python - << 'PY'
37+
from importlib import import_module
38+
import_module('main')
39+
print('Import OK')
40+
PY
41+

.github/workflows/docker.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Docker Build & Push (Backend)
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- '**'
8+
- '!README.md'
9+
10+
jobs:
11+
docker:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
packages: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Log in to GHCR
20+
uses: docker/login-action@v3
21+
with:
22+
registry: ghcr.io
23+
username: ${{ github.actor }}
24+
password: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Build and push
27+
uses: docker/build-push-action@v6
28+
with:
29+
context: .
30+
file: ./Dockerfile
31+
push: true
32+
tags: |
33+
ghcr.io/${{ github.repository }}:backend-latest
34+
ghcr.io/${{ github.repository }}:backend-${{ github.sha }}
35+

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM python:3.11-slim
2+
3+
ENV PYTHONDONTWRITEBYTECODE=1 \
4+
PYTHONUNBUFFERED=1
5+
6+
WORKDIR /app
7+
8+
# System dependencies for pdf2image
9+
RUN apt-get update && apt-get install -y --no-install-recommends \
10+
poppler-utils \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
COPY Backend/requirements.txt ./requirements.txt
14+
RUN pip install --no-cache-dir -r requirements.txt
15+
16+
COPY Backend/ ./
17+
18+
EXPOSE 8080
19+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
20+

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Noteflow Backend (FastAPI)
2+
3+
## Overview
4+
- FastAPI backend for Noteflow
5+
- OCR pipeline supports images, PDF, DOC/DOCX, HWP (via utilities and system tools)
6+
7+
## Run (local)
8+
```
9+
python -m venv .venv
10+
source .venv/bin/activate
11+
pip install -r requirements.txt
12+
uvicorn main:app --host 0.0.0.0 --port 8080 --reload
13+
```
14+
15+
Env (optional):
16+
- `SECRET_KEY`, `ACCESS_TOKEN_EXPIRE_MINUTES`
17+
- Database URLs if you connect a DB (current code uses provided models)
18+
19+
## OCR system tools (optional but recommended)
20+
- PyMuPDF (Python) used by default for PDF text extraction
21+
- Optional fallbacks/tools:
22+
- Poppler (`pdftoppm`) for `pdf2image`
23+
- LibreOffice (`soffice`) for .doc → .pdf
24+
- `hwp5txt` for .hwp text extraction
25+
- If missing, the API still returns 200 with `warnings` explaining limitations.
26+
27+
## API Highlights
28+
- `POST /api/v1/files/ocr` — OCR and create note (accepts file + optional `folder_id`, `langs`, `max_pages`)
29+
- `POST /api/v1/files/upload` — Upload files to folder
30+
- `POST /api/v1/files/audio` — STT from audio, create/append to note
31+
32+
## CI (GitHub Actions)
33+
- This folder includes `.github/workflows/ci.yml` to lint/smoke-test on push/PR.
34+
- Python 3.11, `pip install -r requirements.txt`, syntax check and import smoke.
35+
36+
## Docker (optional; for later)
37+
- Dockerfile included. Build & run locally:
38+
```
39+
docker build -t noteflow-backend .
40+
docker run --rm -p 8080:8080 noteflow-backend
41+
```
42+
- GitHub Actions container build:
43+
- `.github/workflows/docker.yml` pushes to GHCR:
44+
- `ghcr.io/<owner>/<repo>:backend-latest`
45+
- `ghcr.io/<owner>/<repo>:backend-<sha>`
46+
- Deployment example (SSH) once you’re ready:
47+
```
48+
docker login ghcr.io -u <USER> -p <TOKEN>
49+
docker pull ghcr.io/<owner>/<repo>:backend-latest
50+
docker run -d --name backend --restart=always -p 8080:8080 ghcr.io/<owner>/<repo>:backend-latest
51+
```
52+
53+
## Notes
54+
- If you split this folder into its own repository root, the included `.github/workflows/*.yml` files will work as-is.
55+
- OCR uses model-first path (EasyOCR + TrOCR) and falls back to tesseract when available.

requirements.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,31 @@ uvicorn
33
pydantic
44
sqlalchemy
55
mysql-connector-python
6-
dotenv
6+
python-dotenv
77
google-auth
88
requests
99
python-jose[cryptography]
1010
bcrypt
1111

12-
torch==2.3.0+cu121
13-
torchaudio==2.3.0+cu121
14-
torchvision==0.18.0+cu121
15-
--extra-index-url https://download.pytorch.org/whl/cu121
12+
# PyTorch (MacOS: CPU/MPS 빌드 자동 설치됨)
13+
torch==2.3.0
14+
torchvision==0.18.0
15+
torchaudio==2.3.0
1616

1717
transformers>=4.40.0
1818
accelerate
1919
sentencepiece
2020
protobuf
2121
python-multipart
2222
easyocr
23-
whisper
23+
whisper
24+
pytesseract
25+
pdf2image
26+
PyMuPDF
27+
python-docx
28+
29+
langchain>=0.2.0
30+
langchain-community
31+
langchain-core
32+
langchain-openai
33+
langchain-ollama

0 commit comments

Comments
 (0)