-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (36 loc) · 1.24 KB
/
main.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
37
38
39
40
41
42
43
44
45
from flask import Flask, request
from google.cloud import storage
from transcribe import transcribe_gcs_audio_file
from create_document import create_word_document
import os
app = Flask(__name__)
storage_client = storage.Client()
bucket_name = os.getenv("GCS_AUDIO_BUCKET_NAME")
bucket = storage_client.bucket(bucket_name)
# Return page describing the upload service and how to use it
@app.route("/")
def root():
return """
<h1>Upload an audio file</h1>
<form method="post" action="/upload" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
"""
# This route will be used to upload an audio file to the server
@app.route("/upload", methods=["POST"])
def upload_file():
print(request.files)
if "file" not in request.files:
return "No file part", 400
file = request.files["file"]
if file.filename == "":
return "No selected file", 400
if file:
filename = file.filename
blob = bucket.blob(filename)
blob.upload_from_string(file.read(), content_type=file.content_type)
uri = f"gs://{bucket_name}/{filename}"
return transcribe_gcs_audio_file(uri, filename)
if __name__ == "__main__":
app.run()