-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor imports and clean up code formatting in Transcriber.py, main…
….py, and llm/model.py
- Loading branch information
Showing
6 changed files
with
193 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import datetime | ||
|
||
from textual.widgets import Static | ||
from textual.widgets import Static, Footer, TextArea | ||
from textual.screen import Screen | ||
from textual.binding import Binding | ||
from textual import work | ||
|
||
from llm.model import LanguageModel | ||
from notes.manager import NoteManager | ||
|
||
from audio.textual_transcription_textarea import TranscriptionTextArea | ||
|
||
|
||
class NoteTextArea(TextArea): | ||
BINDINGS = [] | ||
|
||
def __init__(self, uuid: str, content: str, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.language = "markdown" | ||
self.note_manager = NoteManager() | ||
self.content = content | ||
self.uuid = uuid | ||
self.text = self.content | ||
|
||
def on_mount(self): | ||
if self.text and len(self.text) > 0: | ||
lines = self.text.split("\n") | ||
self.cursor_location = (len(lines) - 1, len(lines[-1])) | ||
|
||
def on_text_area_changed(self, changed: TextArea.Changed): | ||
self.note_manager.update_note_content(self.uuid, changed.text_area.text) | ||
|
||
|
||
class NoteEditScreen(Screen): | ||
BINDINGS = [ | ||
("escape", "quit", "Quit"), | ||
Binding("ctrl+l", "run_llm", "Run LLM", show=True, priority=True), | ||
] | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.note_manager = NoteManager() | ||
if self.note_manager.selected_note is None: | ||
today = datetime.datetime.now().strftime("%Y-%m-%d") | ||
self.title = today | ||
# add todays date to the title | ||
self.content = f"# Notes {today}\n\n" | ||
self.uuid = self.note_manager.create_note(self.title, self.content) | ||
else: | ||
note = self.note_manager.selected_note | ||
self.title = note["title"] | ||
self.content = self.note_manager.read_note(note["uuid"]) | ||
self.uuid = note["uuid"] | ||
|
||
def compose(self): | ||
yield Static(f"Title: {self.title}") | ||
yield NoteTextArea(self.uuid, self.content, id="note_text") | ||
yield Footer() | ||
|
||
def action_quit(self): | ||
self.app.notify("Note Saved", timeout=1) | ||
new_content = self.query_one("#note_text").text | ||
self.note_manager.update_note_content(self.uuid, new_content) | ||
self.dismiss() | ||
|
||
@work | ||
async def action_run_llm(self): | ||
self.app.notify("Running LLM") | ||
textArea = self.query_one("#note_text") | ||
note_content = textArea.text | ||
textArea.text += f"\n\n# Response\n\n" | ||
for response in LanguageModel().generate_response(note_content): | ||
self.log.info(response) | ||
textArea.text += response | ||
|
||
|
||
class LiveNoteEditScreen(Screen): | ||
BINDINGS = [ | ||
("escape", "quit", "Quit"), | ||
] | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.note_manager = NoteManager() | ||
today = datetime.datetime.now().strftime("%Y-%m-%d") | ||
self.title = today | ||
# add todays date to the title | ||
self.content = f"# Notes {today}\n\n" | ||
self.uuid = self.note_manager.create_note(self.title, self.content) | ||
|
||
def compose(self): | ||
yield Static(f"Title: {self.title}") | ||
yield TranscriptionTextArea(id="Transcription") | ||
text_area = NoteTextArea(self.uuid, self.content, id="note_text") | ||
text_area.focus() | ||
yield text_area | ||
|
||
def action_quit(self): | ||
self.app.notify("Note Saved") | ||
note_content = self.query_one("#note_text").text | ||
transcription = self.query_one("#Transcription").text | ||
combined = f"{note_content}\n\n# Transcription\n\n{transcription}" | ||
self.note_manager.update_note_content(self.uuid, combined) | ||
self.dismiss() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from textual.containers import Grid, Vertical | ||
from textual.widgets import Select, TextArea, Button, Label | ||
from textual.screen import ModalScreen | ||
from textual.message import Message | ||
|
||
class SettingsScreen(ModalScreen): | ||
"""A modal screen for managing LLM settings.""" | ||
|
||
class SettingsChanged(Message): | ||
"""Settings changed message.""" | ||
def __init__(self, prompt: str, model: str) -> None: | ||
self.prompt = prompt | ||
self.model = model | ||
super().__init__() | ||
|
||
def __init__(self, current_prompt: str = "", current_model: str = "gpt-3.5-turbo"): | ||
super().__init__() | ||
self.current_prompt = current_prompt | ||
self.current_model = current_model | ||
|
||
BINDINGS = [("escape", "cancel", "Cancel")] | ||
|
||
def compose(self): | ||
yield Grid( | ||
Vertical( | ||
Label("LLM Settings", id="settings-title", classes="settings-header"), | ||
Label("System Prompt:"), | ||
TextArea( | ||
id="prompt-input", | ||
language="markdown", | ||
value=self.current_prompt, | ||
classes="settings-prompt" | ||
), | ||
Label("Model:"), | ||
Select( | ||
[(model, model) for model in [ | ||
"gpt-3.5-turbo", | ||
"gpt-4", | ||
"claude-3-opus", | ||
"claude-3-sonnet", | ||
"claude-3-haiku" | ||
]], | ||
id="model-select", | ||
value=self.current_model, | ||
classes="settings-select" | ||
), | ||
Grid( | ||
Button("Save", variant="primary", id="save"), | ||
Button("Cancel", variant="default", id="cancel"), | ||
id="button-container", | ||
classes="settings-buttons" | ||
), | ||
id="settings-container" | ||
), | ||
id="settings-dialog" | ||
) | ||
|
||
def on_button_pressed(self, event: Button.Pressed) -> None: | ||
if event.button.id == "save": | ||
prompt = self.query_one("#prompt-input").text | ||
model = self.query_one("#model-select").value | ||
self.post_message(self.SettingsChanged(prompt, model)) | ||
self.dismiss(True) | ||
else: | ||
self.dismiss(False) | ||
|
||
def action_cancel(self): | ||
self.dismiss(False) |