ning8429 commited on
Commit
2beb357
·
verified ·
1 Parent(s): 4ddb23c

Update api_server.py

Browse files
Files changed (1) hide show
  1. api_server.py +8 -3
api_server.py CHANGED
@@ -13,7 +13,7 @@ from tensorflow import keras
13
  from flask import Flask, jsonify, request, render_template, send_file
14
  import torch
15
  from collections import Counter
16
- from clip import clip_result
17
 
18
  # Disable tensorflow warnings
19
  os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
@@ -76,6 +76,8 @@ def get_jpg_files(path):
76
 
77
  # Initialize the Flask application
78
  app = Flask(__name__)
 
 
79
 
80
 
81
  # API route for prediction(YOLO)
@@ -126,11 +128,14 @@ def predict():
126
  yolo_path = f"{YOLO_DIR}/{message_id}/{element}"
127
  yolo_file = get_jpg_files(yolo_path)
128
 
 
 
129
  element_list.append(element)
130
 
131
  for yolo_img in yolo_file: # 每張切圖yolo_img
132
- top_k_words.append(clip_result(yolo_img)) # CLIP預測3個結果(top_k_words)
133
  encoded_images.append(image_to_base64(yolo_img))
 
134
 
135
  # if element_counts[element] > 1: #某隻角色的數量>1
136
  # yolo_path = f"{YOLO_DIR}/{message_id}/{element}"
@@ -162,7 +167,7 @@ def predict():
162
  # }
163
 
164
  return jsonify(response_data)
165
-
166
  # for label_name in label_names:
167
  # yolo_file=f"{YOLO_DIR}/{message_id}/{label_name}/im.jpg.jpg"
168
  # # 將圖片轉換為 base64 編碼
 
13
  from flask import Flask, jsonify, request, render_template, send_file
14
  import torch
15
  from collections import Counter
16
+ from clip_model import ClipModel
17
 
18
  # Disable tensorflow warnings
19
  os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
 
76
 
77
  # Initialize the Flask application
78
  app = Flask(__name__)
79
+ # Initialize the ClipModel at the start
80
+ clip_model = ClipModel()
81
 
82
 
83
  # API route for prediction(YOLO)
 
128
  yolo_path = f"{YOLO_DIR}/{message_id}/{element}"
129
  yolo_file = get_jpg_files(yolo_path)
130
 
131
+ print(yolo_path)
132
+
133
  element_list.append(element)
134
 
135
  for yolo_img in yolo_file: # 每張切圖yolo_img
136
+ top_k_words.append(clip_model.clip_result(yolo_img)) # CLIP預測3個結果(top_k_words)
137
  encoded_images.append(image_to_base64(yolo_img))
138
+ print(top_k_words)
139
 
140
  # if element_counts[element] > 1: #某隻角色的數量>1
141
  # yolo_path = f"{YOLO_DIR}/{message_id}/{element}"
 
167
  # }
168
 
169
  return jsonify(response_data)
170
+
171
  # for label_name in label_names:
172
  # yolo_file=f"{YOLO_DIR}/{message_id}/{label_name}/im.jpg.jpg"
173
  # # 將圖片轉換為 base64 編碼