This repository was archived by the owner on May 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
50 lines (37 loc) · 1.56 KB
/
app.py
File metadata and controls
50 lines (37 loc) · 1.56 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from flask import Flask, render_template, request, redirect
from audio.speech_translator import SpeechTranslator
from azure.storage.blob import BlobServiceClient
from utils.config import (
CS_SUBSCRIPTION_KEY,
CS_REGION,
STORAGE_CONNECTION_STRING,
STORAGE_CONTAINER,
)
speech_translator = SpeechTranslator(
subscription_key=CS_SUBSCRIPTION_KEY, region=CS_REGION
)
blob_service_client = BlobServiceClient.from_connection_string(STORAGE_CONNECTION_STRING)
container_client = blob_service_client.get_container_client(STORAGE_CONTAINER)
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def index():
transcript = ""
if request.method == "POST":
audio_lang, target_lang = request.form.get('language_from'), request.form.get('language_to')
file = request.files.get("file", None)
if file is None:
return redirect(request.url)
elif file.filename == "":
return redirect(request.url)
blob_client = blob_service_client.get_blob_client(
container=STORAGE_CONTAINER, blob=file.filename
)
blob_client.upload_blob(file)
blob_client = container_client.get_blob_client(file.filename)
with open(file.filename, "wb") as f:
data = blob_client.download_blob()
data.readinto(f)
transcript = speech_translator.translate_audio(file.filename, audio_lang, target_lang)
return render_template("index.html", transcript=transcript)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=80, debug=True, threaded=True)