import re import sys import pynvml from pygments import highlight from pygments.formatters import HtmlFormatter from pygments.lexers import TextLexer, get_lexer_by_name, guess_lexer from pygments.util import ClassNotFound from PyQt6.QtCore import QThread, QTimer, pyqtSignal from PyQt6.QtGui import ( QColor, QFont, QTextBlockFormat, QTextCharFormat, QTextCursor, QTextDocument, QTextDocumentFragment, ) from PyQt6.QtWidgets import ( QApplication, QHBoxLayout, QLabel, QLineEdit, QMainWindow, QPushButton, QTextBrowser, QVBoxLayout, QWidget, ) import chatbot # How often the bottom-right GPU/VRAM readout refreshes. GPU_STATUS_INTERVAL_MS = 1000 # GitHub dialect adds fenced code blocks with language tags, tables, and # strikethrough on top of CommonMark; NoHTML stops raw HTML in the model's # output from being interpreted as literal markup in the chat view. _MARKDOWN_FEATURES = ( QTextDocument.MarkdownFeature.MarkdownDialectGitHub | QTextDocument.MarkdownFeature.MarkdownNoHTML ) # Matches fenced code blocks (```lang\ncode\n```) so they can be pulled out # and rendered through Pygments instead of QTextDocumentFragment.fromMarkdown, # which only gives code a monospace font and no syntax colors. _CODE_FENCE_RE = re.compile(r"```([\w+-]*)\n(.*?)```", re.DOTALL) # noclasses=True inlines every color as a style="..." attribute rather than # relying on a