Spaces:
Building
Building
Update src/main.py
Browse files- src/main.py +29 -24
src/main.py
CHANGED
@@ -128,6 +128,7 @@ def translate_korean_to_english(text: str) -> str:
|
|
128 |
text = normalize_quotes(text)
|
129 |
|
130 |
if is_english(text):
|
|
|
131 |
quoted_match = re.search(r"'([^']*)'", text)
|
132 |
if quoted_match:
|
133 |
quoted_word = quoted_match.group(1).upper()
|
@@ -189,7 +190,6 @@ def generate_complete_video(gloss_list: List[str], dataset: Dict[str, Any], list
|
|
189 |
|
190 |
height, width = frames[0].shape[:2]
|
191 |
|
192 |
-
# 임시 파일 처리 최적화
|
193 |
with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as temp_file:
|
194 |
temp_path = temp_file.name
|
195 |
|
@@ -216,6 +216,7 @@ def result():
|
|
216 |
if request.method == 'POST':
|
217 |
input_text = request.form['inputSentence'].strip()
|
218 |
if not input_text:
|
|
|
219 |
return render_template('error.html', error="Please enter text to translate")
|
220 |
|
221 |
try:
|
@@ -234,7 +235,7 @@ def result():
|
|
234 |
|
235 |
generated_gloss = executor.submit(process_nlp).result()
|
236 |
|
237 |
-
#
|
238 |
processed_gloss = []
|
239 |
words = generated_gloss.split()
|
240 |
|
@@ -248,41 +249,43 @@ def result():
|
|
248 |
|
249 |
gloss_sentence_before_synonym = " ".join(processed_gloss)
|
250 |
|
251 |
-
# 동의어 처리
|
252 |
final_gloss = []
|
253 |
i = 0
|
254 |
while i < len(processed_gloss):
|
255 |
if processed_gloss[i] == 'FINGERSPELL-START':
|
256 |
-
|
|
|
257 |
i += 2
|
258 |
while i < len(processed_gloss) and processed_gloss[i] != 'FINGERSPELL-END':
|
259 |
final_gloss.append(processed_gloss[i])
|
260 |
i += 1
|
261 |
if i < len(processed_gloss):
|
262 |
-
final_gloss.append(processed_gloss[i])
|
263 |
i += 1
|
264 |
else:
|
265 |
word = processed_gloss[i]
|
266 |
-
# 동의어 찾기를 스레드 풀에서
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
)
|
276 |
i += 1
|
277 |
|
278 |
gloss_sentence_after_synonym = " ".join(final_gloss)
|
279 |
|
280 |
-
return render_template(
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
|
|
|
|
286 |
|
287 |
except Exception as e:
|
288 |
logger.error(f"Translation processing error: {str(e)}")
|
@@ -292,8 +295,10 @@ def result():
|
|
292 |
def video_feed():
|
293 |
sentence = request.args.get('gloss_sentence_to_display', '')
|
294 |
gloss_list = sentence.split()
|
295 |
-
return Response(
|
296 |
-
|
|
|
|
|
297 |
|
298 |
@app.route('/download_video/<path:gloss_sentence>')
|
299 |
def download_video(gloss_sentence: str):
|
@@ -320,4 +325,4 @@ def download_video(gloss_sentence: str):
|
|
320 |
return f"Error downloading video: {str(e)}", 500
|
321 |
|
322 |
if __name__ == "__main__":
|
323 |
-
app.run(host="0.0.0.0", port=7860, debug=True)
|
|
|
128 |
text = normalize_quotes(text)
|
129 |
|
130 |
if is_english(text):
|
131 |
+
# 영어 문장 안의 작은따옴표 단어를 대문자로 바꿔주는 처리
|
132 |
quoted_match = re.search(r"'([^']*)'", text)
|
133 |
if quoted_match:
|
134 |
quoted_word = quoted_match.group(1).upper()
|
|
|
190 |
|
191 |
height, width = frames[0].shape[:2]
|
192 |
|
|
|
193 |
with tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) as temp_file:
|
194 |
temp_path = temp_file.name
|
195 |
|
|
|
216 |
if request.method == 'POST':
|
217 |
input_text = request.form['inputSentence'].strip()
|
218 |
if not input_text:
|
219 |
+
# 에러 페이지로 이동
|
220 |
return render_template('error.html', error="Please enter text to translate")
|
221 |
|
222 |
try:
|
|
|
235 |
|
236 |
generated_gloss = executor.submit(process_nlp).result()
|
237 |
|
238 |
+
# 작은따옴표 처리(지정된 영단어는 fingerspell로 변환)
|
239 |
processed_gloss = []
|
240 |
words = generated_gloss.split()
|
241 |
|
|
|
249 |
|
250 |
gloss_sentence_before_synonym = " ".join(processed_gloss)
|
251 |
|
252 |
+
# 동의어 처리
|
253 |
final_gloss = []
|
254 |
i = 0
|
255 |
while i < len(processed_gloss):
|
256 |
if processed_gloss[i] == 'FINGERSPELL-START':
|
257 |
+
# fingerspell 구간은 그대로 넣는다
|
258 |
+
final_gloss.extend(processed_gloss[i:i+2]) # FINGERSPELL-START + 첫 글자
|
259 |
i += 2
|
260 |
while i < len(processed_gloss) and processed_gloss[i] != 'FINGERSPELL-END':
|
261 |
final_gloss.append(processed_gloss[i])
|
262 |
i += 1
|
263 |
if i < len(processed_gloss):
|
264 |
+
final_gloss.append(processed_gloss[i]) # FINGERSPELL-END
|
265 |
i += 1
|
266 |
else:
|
267 |
word = processed_gloss[i]
|
268 |
+
# 동의어 찾기를 스레드 풀에서 비동기로 실행하여 결과 얻기
|
269 |
+
synonym = executor.submit(
|
270 |
+
sp.find_synonyms,
|
271 |
+
word,
|
272 |
+
nlp,
|
273 |
+
dict_docs_spacy,
|
274 |
+
list_2000_tokens
|
275 |
+
).result()
|
276 |
+
final_gloss.append(synonym)
|
|
|
277 |
i += 1
|
278 |
|
279 |
gloss_sentence_after_synonym = " ".join(final_gloss)
|
280 |
|
281 |
+
return render_template(
|
282 |
+
'result.html',
|
283 |
+
title=app.config['TITLE'],
|
284 |
+
original_sentence=input_text,
|
285 |
+
english_translation=english_text,
|
286 |
+
gloss_sentence_before_synonym=gloss_sentence_before_synonym,
|
287 |
+
gloss_sentence_after_synonym=gloss_sentence_after_synonym
|
288 |
+
)
|
289 |
|
290 |
except Exception as e:
|
291 |
logger.error(f"Translation processing error: {str(e)}")
|
|
|
295 |
def video_feed():
|
296 |
sentence = request.args.get('gloss_sentence_to_display', '')
|
297 |
gloss_list = sentence.split()
|
298 |
+
return Response(
|
299 |
+
dg.generate_video(gloss_list, dataset, list_2000_tokens),
|
300 |
+
mimetype='multipart/x-mixed-replace; boundary=frame'
|
301 |
+
)
|
302 |
|
303 |
@app.route('/download_video/<path:gloss_sentence>')
|
304 |
def download_video(gloss_sentence: str):
|
|
|
325 |
return f"Error downloading video: {str(e)}", 500
|
326 |
|
327 |
if __name__ == "__main__":
|
328 |
+
app.run(host="0.0.0.0", port=7860, debug=True)
|