Spaces:
Sleeping
Sleeping
Download pages/3_Deployment.py from Srikanth0804/Sentiment_Analysis: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/Srikanth0804/Sentiment_Analysis/resolve/main/pages/3_Deployment.py
- Command line
-
hf download hf://spaces/Srikanth0804/Sentiment_Analysis/pages/3_Deployment.py
-
curl -L -o 3_Deployment.py https://huggingface.co/spaces/Srikanth0804/Sentiment_Analysis/resolve/main/pages/3_Deployment.py
1.42 kB
| import streamlit as st | |
| import pickle | |
| st.set_page_config(page_title="π― YouTube Comment Sentiment Predictor") | |
| st.title("π― Live Sentiment Classifier") | |
| # Load the complete pipeline (TF-IDF + Model) | |
| with open("text_classification.pkl", "rb") as f: | |
| pipeline = pickle.load(f) | |
| # Helpful context for users | |
| with st.expander("#### π **Click here to see what topics this model was trained on**"): | |
| st.markdown(""" | |
| - **heartwarming reunion, kindness stories, feel-good moments** | |
| - **bad customer experience, airline disaster, controversial incidents** | |
| - **tech reviews, travel vlogs, gaming walkthroughs** | |
| """) | |
| # User input | |
| user_input = st.text_area("##### **Enter a YouTube comment to analyze:**", | |
| placeholder="E.g., That reunion video was so emotional!") | |
| # Predict button | |
| if st.button("Predict Sentiment"): | |
| if user_input.strip(): | |
| prediction = pipeline.predict([user_input])[0] | |
| st.markdown(f"## β Prediction: `{prediction.capitalize()}`") | |
| if prediction == "positive": | |
| st.success("π Positive Sentiment") | |
| elif prediction == "negative": | |
| st.error("π Negative Sentiment") | |
| else: | |
| st.info("π Neutral Sentiment") | |
| else: | |
| st.warning("β οΈ Please enter a comment to analyze.") | |
| # Navigation | |
| if st.button("Go to Model Page"): | |
| st.switch_page("pages/2_Model_Training.py") |