Spaces:
Running
Running
File size: 1,084 Bytes
667fe9d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
from __future__ import annotations
from pathlib import Path
import click
import joblib
from app.utils import colorize
@click.group()
def cli() -> None: ...
@cli.command("predict")
@click.option(
"-m",
"--model",
"model_path",
default="models/model.pkl",
help="Path to the model file.",
type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True, resolve_path=True, path_type=Path),
)
@click.argument("text", nargs=-1)
def predict(model_path: Path, text: list[str]) -> None:
input_text = " ".join(text).strip()
if not input_text:
click.echo("[RED]Error[/RED]: Input text is empty.")
return
# Load the model
click.echo("Loading model... ", nl=False)
model = joblib.load(model_path)
click.echo(colorize("[GREEN]DONE"))
# Run the model
click.echo("Performing sentiment analysis... ", nl=False)
prediction = model.predict([input_text])
sentiment = "[GREEN]POSITIVE" if prediction[0] == 1 else "[RED]NEGATIVE"
click.echo(colorize(sentiment))
if __name__ == "__main__":
cli()
|