-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
76 lines (56 loc) · 1.89 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import flask
from flask import Flask, flash, request, redirect, url_for, request
from werkzeug.utils import secure_filename
import json
import os
from whisper_functions import download, transcribe
from summarize import summarize_single, group_sentences
app = Flask(__name__)
@app.route("/")
def hello_world():
return app.send_static_file('index.html')
@app.route("/g_url", methods=['GET'])
def do_link_transcription():
args = request.args
url = args.get('url')
unique = hash(url)
path = 'tmp/' + str(unique) + '.wav'
try:
download(url, path)
if os.path.exists(path):
text = transcribe(path)
groups = '\n'.join(group_sentences(text))
os.remove(path)
return groups, 200, {'Content-Type': 'text/plain; charset=utf-8'}
except:
pass
return 'Download Error', 500
@app.route("/upload_file", methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
try:
file = request.files['file']
path = "tmp/" + str(hash(file.filename))
file.save(path)
if os.path.exists(path):
text = transcribe(path)
groups = '\n'.join(group_sentences(text))
os.remove(path)
return groups, 200, {'Content-Type': 'text/plain; charset=utf-8'}
except:
pass
return 'Upload Error', 500
return '''
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form action="http://localhost:5000/upload_file" method=POST enctype = "multipart/form-data">
<input type=file name=file>
<input type=submit>
</form>
'''
@app.route("/s_text", methods=['POST'])
def do_text_summarization():
text = request.data.decode('utf-8')
summary = summarize_single(text)
return summary, 200, {'Content-Type': 'text/plain; charset=utf-8'}