Spaces:
Sleeping
Sleeping
img binaries
Browse files
main.py
CHANGED
@@ -3,6 +3,7 @@ import io
|
|
3 |
import os
|
4 |
from ctypes import c_int, pointer, string_at
|
5 |
from datetime import datetime
|
|
|
6 |
|
7 |
import cv2
|
8 |
import numpy as np
|
@@ -73,7 +74,7 @@ def load_dependencies():
|
|
73 |
|
74 |
|
75 |
@app.post("/analyze/")
|
76 |
-
async def analyze_image(
|
77 |
progress = print
|
78 |
global trocr_pipeline
|
79 |
# モデルが読み込まれているか確認
|
@@ -85,7 +86,7 @@ async def analyze_image(image_paths: UploadFile):
|
|
85 |
return
|
86 |
|
87 |
all_results = []
|
88 |
-
num_total_files = len(
|
89 |
|
90 |
progress(0, desc="テンプレート画像読み込み中...")
|
91 |
suit_templates = load_suit_templates(SUIT_TEMPLATE_PATH)
|
@@ -99,7 +100,7 @@ async def analyze_image(image_paths: UploadFile):
|
|
99 |
processed_files_info = []
|
100 |
# image_objects = {}
|
101 |
|
102 |
-
for i, image_path in enumerate(
|
103 |
progress(
|
104 |
(i + 1) / num_total_files * 0.15,
|
105 |
desc="ステージ1/3: 文字候補を検出中...",
|
@@ -112,11 +113,12 @@ async def analyze_image(image_paths: UploadFile):
|
|
112 |
|
113 |
try:
|
114 |
# ファイルをバイナリモードで安全に読み込む
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
120 |
# NumPy配列(メモリ上のデータ)から画像をデコード
|
121 |
image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
|
122 |
|
@@ -221,7 +223,7 @@ async def analyze_image(image_paths: UploadFile):
|
|
221 |
# else:
|
222 |
# export_update = gr.update(interactive=False)
|
223 |
final_result = all_results[0]["hands"]
|
224 |
-
filenames = [os.path.basename(p) for p in
|
225 |
# dropdown_update = gr.update(
|
226 |
# choices=filenames, value=filenames[0], interactive=True, open=True
|
227 |
# )
|
|
|
3 |
import os
|
4 |
from ctypes import c_int, pointer, string_at
|
5 |
from datetime import datetime
|
6 |
+
from typing import List
|
7 |
|
8 |
import cv2
|
9 |
import numpy as np
|
|
|
74 |
|
75 |
|
76 |
@app.post("/analyze/")
|
77 |
+
async def analyze_image(image_binaries: List[UploadFile]):
|
78 |
progress = print
|
79 |
global trocr_pipeline
|
80 |
# モデルが読み込まれているか確認
|
|
|
86 |
return
|
87 |
|
88 |
all_results = []
|
89 |
+
num_total_files = len(image_binaries)
|
90 |
|
91 |
progress(0, desc="テンプレート画像読み込み中...")
|
92 |
suit_templates = load_suit_templates(SUIT_TEMPLATE_PATH)
|
|
|
100 |
processed_files_info = []
|
101 |
# image_objects = {}
|
102 |
|
103 |
+
for i, image_path in enumerate(image_binaries):
|
104 |
progress(
|
105 |
(i + 1) / num_total_files * 0.15,
|
106 |
desc="ステージ1/3: 文字候補を検出中...",
|
|
|
113 |
|
114 |
try:
|
115 |
# ファイルをバイナリモードで安全に読み込む
|
116 |
+
file_bytes = np.asarray(bytearray(image_path))
|
117 |
+
# with open(image_path, "rb") as f:
|
118 |
+
# # バイトデータをNumPy配列に変換
|
119 |
+
# file_bytes = np.asarray(
|
120 |
+
# bytearray(f.read()), dtype=np.uint8
|
121 |
+
# )
|
122 |
# NumPy配列(メモリ上のデータ)から画像をデコード
|
123 |
image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
|
124 |
|
|
|
223 |
# else:
|
224 |
# export_update = gr.update(interactive=False)
|
225 |
final_result = all_results[0]["hands"]
|
226 |
+
filenames = [os.path.basename(p) for p in image_binaries]
|
227 |
# dropdown_update = gr.update(
|
228 |
# choices=filenames, value=filenames[0], interactive=True, open=True
|
229 |
# )
|