Spaces:
Running
Running
from __future__ import annotations | |
from pathlib import Path | |
import click | |
import joblib | |
from app.utils import colorize | |
def cli() -> None: ... | |
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() | |