Compare commits
2 Commits
4f7b2a73cb
...
739d27fe71
Author | SHA1 | Date | |
---|---|---|---|
![]() |
739d27fe71 | ||
![]() |
de7ad3d65a |
@@ -14,7 +14,19 @@ from .util import ffmpeg_description, parse_ucs
|
|||||||
|
|
||||||
|
|
||||||
def recommend_text(text: str, ctx: InferenceContext):
|
def recommend_text(text: str, ctx: InferenceContext):
|
||||||
return None
|
return ctx.classify_text_ranked(text)
|
||||||
|
|
||||||
|
def print_recommendation(path: str | None, text: str, ctx: InferenceContext):
|
||||||
|
recommendations = ctx.classify_text_ranked(text)
|
||||||
|
print("----------")
|
||||||
|
if path:
|
||||||
|
print(f"Path: {path}")
|
||||||
|
|
||||||
|
print(f"Text: {text or '<None>'}")
|
||||||
|
for r in recommendations:
|
||||||
|
cat, subcat, _ = ctx.lookup_category(r)
|
||||||
|
print(f"- {r}: {cat}-{subcat}")
|
||||||
|
|
||||||
|
|
||||||
@click.group(epilog="For more information see "
|
@click.group(epilog="For more information see "
|
||||||
"<https://git.squad51.us/jamie/ucsinfer>")
|
"<https://git.squad51.us/jamie/ucsinfer>")
|
||||||
@@ -22,16 +34,15 @@ def recommend_text(text: str, ctx: InferenceContext):
|
|||||||
def ucsinfer():
|
def ucsinfer():
|
||||||
"""
|
"""
|
||||||
Tools for applying UCS categories to sounds using large-language Models
|
Tools for applying UCS categories to sounds using large-language Models
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ucsinfer.command('recommend')
|
@ucsinfer.command('recommend')
|
||||||
@click.option('--text', type=Optional[str], default=None,
|
@click.option('--text', default=None,
|
||||||
help="Recommend a category for given text instead of reading "
|
help="Recommend a category for given text instead of reading "
|
||||||
"from a file")
|
"from a file")
|
||||||
@click.argument('files', nargs=-1)
|
@click.argument('paths', nargs=-1)
|
||||||
@click.option('--model', type=str, metavar="<model-name>",
|
@click.option('--model', type=str, metavar="<model-name>",
|
||||||
default="paraphrase-multilingual-mpnet-base-v2",
|
default="paraphrase-multilingual-mpnet-base-v2",
|
||||||
show_default=True,
|
show_default=True,
|
||||||
@@ -44,29 +55,17 @@ def recommend(text, paths, model):
|
|||||||
m = SentenceTransformer(model)
|
m = SentenceTransformer(model)
|
||||||
ctx = InferenceContext(m, model)
|
ctx = InferenceContext(m, model)
|
||||||
|
|
||||||
recommendations = []
|
|
||||||
if text is not None:
|
if text is not None:
|
||||||
recommendations.append({
|
print_recommendation(None, text, ctx)
|
||||||
"text": text,
|
|
||||||
"recommendations": recommend_text(text, ctx)
|
|
||||||
})
|
|
||||||
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
text = ffmpeg_description(path)
|
text = ffmpeg_description(path)
|
||||||
if text:
|
if text:
|
||||||
recommendations.append({
|
print_recommendation(path, text, ctx)
|
||||||
"path":path,
|
|
||||||
"text":text,
|
|
||||||
"recommendations":recommend_text(text, ctx)
|
|
||||||
})
|
|
||||||
else:
|
else:
|
||||||
recommendations.append({
|
filename = os.path.basename(path)
|
||||||
"path":path,
|
print_recommendation(path, filename, ctx)
|
||||||
"text":None,
|
|
||||||
"recommendations":None
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ucsinfer.command('gather')
|
@ucsinfer.command('gather')
|
||||||
|
Reference in New Issue
Block a user