Skip to content

Commit 8cc2056

Browse files
committed
0914 03:49
1 parent 009bf53 commit 8cc2056

File tree

5 files changed

+154
-1
lines changed

5 files changed

+154
-1
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.

routers/file.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,12 @@ async def ocr_and_create_note(
268268
note_id: Optional[int] = None
269269
if merged_text:
270270
try:
271+
# 추가/변경: 노트 제목을 업로드한 파일 이름으로 설정 (확장자 제거)
272+
base_title = os.path.splitext(filename)[0].strip() or "OCR 결과"
271273
new_note = NoteModel(
272274
user_id=current_user.u_id,
273275
folder_id=folder_id,
274-
title="OCR 결과",
276+
title=base_title,
275277
content=merged_text,
276278
)
277279
db.add(new_note)

0 commit comments

Comments
 (0)