Spaces:
Running
Running
Update app.py
Browse filesadded speech logging
app.py
CHANGED
@@ -48,6 +48,7 @@ def genUsageStats(do_reset=False):
|
|
48 |
ttotal4mini_in = 0
|
49 |
ttotal4mini_out = 0
|
50 |
totalAudio = 0
|
|
|
51 |
for user in unames:
|
52 |
tokens4o_in = 0
|
53 |
tokens4o_out = 0
|
@@ -106,18 +107,39 @@ def genUsageStats(do_reset=False):
|
|
106 |
sleep(3)
|
107 |
if not accessOk:
|
108 |
return f'File access failed reading audio stats for user: {user}'
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
return result
|
112 |
|
113 |
def clear():
|
114 |
-
return [None, [], None]
|
115 |
-
|
116 |
-
def updatePassword(txt):
|
117 |
while not qdelete.empty():
|
118 |
fname = qdelete.get()
|
119 |
if os.path.exists(fname):
|
120 |
os.remove(fname)
|
|
|
|
|
|
|
121 |
return [txt.lower().strip(), "*********"]
|
122 |
|
123 |
# def setModel(val):
|
@@ -225,7 +247,7 @@ def speech_worker(chunks=[]):
|
|
225 |
|
226 |
|
227 |
with gr.Blocks() as demo:
|
228 |
-
def initial_audio_output(txt):
|
229 |
global digits
|
230 |
global abbrevs
|
231 |
while not qspeech.empty():
|
@@ -280,6 +302,11 @@ with gr.Blocks() as demo:
|
|
280 |
line = number + chunk
|
281 |
if line != '"':
|
282 |
chunklist.append(line)
|
|
|
|
|
|
|
|
|
|
|
283 |
chunk = chunklist[0]
|
284 |
if chunk.strip() == '':
|
285 |
return gr.Audio(sources=None)
|
@@ -332,7 +359,7 @@ with gr.Blocks() as demo:
|
|
332 |
reset_button.add(audio_widget)
|
333 |
audio_out = gr.Audio(autoplay=True, visible=False)
|
334 |
audio_out.stop(fn=gen_output_audio, inputs=None, outputs = audio_out)
|
335 |
-
speak_output.click(fn=initial_audio_output, inputs=output_window, outputs=audio_out)
|
336 |
output_window.change(fn=set_speak_button, inputs=output_window,outputs=speak_output)
|
337 |
demo.unload(clean_up)
|
338 |
demo.launch(share=True)
|
|
|
48 |
ttotal4mini_in = 0
|
49 |
ttotal4mini_out = 0
|
50 |
totalAudio = 0
|
51 |
+
totalSpeech = 0
|
52 |
for user in unames:
|
53 |
tokens4o_in = 0
|
54 |
tokens4o_out = 0
|
|
|
107 |
sleep(3)
|
108 |
if not accessOk:
|
109 |
return f'File access failed reading audio stats for user: {user}'
|
110 |
+
userSpeech = 0
|
111 |
+
fp = dataDir + user + '_speech.txt'
|
112 |
+
if os.path.exists(fp):
|
113 |
+
accessOk = False
|
114 |
+
for i in range(3):
|
115 |
+
try:
|
116 |
+
with open(fp) as f:
|
117 |
+
dataList = f.readlines()
|
118 |
+
if do_reset:
|
119 |
+
os.remove(fp)
|
120 |
+
else:
|
121 |
+
for line in dataList:
|
122 |
+
(dud, len) = line.split(':')
|
123 |
+
userSpeech += int(len)
|
124 |
+
totalSpeech += int(len)
|
125 |
+
accessOk = True
|
126 |
+
break
|
127 |
+
except:
|
128 |
+
sleep(3)
|
129 |
+
if not accessOk:
|
130 |
+
return f'File access failed reading speech stats for user: {user}'
|
131 |
+
result.append([user, f'{tokens4mini_in}/{tokens4mini_out}', f'{tokens4o_in}/{tokens4o_out}', f'audio:{userAudio}',f'speech:{userSpeech}'])
|
132 |
+
result.append(['totals', f'{ttotal4mini_in}/{ttotal4mini_out}', f'{ttotal4o_in}/{ttotal4o_out}', f'audio:{totalAudio}',f'speech:{totalSpeech}'])
|
133 |
return result
|
134 |
|
135 |
def clear():
|
|
|
|
|
|
|
136 |
while not qdelete.empty():
|
137 |
fname = qdelete.get()
|
138 |
if os.path.exists(fname):
|
139 |
os.remove(fname)
|
140 |
+
return [None, [], None]
|
141 |
+
|
142 |
+
def updatePassword(txt):
|
143 |
return [txt.lower().strip(), "*********"]
|
144 |
|
145 |
# def setModel(val):
|
|
|
247 |
|
248 |
|
249 |
with gr.Blocks() as demo:
|
250 |
+
def initial_audio_output(txt, user):
|
251 |
global digits
|
252 |
global abbrevs
|
253 |
while not qspeech.empty():
|
|
|
302 |
line = number + chunk
|
303 |
if line != '"':
|
304 |
chunklist.append(line)
|
305 |
+
total_speech = 0
|
306 |
+
for chunk in chunklist:
|
307 |
+
total_speech += len(chunk)
|
308 |
+
with open(dataDir + user + '_speech.txt','a') as f:
|
309 |
+
f.write(f'speech:{str(total_speech)}\n')
|
310 |
chunk = chunklist[0]
|
311 |
if chunk.strip() == '':
|
312 |
return gr.Audio(sources=None)
|
|
|
359 |
reset_button.add(audio_widget)
|
360 |
audio_out = gr.Audio(autoplay=True, visible=False)
|
361 |
audio_out.stop(fn=gen_output_audio, inputs=None, outputs = audio_out)
|
362 |
+
speak_output.click(fn=initial_audio_output, inputs=[output_window, user_window], outputs=audio_out)
|
363 |
output_window.change(fn=set_speak_button, inputs=output_window,outputs=speak_output)
|
364 |
demo.unload(clean_up)
|
365 |
demo.launch(share=True)
|