Spaces:
Building
Building
Update src/main.py
Browse files- src/main.py +25 -23
src/main.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
import display_gloss as dg
|
2 |
import synonyms_preprocess as sp
|
3 |
from NLP_Spacy_base_translator import NlpSpacyBaseTranslator
|
4 |
-
from flask import Flask, render_template, Response, request
|
5 |
import requests
|
6 |
|
7 |
-
app = Flask(__name__)
|
|
|
8 |
|
9 |
-
# 데이터 초기화
|
10 |
nlp, dict_docs_spacy = sp.load_spacy_values()
|
11 |
dataset, list_2000_tokens = dg.load_data()
|
12 |
|
@@ -20,33 +20,36 @@ def translate_korean_to_english(text):
|
|
20 |
"q": text
|
21 |
}
|
22 |
response = requests.get(url, params=params)
|
23 |
-
|
24 |
-
return result[0][0][0]
|
25 |
|
26 |
@app.route('/')
|
27 |
def index():
|
28 |
-
return render_template('index.html')
|
29 |
|
30 |
@app.route('/translate/', methods=['POST'])
|
31 |
def result():
|
32 |
if request.method == 'POST':
|
33 |
korean_sentence = request.form['inputSentence']
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
50 |
|
51 |
@app.route('/video_feed')
|
52 |
def video_feed():
|
@@ -56,5 +59,4 @@ def video_feed():
|
|
56 |
mimetype='multipart/x-mixed-replace; boundary=frame')
|
57 |
|
58 |
if __name__ == "__main__":
|
59 |
-
app.debug = True
|
60 |
app.run(host="0.0.0.0", port=5000, debug=True)
|
|
|
1 |
import display_gloss as dg
|
2 |
import synonyms_preprocess as sp
|
3 |
from NLP_Spacy_base_translator import NlpSpacyBaseTranslator
|
4 |
+
from flask import Flask, render_template, Response, request, jsonify
|
5 |
import requests
|
6 |
|
7 |
+
app = Flask(__name__, static_folder='static')
|
8 |
+
app.config['TITLE'] = 'Sign Language Translate'
|
9 |
|
|
|
10 |
nlp, dict_docs_spacy = sp.load_spacy_values()
|
11 |
dataset, list_2000_tokens = dg.load_data()
|
12 |
|
|
|
20 |
"q": text
|
21 |
}
|
22 |
response = requests.get(url, params=params)
|
23 |
+
return response.json()[0][0][0]
|
|
|
24 |
|
25 |
@app.route('/')
|
26 |
def index():
|
27 |
+
return render_template('index.html', title=app.config['TITLE'])
|
28 |
|
29 |
@app.route('/translate/', methods=['POST'])
|
30 |
def result():
|
31 |
if request.method == 'POST':
|
32 |
korean_sentence = request.form['inputSentence']
|
33 |
+
try:
|
34 |
+
english_translation = translate_korean_to_english(korean_sentence)
|
35 |
+
eng_to_asl_translator = NlpSpacyBaseTranslator(sentence=english_translation)
|
36 |
+
generated_gloss = eng_to_asl_translator.translate_to_gloss()
|
37 |
+
|
38 |
+
gloss_list_lower = [gloss.lower() for gloss in generated_gloss.split() if gloss.isalnum()]
|
39 |
+
gloss_sentence_before_synonym = " ".join(gloss_list_lower)
|
40 |
+
|
41 |
+
gloss_list = [sp.find_synonyms(gloss, nlp, dict_docs_spacy, list_2000_tokens)
|
42 |
+
for gloss in gloss_list_lower]
|
43 |
+
gloss_sentence_after_synonym = " ".join(gloss_list)
|
44 |
+
|
45 |
+
return render_template('result.html',
|
46 |
+
title=app.config['TITLE'],
|
47 |
+
original_sentence=korean_sentence,
|
48 |
+
english_translation=english_translation,
|
49 |
+
gloss_sentence_before_synonym=gloss_sentence_before_synonym,
|
50 |
+
gloss_sentence_after_synonym=gloss_sentence_after_synonym)
|
51 |
+
except Exception as e:
|
52 |
+
return render_template('error.html', error=str(e))
|
53 |
|
54 |
@app.route('/video_feed')
|
55 |
def video_feed():
|
|
|
59 |
mimetype='multipart/x-mixed-replace; boundary=frame')
|
60 |
|
61 |
if __name__ == "__main__":
|
|
|
62 |
app.run(host="0.0.0.0", port=5000, debug=True)
|