-
Notifications
You must be signed in to change notification settings - Fork 0
Codex-generated pull request #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,14 @@ | ||
| @echo off | ||
| setlocal | ||
| cd /d %~dp0 | ||
|
|
||
| if not exist .venv ( | ||
| py -m venv .venv | ||
| ) | ||
|
|
||
| call .venv\Scripts\activate | ||
| python -m pip install --upgrade pip >nul | ||
| python -m pip install -e . >nul | ||
|
|
||
| start "" pythonw "%~dp0bitnet_desktop.pyw" | ||
| endlocal |
This file contains hidden or 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 hidden or 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,5 @@ | ||
| from bitnet_tools.desktop import launch_desktop | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| launch_desktop() |
This file contains hidden or 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 hidden or 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,193 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import subprocess | ||
| import threading | ||
| import tkinter as tk | ||
| from pathlib import Path | ||
| from tkinter import filedialog, messagebox, ttk | ||
|
|
||
| from .analysis import build_analysis_payload | ||
|
|
||
|
|
||
| def run_ollama(model: str, prompt: str) -> str: | ||
| proc = subprocess.run( | ||
| ["ollama", "run", model, prompt], | ||
| capture_output=True, | ||
| text=True, | ||
| check=False, | ||
| ) | ||
| if proc.returncode != 0: | ||
| raise RuntimeError(proc.stderr.strip() or "ollama run failed") | ||
| return proc.stdout.strip() | ||
|
|
||
|
|
||
| class DesktopApp: | ||
| def __init__(self, root: tk.Tk) -> None: | ||
| self.root = root | ||
| self.root.title("BitNet CSV Analyzer (Windows)") | ||
| self.root.geometry("1100x760") | ||
|
|
||
| self.csv_path: Path | None = None | ||
| self.latest_prompt = "" | ||
|
|
||
| self._build_ui() | ||
|
|
||
| def _build_ui(self) -> None: | ||
| frame = ttk.Frame(self.root, padding=12) | ||
| frame.pack(fill="both", expand=True) | ||
|
|
||
| header = ttk.Label( | ||
| frame, | ||
| text="BitNet CSV Analyzer - 터미널 없이 바로 실행", | ||
| font=("Segoe UI", 14, "bold"), | ||
| ) | ||
| header.pack(anchor="w") | ||
|
|
||
| sub = ttk.Label( | ||
| frame, | ||
| text="CSV 선택 → 분석 → BitNet 실행 순서로 사용하세요.", | ||
| ) | ||
| sub.pack(anchor="w", pady=(0, 10)) | ||
|
|
||
| top_row = ttk.Frame(frame) | ||
| top_row.pack(fill="x", pady=(0, 8)) | ||
| ttk.Button(top_row, text="CSV 파일 열기", command=self._open_csv).pack(side="left") | ||
|
|
||
| self.csv_label = ttk.Label(top_row, text="선택된 파일 없음") | ||
| self.csv_label.pack(side="left", padx=12) | ||
|
|
||
| question_row = ttk.LabelFrame(frame, text="질문") | ||
| question_row.pack(fill="x", pady=(0, 8)) | ||
|
|
||
| chip_row = ttk.Frame(question_row) | ||
| chip_row.pack(anchor="w", padx=8, pady=6) | ||
| presets = [ | ||
| "핵심 인사이트 3개와 근거를 알려줘", | ||
| "이상치 의심 포인트와 추가 확인 항목을 알려줘", | ||
| "실행 가능한 다음 액션 5개를 우선순위로 제안해줘", | ||
| ] | ||
| for txt in presets: | ||
| ttk.Button(chip_row, text=txt.split()[0], command=lambda t=txt: self._set_question(t)).pack( | ||
| side="left", padx=(0, 6) | ||
| ) | ||
|
|
||
| self.question = tk.Text(question_row, height=3, wrap="word") | ||
| self.question.pack(fill="x", padx=8, pady=(0, 8)) | ||
| self.question.insert("1.0", presets[0]) | ||
|
|
||
| model_row = ttk.Frame(frame) | ||
| model_row.pack(fill="x", pady=(0, 8)) | ||
|
|
||
| ttk.Label(model_row, text="BitNet 모델 태그").pack(side="left") | ||
| self.model = ttk.Entry(model_row) | ||
| self.model.insert(0, "bitnet:latest") | ||
| self.model.pack(side="left", fill="x", expand=True, padx=8) | ||
|
|
||
| ttk.Button(model_row, text="1) 분석", command=self._analyze_async).pack(side="left", padx=(8, 4)) | ||
| ttk.Button(model_row, text="2) BitNet 실행", command=self._run_model_async).pack(side="left") | ||
|
|
||
| self.status = ttk.Label(frame, text="대기 중") | ||
| self.status.pack(anchor="w", pady=(0, 8)) | ||
|
|
||
| output = ttk.Panedwindow(frame, orient="vertical") | ||
| output.pack(fill="both", expand=True) | ||
|
|
||
| self.summary = self._make_text_panel(output, "데이터 요약") | ||
| self.prompt = self._make_text_panel(output, "생성 프롬프트") | ||
| self.answer = self._make_text_panel(output, "BitNet 응답") | ||
|
|
||
| def _make_text_panel(self, parent: ttk.Panedwindow, title: str) -> tk.Text: | ||
| panel = ttk.LabelFrame(parent, text=title) | ||
| text = tk.Text(panel, wrap="word", height=10) | ||
| scrollbar = ttk.Scrollbar(panel, orient="vertical", command=text.yview) | ||
| text.configure(yscrollcommand=scrollbar.set) | ||
| text.pack(side="left", fill="both", expand=True) | ||
| scrollbar.pack(side="right", fill="y") | ||
| parent.add(panel, weight=1) | ||
| return text | ||
|
|
||
| def _on_ui(self, func, *args) -> None: | ||
| self.root.after(0, lambda: func(*args)) | ||
|
|
||
| def _set_question(self, text: str) -> None: | ||
| self.question.delete("1.0", "end") | ||
| self.question.insert("1.0", text) | ||
|
|
||
| def _open_csv(self) -> None: | ||
| path = filedialog.askopenfilename( | ||
| title="CSV 파일 선택", | ||
| filetypes=[("CSV files", "*.csv"), ("All files", "*.*")], | ||
| ) | ||
| if not path: | ||
| return | ||
| self.csv_path = Path(path) | ||
| self.csv_label.configure(text=str(self.csv_path)) | ||
|
|
||
| def _get_question(self) -> str: | ||
| question = self.question.get("1.0", "end").strip() | ||
| return question or "이 데이터의 핵심 인사이트를 알려줘" | ||
|
|
||
| def _analyze_async(self) -> None: | ||
| threading.Thread(target=self._analyze, daemon=True).start() | ||
|
|
||
| def _analyze(self) -> None: | ||
| self._on_ui(self._set_status, "분석 중...") | ||
| try: | ||
| question = self._get_question() | ||
| if self.csv_path: | ||
| payload = build_analysis_payload(self.csv_path, question) | ||
| else: | ||
| self._on_ui( | ||
| messagebox.showinfo, | ||
| "파일 미선택", | ||
| "CSV를 선택하지 않아 본문 텍스트 입력을 안내합니다. 텍스트 박스에 CSV를 붙여넣으세요.", | ||
| ) | ||
| return | ||
|
|
||
| self.latest_prompt = payload["prompt"] | ||
| self._on_ui(self._set_text, self.summary, json.dumps(payload["summary"], ensure_ascii=False, indent=2)) | ||
| self._on_ui(self._set_text, self.prompt, self.latest_prompt) | ||
| self._on_ui(self._set_text, self.answer, "") | ||
| self._on_ui(self._set_status, "분석 완료") | ||
| except Exception as exc: | ||
| self._on_ui(self._set_status, f"오류: {exc}") | ||
|
|
||
| def _run_model_async(self) -> None: | ||
| threading.Thread(target=self._run_model, daemon=True).start() | ||
|
|
||
| def _run_model(self) -> None: | ||
| if not self.latest_prompt: | ||
| self._on_ui(self._set_text, self.answer, "먼저 분석을 실행해 프롬프트를 생성하세요.") | ||
| return | ||
|
|
||
| model = self.model.get().strip() | ||
| if not model: | ||
| self._on_ui(self._set_text, self.answer, "모델 태그를 입력하세요. 예: bitnet:latest") | ||
| return | ||
|
|
||
| self._on_ui(self._set_status, "BitNet 실행 중...") | ||
| try: | ||
| result = run_ollama(model, self.latest_prompt) | ||
| self._on_ui(self._set_text, self.answer, result) | ||
| self._on_ui(self._set_status, "BitNet 실행 완료") | ||
| except Exception as exc: | ||
| self._on_ui(self._set_text, self.answer, f"오류: {exc}") | ||
| self._on_ui(self._set_status, "BitNet 실행 실패") | ||
|
|
||
| def _set_text(self, widget: tk.Text, value: str) -> None: | ||
| widget.delete("1.0", "end") | ||
| widget.insert("1.0", value) | ||
|
|
||
| def _set_status(self, value: str) -> None: | ||
| self.status.configure(text=value) | ||
|
|
||
|
|
||
| def launch_desktop() -> None: | ||
| root = tk.Tk() | ||
| DesktopApp(root) | ||
| root.mainloop() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| launch_desktop() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_analyze_asyncruns_analyzein a backgroundthreading.Thread, but_analyzeimmediately calls_get_question, which readsself.question.get(...)from that worker thread. Tkinter is not thread-safe, so this can intermittently raiseTclError/hangs when users click "분석" (same pattern also appears in_run_modelwithself.model.get()). Capture widget values on the main thread (e.g., before starting the worker or viaroot.after/queue handoff) and only do non-UI work in the background thread.Useful? React with 👍 / 👎.