Skip to content

Commit

Permalink
♻️ REFACTOR: predict 함수 수정
Browse files Browse the repository at this point in the history
- 자연어 처리 결과물 적재 해소
  • Loading branch information
yjsmk0902 committed May 28, 2024
1 parent 54b6830 commit 0304c1d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from flask import Flask, request, jsonify
import os
from ultralytics import YOLO
import requests
from PIL import Image

# Flask 애플리케이션 초기화
Expand Down Expand Up @@ -42,15 +41,19 @@ def predict():
# 예측 수행
img = Image.open(file_path)
results = model.predict(img) # 이미지 객체를 사용하여 예측
os.remove(file_path)

# 결과 처리 및 텍스트 파일로 저장
result_txt_path = os.path.join(app.config['UPLOAD_FOLDER'], RESULT_TEXT_FILE)
results[0].save_txt(result_txt_path) # 첫 번째 결과를 텍스트 파일로 저장
results[0].save(filename='result.jpg')

# 텍스트 파일의 내용을 String으로 변환하고 \n을 공백으로 바꿈
with open(result_txt_path, 'r') as f:
predictions_txt = f.read().replace('\n', ' ')

os.remove(result_txt_path)

return predictions_txt

return jsonify({'error': ERROR_MESSAGE_FILE_UPLOAD_FAILED}), 500
Expand Down

0 comments on commit 0304c1d

Please sign in to comment.