-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
36 lines (29 loc) · 1.36 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from flask import Flask, request, url_for, redirect, render_template
from googletrans import Translator
app = Flask(__name__)
translator = Translator()
@app.route("/", methods=['POST', 'GET'])
def home():
if request.method == 'POST':
try:
text_to_translate = request.form["text-to-translate"].lower()
selected_language = request.form["select-language"]
translated_text = translator.translate(
text_to_translate, dest=selected_language)
text = translated_text.text
pronunciation_data = translated_text.pronunciation
if (str(pronunciation_data) == "None"):
pronunciation_data = "{Sorry, data not available}"
confidence = round((translator.translate(
text_to_translate, dest=selected_language).extra_data["confidence"])*100, 2)
except:
pronunciation_data = "-"
text = "{ERROR: We are not able to handle your request right now}"
confidence = "-"
return render_template('index.html', translation_result=text, pronunciation=pronunciation_data, confidence_level=str(confidence)+" %")
return render_template("index.html")
@app.route("/team")
def team():
return render_template("team.html")
if __name__ == "__main__":
app.run("0.0.0.0", debug=True)