Repository navigation
Expand file tree
/
Copy pathpythonClientApp.py
More file actions
79 lines (62 loc) · 2.65 KB
/
Copy pathpythonClientApp.py
File metadata and controls
79 lines (62 loc) · 2.65 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
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)
def processInputFile():
opResponseObj = clntApp.processAudioFile()
jsonStr = json.dumps(opResponseObj, ensure_ascii=False).encode('utf8')
# print(jsonStr.decode())
return (jsonStr.decode())
# return Response()
if __name__ == "__main__":
clntApp = ClientService()
outputVal = processInputFile()
print(outputVal)