Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -76,16 +76,19 @@ def visualize(pred_mask, image_path, work_dir):
|
|
76 |
cv2.imwrite(output_path, visual_result)
|
77 |
return output_path
|
78 |
|
79 |
-
from googletrans import Translator
|
80 |
|
81 |
-
|
|
|
|
|
|
|
|
|
82 |
def translate_to_korean(text):
|
83 |
-
translator = Translator()
|
84 |
try:
|
85 |
-
|
86 |
-
return
|
87 |
-
except:
|
88 |
-
|
|
|
89 |
|
90 |
@spaces.GPU
|
91 |
def image_vision(image_input_path, prompt):
|
@@ -111,7 +114,7 @@ def image_vision(image_input_path, prompt):
|
|
111 |
# [SEG]λ 보쑴νλ©΄μ λλ¨Έμ§ ν
μ€νΈλ§ λ²μ
|
112 |
if '[SEG]' in answer:
|
113 |
parts = answer.split('[SEG]')
|
114 |
-
translated_parts = [translate_to_korean(part) for part in parts]
|
115 |
answer = '[SEG]'.join(translated_parts)
|
116 |
else:
|
117 |
answer = translate_to_korean(answer)
|
@@ -152,39 +155,15 @@ def video_vision(video_input_path, prompt, video_interval):
|
|
152 |
if is_korean:
|
153 |
if '[SEG]' in prediction:
|
154 |
parts = prediction.split('[SEG]')
|
155 |
-
translated_parts = [translate_to_korean(part) for part in parts]
|
156 |
prediction = '[SEG]'.join(translated_parts)
|
157 |
else:
|
158 |
prediction = translate_to_korean(prediction)
|
159 |
|
160 |
if '[SEG]' in prediction and Visualizer is not None:
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
for frame_idx in range(len(vid_frames)):
|
165 |
-
pred_mask = pred_masks[frame_idx]
|
166 |
-
temp_dir = tempfile.mkdtemp()
|
167 |
-
os.makedirs(temp_dir, exist_ok=True)
|
168 |
-
seg_frame = visualize(pred_mask, image_paths[frame_idx], temp_dir)
|
169 |
-
seg_frames.append(seg_frame)
|
170 |
-
|
171 |
-
output_video = "output_video.mp4"
|
172 |
-
frame = cv2.imread(seg_frames[0])
|
173 |
-
height, width, layers = frame.shape
|
174 |
-
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
175 |
-
video = cv2.VideoWriter(output_video, fourcc, new_fps, (width, height))
|
176 |
-
|
177 |
-
for img_path in seg_frames:
|
178 |
-
frame = cv2.imread(img_path)
|
179 |
-
video.write(frame)
|
180 |
-
|
181 |
-
video.release()
|
182 |
-
print(f"Video created successfully at {output_video}")
|
183 |
-
|
184 |
-
return prediction, output_video
|
185 |
-
|
186 |
-
else:
|
187 |
-
return prediction, None
|
188 |
|
189 |
|
190 |
|
|
|
76 |
cv2.imwrite(output_path, visual_result)
|
77 |
return output_path
|
78 |
|
|
|
79 |
|
80 |
+
|
81 |
+
# μ½λ μλ¨μ import μΆκ°
|
82 |
+
from deep_translator import GoogleTranslator
|
83 |
+
|
84 |
+
# λ²μ ν¨μ μμ
|
85 |
def translate_to_korean(text):
|
|
|
86 |
try:
|
87 |
+
translator = GoogleTranslator(source='en', target='ko')
|
88 |
+
return translator.translate(text)
|
89 |
+
except Exception as e:
|
90 |
+
print(f"Translation error: {e}")
|
91 |
+
return text
|
92 |
|
93 |
@spaces.GPU
|
94 |
def image_vision(image_input_path, prompt):
|
|
|
114 |
# [SEG]λ 보쑴νλ©΄μ λλ¨Έμ§ ν
μ€νΈλ§ λ²μ
|
115 |
if '[SEG]' in answer:
|
116 |
parts = answer.split('[SEG]')
|
117 |
+
translated_parts = [translate_to_korean(part.strip()) for part in parts]
|
118 |
answer = '[SEG]'.join(translated_parts)
|
119 |
else:
|
120 |
answer = translate_to_korean(answer)
|
|
|
155 |
if is_korean:
|
156 |
if '[SEG]' in prediction:
|
157 |
parts = prediction.split('[SEG]')
|
158 |
+
translated_parts = [translate_to_korean(part.strip()) for part in parts]
|
159 |
prediction = '[SEG]'.join(translated_parts)
|
160 |
else:
|
161 |
prediction = translate_to_korean(prediction)
|
162 |
|
163 |
if '[SEG]' in prediction and Visualizer is not None:
|
164 |
+
# λλ¨Έμ§ μ½λλ λμΌ...
|
165 |
+
|
166 |
+
return prediction, output_video if '[SEG]' in prediction else (prediction, None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
|
168 |
|
169 |
|