-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
47 lines (35 loc) ยท 1.14 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import shutil
import uvicorn
import configparser
import torch.utils.data
from fastapi import FastAPI, UploadFile
import tensorflow as tf
from food_detection import detect_and_crop_image
from food_recognition import predict_food
app = FastAPI(max_request_size = 1024*1024*1024)
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model_path = tf.keras.models.load_model('./food_recognition_model2.h5')
# ์๋ฒ ์ฃผ์ ๋ฐ์์ค๊ธฐ
config = configparser.ConfigParser()
config.read('config.ini')
host = config.get('server', 'host')
port = config.getint('server', 'port')
@app.get("/")
async def root():
return {"message": f"Server running on {host}:{port}"}
@app.post("/api/v1/analyze/image")
async def preprocess_image(image: UploadFile):
# ์๋ฅธ ์ด๋ฏธ์ง๋ฅผ ์ ์ฅํ ๋๋ ํ ๋ฆฌ ์์ฑ
dir_name = "crop"
print("*")
if os.path.exists(dir_name):
shutil.rmtree(dir_name)
os.mkdir(dir_name)
detect_and_crop_image(image, dir_name)
food_name = predict_food()
print(food_name)
return food_name
if __name__ == '__main__':
print(host)
uvicorn.run(app, host=host, port=port)