import gradio as gr import nltk import joblib nltk.download("punkt") nltk.download("wordnet") nltk.download('punkt_tab') model = joblib.load("sentiment_pipeline.joblib") def predict_sentiment(text, show_preprocessed=False): proba = model.predict_proba([text])[0] sentiment = "Positive π" if proba[1] >= 0.5 else "Negative π" confidence = f"{round(max(proba) * 100, 2)}%" pre_out = "" if show_preprocessed: pre_out = model.named_steps["textpreprocessor"].transform([text])[0] return sentiment, confidence, pre_out with gr.Blocks(css=""" .pipeline-container { background-color: blue; border:1px solid #ddd; border-radius:8px; padding:8px; margin-bottom: 4px; } .footer { margin-top: 24px; font-size:0.9rem; text-align:center; } """) as demo: gr.Markdown("# π¬ SentiMDB") gr.Markdown( "### SentiMDB is a lightweight, production-ready Sentiment Analysis Pipeline based on IMDb movie reviews. It features a Flask web app, a Dockerized setup for easy deployment, and a Hugging Face Spaces-powered online demo. The project includes a comprehensive Jupyter Notebook, offering a guide to English Text Preprocessing and detailing the full Machine Learning Development process, including Model Selection, Error Analysis, and Fine-Tuning. By leveraging classic machine learning tools alone, the model achieved 91.67% prediction accuracy." ) with gr.Row(): with gr.Column(scale=1): gr.HTML("""