Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions batch_processing/batch_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from enum import Enum
from io import BytesIO
from typing import Optional, List
import tkinter as tk
from pydantic import BaseModel, ConfigDict, Field

from file_handling.data_conversion import make_str_enum
Expand Down Expand Up @@ -108,7 +107,7 @@ def generate_multi_label_batch(labels, quotes) -> BytesIO | None:
labels_enum = make_str_enum("Label", labels)

class LabeledQuoteMulti(BaseModel):
label: List[labels_enum] = Field(..., min_items=1)
label: List[labels_enum] = Field(..., min_length=1)
model_config = ConfigDict(use_enum_values=True, extra='forbid')

SCHEMA = LabeledQuoteMulti.model_json_schema()
Expand Down Expand Up @@ -156,7 +155,7 @@ def generate_keyword_extraction_batch(texts) -> BytesIO | None:
Returns a BytesIO whose .name is set to 'batchinput.jsonl'.
"""
class KeywordExtraction(BaseModel):
keywords: list[str] = Field(..., min_items=1)
keywords: list[str] = Field(..., min_length=1)
model_config = ConfigDict(extra='forbid')

SCHEMA = KeywordExtraction.model_json_schema()
Expand Down
11 changes: 0 additions & 11 deletions file_handling/data_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,6 @@ def _initial_blank_preview():
_fill_preview_rows([[""] * 5 for _ in range(5)])
_update_dataset_name_preview()

def _current_header_labels() -> list[str]:
# Return the labels currently shown atop the preview
return [tree.heading(cid)["text"] for cid in tree["columns"]]

def _selected_header_label() -> str:
labels = _current_header_labels()
idx = selected_col.get()
if 0 <= idx < len(labels):
return str(labels[idx])
return ""

def _update_dataset_name_controls_enabled():
# Enable/disable "selected column header" radio based on has_headers + data present
has_data = bool(_loaded_rows)
Expand Down
21 changes: 10 additions & 11 deletions live_processing/keyword_extraction_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,28 @@

from typing import Optional
import tkinter as tk
from tkinter import messagebox
from pydantic import BaseModel, ValidationError, Field, ConfigDict
from openai import OpenAI
from file_handling.data_import import import_data
from file_handling.data_conversion import save_as_csv, to_long_df
from settings import secrets_store, config
from settings import config
from batch_processing.batch_method import get_client

# Progress UI lives in a separate module
from ui.progress_ui import ProgressController

# Initialize OpenAI client with stored API key
try:
OPENAI_API_KEY = secrets_store.load_api_key()
client = OpenAI(api_key=OPENAI_API_KEY) if OPENAI_API_KEY else None
except Exception:
OPENAI_API_KEY = None
client = None


def keyword_extraction_pipeline(parent: Optional[tk.Misc] = None):
"""
Prompt for quotes CSVs, extract keywords from each quote,
show progress, then save results to CSV.
"""
try:
client = get_client()
except Exception as e:
messagebox.showerror("API Key Required", str(e))
return

# Get quotes data
from_import = import_data(parent, "Select the quotes data")
if from_import is None:
Expand All @@ -40,7 +39,7 @@ def keyword_extraction_pipeline(parent: Optional[tk.Misc] = None):
class KeywordExtraction(BaseModel):
id: int | None = None
quote: str
keywords: list[str] = Field(..., min_items=1)
keywords: list[str] = Field(..., min_length=1)
model_config = ConfigDict()

total = len(quotes)
Expand Down
21 changes: 10 additions & 11 deletions live_processing/multi_label_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,28 @@

from typing import Optional, List
import tkinter as tk
from tkinter import messagebox
from pydantic import BaseModel, ValidationError, Field, ConfigDict
from openai import OpenAI
from file_handling.data_import import import_data
from file_handling.data_conversion import make_str_enum, save_as_csv, to_long_df
from settings import secrets_store, config
from settings import config
from batch_processing.batch_method import get_client

# Progress UI lives in a separate module
from ui.progress_ui import ProgressController

# Initialize OpenAI client with stored API key
try:
OPENAI_API_KEY = secrets_store.load_api_key()
client = OpenAI(api_key=OPENAI_API_KEY) if OPENAI_API_KEY else None
except Exception:
OPENAI_API_KEY = None
client = None


def multi_label_pipeline(parent: Optional[tk.Misc] = None):
"""
Prompt for labels/quotes CSVs, classify each quote with 1+ labels,
show progress, then save results to CSV.
"""
try:
client = get_client()
except Exception as e:
messagebox.showerror("API Key Required", str(e))
return

# Get labels data
from_import = import_data(parent, "Select the labels data")
if from_import is None:
Expand All @@ -47,7 +46,7 @@ def multi_label_pipeline(parent: Optional[tk.Misc] = None):
class LabeledQuoteMulti(BaseModel):
id: int | None = None
quote: str
label: List[labels] = Field(..., min_items=1)
label: List[labels] = Field(..., min_length=1)
model_config = ConfigDict(use_enum_values=True, extra='forbid')

total = len(quotes)
Expand Down
19 changes: 9 additions & 10 deletions live_processing/single_label_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,28 @@

from typing import Optional
import tkinter as tk
from tkinter import messagebox
from pydantic import BaseModel, ValidationError, Field, ConfigDict
from openai import OpenAI
from file_handling.data_import import import_data
from file_handling.data_conversion import make_str_enum, save_as_csv, to_long_df
from settings import secrets_store, config
from settings import config
from batch_processing.batch_method import get_client

# Progress UI lives in a separate module
from ui.progress_ui import ProgressController

# Initialize OpenAI client with stored API key
try:
OPENAI_API_KEY = secrets_store.load_api_key()
client = OpenAI(api_key=OPENAI_API_KEY) if OPENAI_API_KEY else None
except Exception:
OPENAI_API_KEY = None
client = None


def single_label_pipeline(parent: Optional[tk.Misc] = None):
"""
Prompt for labels/quotes CSVs, classify each quote with exactly one label,
show progress, then save results to CSV.
"""
try:
client = get_client()
except Exception as e:
messagebox.showerror("API Key Required", str(e))
return

# Get labels data
from_import = import_data(parent, "Select the labels data")
if from_import is None:
Expand Down
7 changes: 6 additions & 1 deletion ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ def build_ui(root: tk.Tk) -> None:
root: The main Tkinter window to build the UI in
"""
root.title(APP_TITLE)
root.iconbitmap(asset_path("app.ico"))
try:
# .ico files are only natively supported by iconbitmap on Windows;
# this raises TclError on Linux/macOS Tk builds.
root.iconbitmap(asset_path("app.ico"))
except tk.TclError:
pass

# ===== Top-level grid: header, spacer, table area =====
root.columnconfigure(0, weight=1)
Expand Down
Loading