Spaces:
Running
Running
Commit ·
6e755f8
1
Parent(s): 2e56fff
- .dockerignore +8 -0
- .env +1 -0
- .gitignore +13 -0
- Dockerfile +18 -0
- app.py +21 -0
- readme.txt +7 -0
- requirements.txt +7 -0
- routers/test_router.py +64 -0
- utils/common.py +9 -0
.dockerignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
*.pyo
|
| 4 |
+
*.pyd
|
| 5 |
+
*.log
|
| 6 |
+
.git
|
| 7 |
+
.gitignore
|
| 8 |
+
.venv/
|
.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
POSTGRES_URL="postgres://postgres.gxicreuzktyzvkbxlbgc:smTwq8ODnMF6GrGU@aws-1-ap-northeast-2.pooler.supabase.com:6543/postgres?sslmode=require"
|
.gitignore
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python Bytecode Files
|
| 2 |
+
*.pyc
|
| 3 |
+
__pycache__/
|
| 4 |
+
|
| 5 |
+
# Dependencies
|
| 6 |
+
venv/
|
| 7 |
+
.venv/
|
| 8 |
+
.mypy_cache/
|
| 9 |
+
|
| 10 |
+
# ⭐️ 학습된 모델 및 결과 폴더 제외 ⭐️
|
| 11 |
+
my_local_models/
|
| 12 |
+
model_save/
|
| 13 |
+
model_save_minilm/
|
Dockerfile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.13-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
# 패키지 설치
|
| 6 |
+
COPY requirements.txt .
|
| 7 |
+
|
| 8 |
+
RUN pip install --no-cache-dir --upgrade pip \
|
| 9 |
+
&& pip install --no-cache-dir -r requirements.txt
|
| 10 |
+
|
| 11 |
+
# 프로젝트 전체 복사
|
| 12 |
+
COPY . .
|
| 13 |
+
|
| 14 |
+
# Hugging Face Spaces 기본 포트
|
| 15 |
+
EXPOSE 7860
|
| 16 |
+
|
| 17 |
+
# FastAPI 실행
|
| 18 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from routers import test_router
|
| 3 |
+
import uvicorn
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
app.include_router(test_router.router)
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@app.get("/")
|
| 11 |
+
def home():
|
| 12 |
+
return {"message": "FastAPI 실행 성공"}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
if __name__ == "__main__":
|
| 16 |
+
uvicorn.run(
|
| 17 |
+
"app:app",
|
| 18 |
+
host="127.0.0.1",
|
| 19 |
+
port=8000,
|
| 20 |
+
reload=True
|
| 21 |
+
)
|
readme.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
py -3.13 -m uv venv venv
|
| 2 |
+
|
| 3 |
+
.\venv\Scripts\Activate.ps1
|
| 4 |
+
|
| 5 |
+
uv pip install -r requirements.txt
|
| 6 |
+
|
| 7 |
+
uv run python app.py
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn[standard]
|
| 3 |
+
python-multipart
|
| 4 |
+
python-dotenv
|
| 5 |
+
pydantic
|
| 6 |
+
sqlalchemy
|
| 7 |
+
psycopg[binary]
|
routers/test_router.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, Form, File, UploadFile
|
| 2 |
+
from utils.common import CommonResponse
|
| 3 |
+
|
| 4 |
+
router = APIRouter(
|
| 5 |
+
prefix="/test",
|
| 6 |
+
tags=["test"]
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
@router.get("/")
|
| 10 |
+
def test_home():
|
| 11 |
+
try:
|
| 12 |
+
return CommonResponse(success=True)
|
| 13 |
+
except Exception as e:
|
| 14 |
+
return CommonResponse(success=False, msg=str(e))
|
| 15 |
+
|
| 16 |
+
@router.get("/info")
|
| 17 |
+
def test_info(name: str = "", age: int = 0):
|
| 18 |
+
try:
|
| 19 |
+
# 비즈니스 로직 처리
|
| 20 |
+
data = {
|
| 21 |
+
"name": name,
|
| 22 |
+
"age": age
|
| 23 |
+
}
|
| 24 |
+
return CommonResponse(success=True, data=data)
|
| 25 |
+
except Exception as e:
|
| 26 |
+
return CommonResponse(success=False, msg=str(e))
|
| 27 |
+
|
| 28 |
+
@router.get("/mytest")
|
| 29 |
+
def mytest(username: str = "", password: str=""):
|
| 30 |
+
try:
|
| 31 |
+
# 비즈니스 로직 처리
|
| 32 |
+
data = {
|
| 33 |
+
"username": username,
|
| 34 |
+
"password": password
|
| 35 |
+
}
|
| 36 |
+
return CommonResponse(success=True, data=data)
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return CommonResponse(success=False, msg=str(e))
|
| 39 |
+
|
| 40 |
+
@router.post("/mytest")
|
| 41 |
+
def post_mytest(username: str = Form(""), password: str = Form("")):
|
| 42 |
+
try:
|
| 43 |
+
# business logic
|
| 44 |
+
data = {
|
| 45 |
+
"username": username,
|
| 46 |
+
"password": password
|
| 47 |
+
}
|
| 48 |
+
return CommonResponse(success=True, data=data)
|
| 49 |
+
except Exception as e:
|
| 50 |
+
return CommonResponse(success=False, msg=str(e))
|
| 51 |
+
|
| 52 |
+
@router.post("/upload")
|
| 53 |
+
async def upload_file(file: UploadFile = File(...)):
|
| 54 |
+
try:
|
| 55 |
+
# business logic
|
| 56 |
+
contents = await file.read()
|
| 57 |
+
data = {
|
| 58 |
+
"filename": file.filename,
|
| 59 |
+
"content_type": file.content_type,
|
| 60 |
+
"size": len(contents)
|
| 61 |
+
}
|
| 62 |
+
return CommonResponse(success=True, data=data)
|
| 63 |
+
except Exception as e:
|
| 64 |
+
return CommonResponse(success=False, msg=str(e))
|
utils/common.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Generic, TypeVar, Any, Optional
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
|
| 4 |
+
T = TypeVar("T")
|
| 5 |
+
|
| 6 |
+
class CommonResponse(BaseModel, Generic[T]):
|
| 7 |
+
success: bool=True
|
| 8 |
+
data: Optional[T] = None
|
| 9 |
+
msg: str = ""
|