Skip to content

Commit

Permalink
Merge pull request #19 from JuergenFleiss/Frontend_Connection
Browse files Browse the repository at this point in the history
aTrain_core v. 1.2.0
  • Loading branch information
andreafooo authored Oct 10, 2024
2 parents b5269d2 + 3c79439 commit ddfcbe7
Show file tree
Hide file tree
Showing 18 changed files with 3,681 additions and 580 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ aTrain_core.egg-info
installer.iss
prepare_msix.py
.DS_Store
test.py
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
recursive-include aTrain_core/models *
include aTrain_core/ffmpeg*
recursive-include aTrain_core/models *
70 changes: 70 additions & 0 deletions aTrain_core/GUI_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import json
import os
from multiprocessing import Queue
from queue import Full
from typing import List


class EventSender:
def __init__(self, maxsize: int = 10):
self.listeners: List[Queue] = []
self.maxsize: int = maxsize

def stream(self):
listener = Queue(maxsize=self.maxsize)
self.listeners.append(listener)
while True:
event = listener.get()
if event == "stop":
break
yield event

def end_stream(self):
self.__send(data=None, event=None, stop=True)

def __send(self, data, event, stop: bool = False):
event_string = f"event: {event}\ndata: {data}\n\n" if not stop else "stop"
for i in reversed(range(len(self.listeners))):
try:
self.listeners[i].put_nowait(event_string)
except Full:
del self.listeners[i]

def task_info(self, task: str):
"""Send the current task to the frontend for display during transcription."""
self.__send(data=task, event="task")

def error_info(self, error: str, traceback: str = ""):
"""Send an error message to the frontend for display during transcription."""
error_data = json.dumps({"error": error, "traceback": traceback})
self.__send(data=error_data, event="error")

def progress_info(self, current: int, total: int):
"""Send a progress update to the frontend for diplay during transcription."""
progress_data = json.dumps({"current": current, "total": total})
self.__send(data=progress_data, event="progress")

def finished_info(self):
"""Send an event to the frond to inidcate that a process has finished."""
self.__send(data="", event="finished")


class ProgressTracker:
def __init__(self, total_chunks):
self.total_chunks = total_chunks
self.completed_chunks = 0
self.progress_data = []

def progress_callback(self, current_chunk):
self.completed_chunks += 1
overall_progress = (self.completed_chunks / self.total_chunks) * 100
progress_info = {
"current": self.completed_chunks,
"total": self.total_chunks,
"percentage": overall_progress,
}
self.progress_data.append(progress_info)
return progress_info

def get_progress(self):
return self.progress_data
2 changes: 1 addition & 1 deletion aTrain_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .cli import cli
from .load_resources import download_all_resources
from .load_resources import download_all_models
2 changes: 1 addition & 1 deletion aTrain_core/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .cli import cli

if __name__ == "__main__":
cli()
cli()
Loading

0 comments on commit ddfcbe7

Please sign in to comment.