test successed next step to implement in gradio app

This commit is contained in:
Jaikinator
2023-11-17 14:12:53 +01:00
parent fafe5c2709
commit 105161b6a6
+15 -4
View File
@@ -1,3 +1,4 @@
import os
import time import time
from scraibe import Scraibe from scraibe import Scraibe
@@ -22,29 +23,38 @@ def model_thread():
last_used = time.time() last_used = time.time()
def interaction_thread(): def interaction_thread():
global model global model, model_runner
while True: while True:
command = input("Enter a command ('q' to quit, 'reload' to reload model): ") command = input("Enter a command ('q' to quit, 'reload' to reload model): ")
print("Command entered:", command, command.lower() == 'reload')
if command.lower() == 'q': if command.lower() == 'q':
break break
elif command.lower() == 'reload': elif command.lower() == 'reload':
print("Reloading model...", model) print("Reloading model...", model)
if model is None: if model is None:
transcribe_active.clear() #black magic
model_runner = threading.Thread(target=model_thread) model_runner = threading.Thread(target=model_thread)
model_runner.start() model_runner.start()
model_runner.join() model_runner.join()
else: else:
print("Model is already loaded.") print("Model is already loaded.")
else: else:
if os.path.exists(command):
transcribe = threading.Thread(target=transcribe_thread, args=(command,)) transcribe = threading.Thread(target=transcribe_thread, args=(command,))
transcribe.start() transcribe.start()
transcribe.join() transcribe.join()
else:
print("File does not exist.")
def delete_unused_model(model_runner): def delete_unused_model(model_runner):
global model, last_used, transcribe_active global model, last_used, transcribe_active
while True: while True:
if not transcribe_active.is_set() and (time.time() - last_used > 30) and model is not None: print("Checking for unused model...", transcribe_active.is_set())
_unload_porperty = (not transcribe_active.is_set() and (time.time() - last_used > 30) and model is not None)
if _unload_porperty:
del model del model
model = None model = None
@@ -53,8 +63,9 @@ def delete_unused_model(model_runner):
torch.cuda.empty_cache() torch.cuda.empty_cache()
model_runner.join() model_runner.join()
print("Model deleted", threading.active_count()) print("Model deleted", threading.active_count())
time.sleep(1) time.sleep(10)
if __name__ == "__main__": if __name__ == "__main__":