Merry99 commited on
Commit
37d20cf
ยท
1 Parent(s): a67f94d

Fast API Server init

Browse files
Files changed (4) hide show
  1. .dockerignore +20 -0
  2. Dockerfile +23 -0
  3. app.py +63 -0
  4. requirements.txt +5 -0
.dockerignore ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__
2
+ *.pyc
3
+ *.pyo
4
+ *.pyd
5
+ .Python
6
+ *.so
7
+ *.egg
8
+ *.egg-info
9
+ dist
10
+ build
11
+ .git
12
+ .gitignore
13
+ .vscode
14
+ .idea
15
+ *.log
16
+ .DS_Store
17
+ venv
18
+ env
19
+ .env
20
+
Dockerfile ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ # ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ ์„ค์ •
4
+ WORKDIR /app
5
+
6
+ # ์‹œ์Šคํ…œ ํŒจํ‚ค์ง€ ์—…๋ฐ์ดํŠธ ๋ฐ ํ•„์š”ํ•œ ํŒจํ‚ค์ง€ ์„ค์น˜
7
+ RUN apt-get update && apt-get install -y \
8
+ build-essential \
9
+ && rm -rf /var/lib/apt/lists/*
10
+
11
+ # requirements ๋ณต์‚ฌ ๋ฐ ์„ค์น˜
12
+ COPY requirements.txt .
13
+ RUN pip install --no-cache-dir -r requirements.txt
14
+
15
+ # ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฝ”๋“œ ๋ณต์‚ฌ
16
+ COPY . .
17
+
18
+ # Hugging Face Space๋Š” ํฌํŠธ 7860์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค
19
+ EXPOSE 7860
20
+
21
+ # FastAPI ์„œ๋ฒ„ ์‹คํ–‰
22
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
23
+
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from pydantic import BaseModel
4
+ import uvicorn
5
+
6
+ # FastAPI ์•ฑ ์ƒ์„ฑ
7
+ app = FastAPI(
8
+ title="MuscleCare API",
9
+ description="MuscleCare ํ”ผ๋กœ๋„ ๊ด€๋ฆฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ API",
10
+ version="1.0.0"
11
+ )
12
+
13
+ # CORS ์„ค์ •
14
+ app.add_middleware(
15
+ CORSMiddleware,
16
+ allow_origins=["*"],
17
+ allow_credentials=True,
18
+ allow_methods=["*"],
19
+ allow_headers=["*"],
20
+ )
21
+
22
+
23
+ # ์š”์ฒญ/์‘๋‹ต ๋ชจ๋ธ ์˜ˆ์‹œ
24
+ class HealthCheckResponse(BaseModel):
25
+ status: str
26
+ message: str
27
+
28
+
29
+ # ๊ธฐ๋ณธ ๋ผ์šฐํŠธ
30
+ @app.get("/")
31
+ async def root():
32
+ """
33
+ ๋ฃจํŠธ ์—”๋“œํฌ์ธํŠธ
34
+ """
35
+ return {
36
+ "message": "Welcome to MuscleCare API",
37
+ "status": "running",
38
+ "docs": "/docs"
39
+ }
40
+
41
+
42
+ @app.get("/health", response_model=HealthCheckResponse)
43
+ async def health_check():
44
+ """
45
+ ํ—ฌ์Šค ์ฒดํฌ ์—”๋“œํฌ์ธํŠธ
46
+ """
47
+ return HealthCheckResponse(
48
+ status="healthy",
49
+ message="MuscleCare API is running successfully"
50
+ )
51
+
52
+
53
+ # ์—ฌ๊ธฐ์— ์ถ”๊ฐ€ ์—”๋“œํฌ์ธํŠธ๋ฅผ ์ž‘์„ฑํ•˜์„ธ์š”
54
+ # ์˜ˆ์‹œ:
55
+ # @app.post("/predict")
56
+ # async def predict(data: YourDataModel):
57
+ # # ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง
58
+ # return {"result": "your_result"}
59
+
60
+
61
+ if __name__ == "__main__":
62
+ uvicorn.run(app, host="0.0.0.0", port=7860)
63
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi==0.104.1
2
+ uvicorn[standard]==0.24.0
3
+ pydantic==2.5.0
4
+ python-multipart==0.0.6
5
+