Compare commits
No commits in common. "80428e1bbff00de5cafdf7eb571ac7a1cb97ff69" and "ce80647bbb8ac6e843fd9708346dffe62cf4f93e" have entirely different histories.
80428e1bbf
...
ce80647bbb
|
@ -6,53 +6,48 @@ import json
|
||||||
import sys
|
import sys
|
||||||
import gptc
|
import gptc
|
||||||
|
|
||||||
def main():
|
parser = argparse.ArgumentParser(
|
||||||
parser = argparse.ArgumentParser(
|
description="General Purpose Text Classifier", prog="gptc"
|
||||||
description="General Purpose Text Classifier", prog="gptc"
|
)
|
||||||
)
|
subparsers = parser.add_subparsers(dest="subparser_name", required=True)
|
||||||
subparsers = parser.add_subparsers(dest="subparser_name", required=True)
|
|
||||||
|
|
||||||
compile_parser = subparsers.add_parser("compile", help="compile a raw model")
|
compile_parser = subparsers.add_parser("compile", help="compile a raw model")
|
||||||
compile_parser.add_argument("model", help="raw model to compile")
|
compile_parser.add_argument("model", help="raw model to compile")
|
||||||
compile_parser.add_argument("--max-ngram-length", "-n", help="maximum ngram length", type=int, default=1)
|
compile_parser.add_argument("--max-ngram-length", "-n", help="maximum ngram length", type=int, default=1)
|
||||||
|
|
||||||
classify_parser = subparsers.add_parser("classify", help="classify text")
|
classify_parser = subparsers.add_parser("classify", help="classify text")
|
||||||
classify_parser.add_argument("model", help="compiled model to use")
|
classify_parser.add_argument("model", help="compiled model to use")
|
||||||
classify_parser.add_argument("--max-ngram-length", "-n", help="maximum ngram length", type=int, default=1)
|
classify_parser.add_argument("--max-ngram-length", "-n", help="maximum ngram length", type=int, default=1)
|
||||||
group = classify_parser.add_mutually_exclusive_group()
|
group = classify_parser.add_mutually_exclusive_group()
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"-j",
|
"-j",
|
||||||
"--json",
|
"--json",
|
||||||
help="output confidence dict as JSON (default)",
|
help="output confidence dict as JSON (default)",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"-c",
|
"-c",
|
||||||
"--category",
|
"--category",
|
||||||
help="output most likely category or `None`",
|
help="output most likely category or `None`",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
with open(args.model, "r") as f:
|
with open(args.model, "r") as f:
|
||||||
model = json.load(f)
|
model = json.load(f)
|
||||||
|
|
||||||
if args.subparser_name == "compile":
|
if args.subparser_name == "compile":
|
||||||
print(json.dumps(gptc.compile(model, args.max_ngram_length)))
|
print(json.dumps(gptc.compile(model, args.max_ngram_length)))
|
||||||
|
else:
|
||||||
|
classifier = gptc.Classifier(model, args.max_ngram_length)
|
||||||
|
|
||||||
|
if sys.stdin.isatty():
|
||||||
|
text = input("Text to analyse: ")
|
||||||
else:
|
else:
|
||||||
classifier = gptc.Classifier(model, args.max_ngram_length)
|
text = sys.stdin.read()
|
||||||
|
|
||||||
if sys.stdin.isatty():
|
if args.category:
|
||||||
text = input("Text to analyse: ")
|
print(classifier.classify(text))
|
||||||
else:
|
else:
|
||||||
text = sys.stdin.read()
|
print(json.dumps(classifier.confidence(text)))
|
||||||
|
|
||||||
if args.category:
|
|
||||||
print(classifier.classify(text))
|
|
||||||
else:
|
|
||||||
print(json.dumps(classifier.confidence(text)))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
[build-system]
|
|
||||||
requires = ["setuptools>=61.0.0", "wheel"]
|
|
||||||
build-backend = "setuptools.build_meta"
|
|
||||||
|
|
||||||
[project]
|
|
||||||
name = "gptc"
|
|
||||||
version = "2.0.0"
|
|
||||||
description = "General-purpose text classifier"
|
|
||||||
readme = "README.md"
|
|
||||||
authors = [{ name = "Samuel Sloniker", email = "sam@kj7rrv.com"}]
|
|
||||||
license = { file = "LICENSE" }
|
|
||||||
classifiers = [
|
|
||||||
"Programming Language :: Python",
|
|
||||||
"Programming Language :: Python :: 3",
|
|
||||||
"Development Status :: 5 - Production/Stable",
|
|
||||||
"License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)",
|
|
||||||
"Operating System :: OS Independent",
|
|
||||||
]
|
|
||||||
dependencies = []
|
|
||||||
requires-python = ">=3.7"
|
|
||||||
|
|
||||||
[project.urls]
|
|
||||||
Homepage = "https://git.kj7rrv.com/kj7rrv/gptc"
|
|
||||||
|
|
||||||
[project.scripts]
|
|
||||||
gptc = "gptc.__main__:main"
|
|
||||||
|
|
||||||
[tool.setuptools]
|
|
||||||
packages = ["gptc"]
|
|
17
setup.py
Normal file
17
setup.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
with open("README.md", "r") as fh:
|
||||||
|
long_description = fh.read()
|
||||||
|
setuptools.setup(
|
||||||
|
name="gptc",
|
||||||
|
version="1.0.0",
|
||||||
|
description="General-purpose text classifier",
|
||||||
|
long_description=long_description,
|
||||||
|
long_description_content_type="text/markdown",
|
||||||
|
packages=setuptools.find_packages(),
|
||||||
|
classifiers=[
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
],
|
||||||
|
python_requires=">=3.6",
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user