Author:ptrace
Comitter:ptrace
Date:2026-08-02 00:54:33 UTC
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..32c7e0c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,27 @@
# Random collection of things
Most of the stuff assumes Linux.
```
.-"""-.
' \
|,. ,-. |
|()L( ()| |
|,' `".| |
|.___.',| `
.j `--"' ` `.
/ ' ' \
/ / ` `.
/ / ` .
/ / l |
. , | |
,"`. .| |
_.' ``. | `..-'l
| `.`, | `.
| `. __.j )
|__ |--""___| ,-'
`"--...,+"""" `._,.-' mh
```
_ASCII art by [Maija Haavisto](https://www.asciiart.eu/art/ea1ab399bf03d655)_
diff --git a/desc.gt b/desc.gt
new file mode 100644
index 0000000..0d41ccd
--- /dev/null
+++ b/desc.gt
@@ -0,0 +1 @@
Random things
diff --git a/python/ml_grammar.py b/python/ml_grammar.py
new file mode 100644
index 0000000..3bc1d44
--- /dev/null
+++ b/python/ml_grammar.py
@@ -0,0 +1,88 @@
#!/bin/python
from shutil import get_terminal_size
from sys import exit, argv
from subprocess import run
from pathlib import Path
MODEL_PATH = "/drives/drive3/ML/LLama-3-8B-grammar-correction/Llama-3-8B-grammar-correction.Q6_K.gguf"
TEMPERATURE = 0.1 # Recommendation by model
TOKENS_TO_PREDICT = 256
GPU_LAYERS = 99 # Also possible: "auto", "all"
LLAMA_TOOL = "llama-completion"
SYSTEM_PROMPT = "Correct the grammar and spelling of the following text. " \
"Show only the corrected sentences."
def main():
path_maybe = arg_parse()
fp = Path(path_maybe)
fp_abs = fp.absolute()
if not fp.exists():
print("Error: File path does not exist:", fp_abs)
exit(1)
print("Loading ...")
run_model(fp_abs)
def arg_parse():
args = argv
max_args = 2
if len(args) == 1 or len(args) > max_args:
print("Insufficient arguments. Expecting a path to a text file")
exit(1)
return args[1]
def run_model(fp):
cmd = [
LLAMA_TOOL,
"-m", MODEL_PATH,
"-ngl", str(GPU_LAYERS),
"--single-turn", # Exits llama after one prompt
"--temp", str(TEMPERATURE),
"--n-predict", str(TOKENS_TO_PREDICT),
"--no-display-prompt",
"--system-prompt", SYSTEM_PROMPT,
"-f", fp,
]
try:
result = run(cmd, capture_output=True, text=True)
except FileNotFoundError:
print(f"Could not find `{LLAMA_TOOL}` in $PATH")
exit(1)
except Exception as e:
print(e)
exit(1)
output_label = "-- OUTPUT "
term_width = get_terminal_size(fallback=(80, 24)).columns
width_remainder = abs(term_width - len(output_label))
if result.stdout:
print(f"{output_label}{'-' * width_remainder}")
print(result.stdout)
if result.returncode != 0 and result.stderr:
print("*** *** ERROR *** ***")
print(result.stderr)
exit(result.returncode)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("Terminated by user.")
exit(1)