Spaces:
Sleeping
Sleeping
Commit
·
67868c4
1
Parent(s):
91195cf
Added route to support stop running transcription
Browse files- ASR_Server.py +28 -1
ASR_Server.py
CHANGED
|
@@ -22,6 +22,9 @@ import timeit
|
|
| 22 |
cpu_score = timeit.timeit("sum(range(1000000))", number=5)
|
| 23 |
print(f"🧠 CPU benchmark score: {cpu_score:.2f}")
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
job_status = {
|
| 27 |
"running": False,
|
|
@@ -56,6 +59,7 @@ def generateTranscript(ASR_model):
|
|
| 56 |
from datetime import datetime
|
| 57 |
import traceback
|
| 58 |
|
|
|
|
| 59 |
job_status.update({
|
| 60 |
"running": True,
|
| 61 |
"model": ASR_model,
|
|
@@ -125,6 +129,21 @@ def generateTranscript(ASR_model):
|
|
| 125 |
rtfx_score = []
|
| 126 |
|
| 127 |
for idx, row in tqdm.tqdm(df.iterrows(), total=len(df)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
filename = row[filename_column] + ".wav"
|
| 129 |
|
| 130 |
if filename in dataset_map:
|
|
@@ -246,6 +265,13 @@ def asr_models():
|
|
| 246 |
def get_status():
|
| 247 |
return jsonify(job_status)
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
@app.route('/api', methods=['GET'])
|
| 250 |
def api():
|
| 251 |
model = request.args.get('ASR_model', default="", type=str)
|
|
@@ -291,7 +317,7 @@ def api():
|
|
| 291 |
job_status["error_trace"] = None
|
| 292 |
|
| 293 |
return jsonify({
|
| 294 |
-
'message': "Transcription failed
|
| 295 |
'error': error_msg,
|
| 296 |
'error_trace': error_trace,
|
| 297 |
'status': job_status,
|
|
@@ -305,6 +331,7 @@ def api():
|
|
| 305 |
# Start the transcript generation in a separate thread
|
| 306 |
# thread = threading.Thread(target=generateTranscript, args=(model,), daemon=True)
|
| 307 |
thread = threading.Thread(target=generateTranscript, args=(model,))
|
|
|
|
| 308 |
thread.start()
|
| 309 |
|
| 310 |
return response
|
|
|
|
| 22 |
cpu_score = timeit.timeit("sum(range(1000000))", number=5)
|
| 23 |
print(f"🧠 CPU benchmark score: {cpu_score:.2f}")
|
| 24 |
|
| 25 |
+
# Vars for stopping running transcription:
|
| 26 |
+
stop_transcription_flag = {"active": False}
|
| 27 |
+
current_thread = {"thread": None}
|
| 28 |
|
| 29 |
job_status = {
|
| 30 |
"running": False,
|
|
|
|
| 59 |
from datetime import datetime
|
| 60 |
import traceback
|
| 61 |
|
| 62 |
+
stop_transcription_flag["active"] = False
|
| 63 |
job_status.update({
|
| 64 |
"running": True,
|
| 65 |
"model": ASR_model,
|
|
|
|
| 129 |
rtfx_score = []
|
| 130 |
|
| 131 |
for idx, row in tqdm.tqdm(df.iterrows(), total=len(df)):
|
| 132 |
+
#------------------------------------------
|
| 133 |
+
if stop_transcription_flag.get("active", False):
|
| 134 |
+
job_status.update({
|
| 135 |
+
"running": False,
|
| 136 |
+
"model": None,
|
| 137 |
+
"message": "Transcription cancelled by user.",
|
| 138 |
+
"error": None,
|
| 139 |
+
"error_trace": None,
|
| 140 |
+
"completed": idx,
|
| 141 |
+
"%_completed": (idx + 1) * 100 / total,
|
| 142 |
+
"total": total
|
| 143 |
+
})
|
| 144 |
+
print("🛑 Transcription cancelled by user request.")
|
| 145 |
+
return
|
| 146 |
+
#----------------------------------------------------------
|
| 147 |
filename = row[filename_column] + ".wav"
|
| 148 |
|
| 149 |
if filename in dataset_map:
|
|
|
|
| 265 |
def get_status():
|
| 266 |
return jsonify(job_status)
|
| 267 |
|
| 268 |
+
@app.route('/api/stop', methods=['GET'])
|
| 269 |
+
def stop_transcription():
|
| 270 |
+
global stop_transcription_flag
|
| 271 |
+
stop_transcription_flag["active"] = True
|
| 272 |
+
return jsonify({"message": "Stop requested. The running transcription will terminate soon or as soon as possible."})
|
| 273 |
+
|
| 274 |
+
|
| 275 |
@app.route('/api', methods=['GET'])
|
| 276 |
def api():
|
| 277 |
model = request.args.get('ASR_model', default="", type=str)
|
|
|
|
| 317 |
job_status["error_trace"] = None
|
| 318 |
|
| 319 |
return jsonify({
|
| 320 |
+
'message': f"Transcription failed (Kindly do not run this model again, untill we fix the issue): {error_msg}",
|
| 321 |
'error': error_msg,
|
| 322 |
'error_trace': error_trace,
|
| 323 |
'status': job_status,
|
|
|
|
| 331 |
# Start the transcript generation in a separate thread
|
| 332 |
# thread = threading.Thread(target=generateTranscript, args=(model,), daemon=True)
|
| 333 |
thread = threading.Thread(target=generateTranscript, args=(model,))
|
| 334 |
+
current_thread["thread"] = thread
|
| 335 |
thread.start()
|
| 336 |
|
| 337 |
return response
|