Create a working docker setup

This commit is contained in:
Tomasz Frątczak 2024-02-14 21:20:20 +01:00
parent 53102be98b
commit 6eb24e74eb
5 changed files with 30 additions and 13 deletions

10
dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM python
RUN mkdir /app
COPY notescriber /app/notescriber
COPY notescriber.py /app/notescriber.py
COPY requirements.txt /app/requirements.txt
COPY .config.yaml /app/.config.yaml
WORKDIR /app
RUN pip install -r requirements.txt

View File

@ -8,14 +8,11 @@ class Config:
url = None
path = None
def __init__(self):
pass
def parse_args(self):
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--path', type=str, help='Path to config yaml file')
parser.add_argument('--path', type=str, help='Path to config yaml file', dest='path')
args = parser.parse_args()
return args.arg
return args
def load_config(self, path=None):
if path is None:
@ -24,4 +21,7 @@ class Config:
self.username = confFile['username']
self.password = confFile['password']
self.url = confFile['url']
self.path = confFile['path']
self.path = self.parse_args().path
if self.path is None:
self.path = confFile['path']
print(self.path)

View File

@ -1,4 +1,5 @@
import threading
import os
class Dispatcher:
@ -7,9 +8,6 @@ class Dispatcher:
extensionFilter = None
noteGenerator = None
def __init__(self):
pass
def add_audio_processor(self, audioProcessor):
self.audioProcessor = audioProcessor
@ -19,11 +17,12 @@ class Dispatcher:
def process_audio_file(self, audio_file):
self.threads.append(threading.Thread(target=self._execute_thread, args=(audio_file,)))
self.threads[-1].start()
# TODO: we need to have a way to wipe old threads, otherwise we will have a memory leak
# TODO: we need to have a way to wipe old threads, otherwise we may have a memory leak
def _execute_thread(self, audio_file):
filename = os.path.basename(audio_file.pathname)
note = self.audioProcessor.execute(audio_file.pathname)
self.noteGenerator.generate_note(audio_file.pathname, note)
self.noteGenerator.generate_note(filename, note)
def halt(self):
for thread in self.threads:

View File

@ -1,4 +1,5 @@
from nextcloud_notes_api import NotesApi, Note
from datetime import date
class Notetaker:
@ -11,7 +12,13 @@ class Notetaker:
self.password = password
self.url = url
def format_note(self, filename, note):
result = f"# {filename}\n\n"
result += f"-----------------\nTranscription date: {date.today()}\n-----------------\n\n"
result += note
return result
def generate_note(self, filename, note):
api = NotesApi(self.username, self.password, self.url)
ncnote = Note(title=filename, content=note, category="Voicenotes")
ncnote = Note(title=filename, content=self.format_note(filename, note), category="Voicenotes")
api.create_note(ncnote)

View File

@ -2,3 +2,4 @@ openai-whisper==20231117
pyinotify==0.9.6
nextcloud_notes_api==1.0.0
PyYaml==6.0.1
pyasyncore==1.0.3