Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ next-env.d.ts
public/img/uploads
postgres_data/
postgres_ssl/certs/certstrap
venv/
__pycache__/
*.pyc
*.pyo
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@
- Alternatively, you can use the local DBMS using the Dockerizing part below. The setting file DATABASE_CLIENT needs to be changed.




### 🌱 Env
- Rename env.dummy to .env.local. Make sure the file is not pushed to the public GitHub repository.
- To avoid using analytics and statistics by connecting to Google Firebase, delete analytics.ts.
Expand All @@ -99,6 +97,20 @@ $ npm install
$ npm run dev
```

### Dev Python API
```bash
$ pyenv versions
system
3.10.12
* 3.12.8 (set by /home/ppabam/.pyenv/version)
$ python -m venv venv
$ source venv/bin/activate
$ python -V
Python 3.10.12
$ pip install -r requirements.txt
$ uvicorn api.index:app --reload
```

### Test
```bash
$ npx jest -t "should correctly join URL parts into a complete URL"
Expand Down
40 changes: 40 additions & 0 deletions api/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from fastapi import FastAPI
from typing import Dict
from flag_morph.extract import extract_nouns
from kiwipiepy import Kiwi

### Create FastAPI instance with custom docs and openapi url
app = FastAPI(docs_url="/api/py/docs", openapi_url="/api/py/openapi.json")

@app.get("/api/py/hipy")
def hello_fast_api():
return {"message": "HI PYTHON FastAPI"}

@app.get("/api/py/n/{sentence}")
def get_nouns(sentence: str) -> Dict[str, list[str]]:
r = extract_nouns(sentence)
return {"nouns": r}

kiwi = Kiwi()
kiwi.analyze("테스트") # 강제로 모델 로드

def extract_nouns(sentence: str, is_print: bool = False) -> list:
"""
주어진 문장에서 명사(NNG, NNP, NP)만 추출하여 리스트로 반환합니다.
"""
result = kiwi.analyze(sentence)
tokens = result[0][0]

target_pos = {"NNG", "NNP", "NP"}
extracted = [word for word, pos, _, _ in tokens if pos in target_pos]

if is_print:
print(f"Extracted nouns: {extracted}")

return extracted

@app.get("/api/py/kiwi/{sentence}")
def run_kiwi(sentence: str) -> Dict[str, list[str]]:
r = extract_nouns(sentence)
return {"nouns": r}

26 changes: 26 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,32 @@ const nextConfig = {
},
];
},

rewrites: async () => {
return [
{
source: "/api/py/:path*",
destination:
process.env.NODE_ENV === "development"
? "http://127.0.0.1:8000/api/py/:path*"
: "/api/",
},
{
source: "/docs",
destination:
process.env.NODE_ENV === "development"
? "http://127.0.0.1:8000/api/py/docs"
: "/api/py/docs",
},
{
source: "/openapi.json",
destination:
process.env.NODE_ENV === "development"
? "http://127.0.0.1:8000/api/py/openapi.json"
: "/api/py/openapi.json",
},
];
},
};

export default nextConfig;
78 changes: 73 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "fff",
"version": "252.2.2",
"version": "253.1.1",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "concurrently \"next dev\" \"npm run fastapi-dev\"",
"lh": "next dev -H 0.0.0.0 -p 3000",
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "jest"
"test": "jest",
"fastapi-dev": "pip install -r requirements.txt && python -m uvicorn api.index:app --reload"
},
"dependencies": {
"@fingerprintjs/fingerprintjs": "^4.5.1",
Expand Down Expand Up @@ -56,7 +57,8 @@
"tailwindcss-animate": "^1.0.7",
"use-debounce": "^10.0.4",
"vaul": "^1.1.2",
"zod": "^3.24.1"
"zod": "^3.24.1",
"concurrently": "^9.0.1"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.6.3",
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fastapi==0.115.0
uvicorn[standard]==0.30.6
korean-age-calculator==1.0.0
flag-morph==1.0.1