Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -76,9 +76,20 @@ def visualize(pred_mask, image_path, work_dir):
|
|
| 76 |
cv2.imwrite(output_path, visual_result)
|
| 77 |
return output_path
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
@spaces.GPU
|
| 80 |
def image_vision(image_input_path, prompt):
|
| 81 |
-
#
|
| 82 |
is_korean = any(ord('κ°') <= ord(char) <= ord('ν£') for char in prompt)
|
| 83 |
|
| 84 |
image_path = image_input_path
|
|
@@ -93,18 +104,21 @@ def image_vision(image_input_path, prompt):
|
|
| 93 |
}
|
| 94 |
return_dict = model.predict_forward(**input_dict)
|
| 95 |
print(return_dict)
|
| 96 |
-
answer = return_dict["prediction"]
|
| 97 |
|
| 98 |
-
# νκΈ ν둬ννΈμΈ κ²½μ° μλ΅μ νκΈλ‘
|
| 99 |
if is_korean:
|
| 100 |
-
#
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
seg_image = return_dict["prediction_masks"]
|
| 106 |
|
| 107 |
-
if
|
| 108 |
pred_masks = seg_image[0]
|
| 109 |
temp_dir = tempfile.mkdtemp()
|
| 110 |
pred_mask = pred_masks
|
|
@@ -116,10 +130,9 @@ def image_vision(image_input_path, prompt):
|
|
| 116 |
|
| 117 |
@spaces.GPU(duration=80)
|
| 118 |
def video_vision(video_input_path, prompt, video_interval):
|
| 119 |
-
#
|
| 120 |
is_korean = any(ord('κ°') <= ord(char) <= ord('ν£') for char in prompt)
|
| 121 |
|
| 122 |
-
# Open the original video
|
| 123 |
cap = cv2.VideoCapture(video_input_path)
|
| 124 |
original_fps = cap.get(cv2.CAP_PROP_FPS)
|
| 125 |
frame_skip_factor = video_interval
|
|
@@ -135,13 +148,16 @@ def video_vision(video_input_path, prompt, video_interval):
|
|
| 135 |
prediction = result['prediction']
|
| 136 |
print(prediction)
|
| 137 |
|
| 138 |
-
# νκΈ ν둬ννΈμΈ κ²½μ° μλ΅μ νκΈλ‘
|
| 139 |
if is_korean:
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
| 145 |
_seg_idx = 0
|
| 146 |
pred_masks = result['prediction_masks'][_seg_idx]
|
| 147 |
seg_frames = []
|
|
|
|
| 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 |
+
result = translator.translate(text, dest='ko', src='en')
|
| 86 |
+
return result.text
|
| 87 |
+
except:
|
| 88 |
+
return text # λ²μ μ€ν¨μ μλ³Έ ν
μ€νΈ λ°ν
|
| 89 |
+
|
| 90 |
@spaces.GPU
|
| 91 |
def image_vision(image_input_path, prompt):
|
| 92 |
+
# νκΈ μ
λ ₯ νμΈ
|
| 93 |
is_korean = any(ord('κ°') <= ord(char) <= ord('ν£') for char in prompt)
|
| 94 |
|
| 95 |
image_path = image_input_path
|
|
|
|
| 104 |
}
|
| 105 |
return_dict = model.predict_forward(**input_dict)
|
| 106 |
print(return_dict)
|
| 107 |
+
answer = return_dict["prediction"]
|
| 108 |
|
| 109 |
+
# νκΈ ν둬ννΈμΈ κ²½μ° μλ΅μ νκΈλ‘ λ²μ
|
| 110 |
if is_korean:
|
| 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)
|
| 118 |
|
| 119 |
seg_image = return_dict["prediction_masks"]
|
| 120 |
|
| 121 |
+
if '[SEG]' in answer and Visualizer is not None:
|
| 122 |
pred_masks = seg_image[0]
|
| 123 |
temp_dir = tempfile.mkdtemp()
|
| 124 |
pred_mask = pred_masks
|
|
|
|
| 130 |
|
| 131 |
@spaces.GPU(duration=80)
|
| 132 |
def video_vision(video_input_path, prompt, video_interval):
|
| 133 |
+
# νκΈ μ
λ ₯ νμΈ
|
| 134 |
is_korean = any(ord('κ°') <= ord(char) <= ord('ν£') for char in prompt)
|
| 135 |
|
|
|
|
| 136 |
cap = cv2.VideoCapture(video_input_path)
|
| 137 |
original_fps = cap.get(cv2.CAP_PROP_FPS)
|
| 138 |
frame_skip_factor = video_interval
|
|
|
|
| 148 |
prediction = result['prediction']
|
| 149 |
print(prediction)
|
| 150 |
|
| 151 |
+
# νκΈ ν둬ννΈμΈ κ²½μ° μλ΅μ νκΈλ‘ λ²μ
|
| 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 |
_seg_idx = 0
|
| 162 |
pred_masks = result['prediction_masks'][_seg_idx]
|
| 163 |
seg_frames = []
|