Repository navigation
Expand file tree
/
Copy pathclientService.py
More file actions
104 lines (83 loc) · 3.46 KB
/
Copy pathclientService.py
File metadata and controls
104 lines (83 loc) · 3.46 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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os
from wsgiref import simple_server
from flask import Flask, request, render_template
from flask import Response
from flask_cors import CORS, cross_origin
import shutil, os
import json
from speech_to_text.transcriptGenerator import generateTranscript
from spellingcorrector.spellcorrector import spell_corrector
from keywordspotter.keywordSpotter import AddMultiKeywords
app = Flask(__name__)
CORS(app)
app.config['DEBUG'] = True
class ClientService:
def __init__(self):
self.FolderPath = "InputFiles"
self.fileList = os.listdir(self.FolderPath)
self.separatedOutputFiles = "./SeparatedOutputFiles"
self.outputText = {}
def processAudioFile(self):
outputResponseObj = {}
for val in self.fileList:
inputFileTranscriptedOp = generateTranscript(os.path.join(self.FolderPath,val), self.separatedOutputFiles)
print(inputFileTranscriptedOp)
outputResponseObj["inputFileTranscriptedOp"] = inputFileTranscriptedOp
spellCorrectedOpMap = {}
for val in inputFileTranscriptedOp.keys():
spellcorrectedOp = spell_corrector(inputFileTranscriptedOp[val])
# print("Input Text : ", outputText[val])
# print("Corrected Text : ", spellcorrectedOp)
spellCorrectedOpMap[val] = spellcorrectedOp
# inputFileTranscriptedOp[val] = spellcorrectedOp
outputResponseObj["spellCorrectedOpMap"] = spellCorrectedOpMap
print(inputFileTranscriptedOp)
extractedKeywordMap = {}
for val in inputFileTranscriptedOp.keys():
adding = AddMultiKeywords(inputFileTranscriptedOp[val],
{"place": ["england"],
"team": ["manchester united"],
"game": ["football"]})
result = adding.addkey()
extractedKeywordMap[val] = result
outputResponseObj["extractedKeywors"] = extractedKeywordMap
return outputResponseObj
inputFileDir = "./InputFiles"
archiveDir = './ArchivedInputFiles'
def archiveOldInputFiles():
files = os.listdir(inputFileDir)
for f in files:
if os.path.exists(os.path.join(archiveDir, f)):
os.remove(os.path.join(archiveDir, f))
shutil.move(os.path.join(inputFileDir, f), archiveDir)
@app.route("/", methods=["GET"])
def homePage():
return render_template("index.html")
@app.route("/upload", methods=["POST"])
def getInputFIle():
opReap = {}
try:
inputFile = request.files.get('file')
archiveOldInputFiles()
inputFile.save(os.path.join("InputFiles", inputFile.filename))
except Exception as e:
opReap["outputError"] = str(e)
jsonStr = json.dumps(opReap, ensure_ascii=False).encode('utf8')
return Response(jsonStr.decode())
opReap["output"] = "Successfully uploaded the file"
jsonStr = json.dumps(opReap, ensure_ascii=False).encode('utf8')
return Response(jsonStr.decode())
@app.route("/startprocessing", methods=["POST"])
def processInputFile():
opResponseObj = clntApp.processAudioFile()
jsonStr = json.dumps(opResponseObj, ensure_ascii=False).encode('utf8')
# print(jsonStr.decode())
return Response(jsonStr.decode())
# return Response()
if __name__ == "__main__":
clntApp = ClientService()
host = '0.0.0.0'
port = 5000
httpd = simple_server.make_server(host, port, app)
print("Serving on %s %d" % (host, port))
httpd.serve_forever()