Download app.py from Rifqiakmals/Final-Project-Sentiment-Analysis-Application: direct link, hf CLI and curl.
- Browser
- Download file 636 Bytes
-
https://huggingface.co/spaces/Rifqiakmals/Final-Project-Sentiment-Analysis-Application/resolve/main/app.py
- Command line
-
hf download hf://spaces/Rifqiakmals/Final-Project-Sentiment-Analysis-Application/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Rifqiakmals/Final-Project-Sentiment-Analysis-Application/resolve/main/app.py
636 Bytes
| import gradio as gr | |
| import joblib | |
| # Load model dan CountVectorizer | |
| model = joblib.load('sentiment_model.pkl') | |
| vectorizer = joblib.load('count_vectorizer.pkl') | |
| # Fungsi untuk melakukan prediksi sentimen | |
| def predict_sentiment(comment): | |
| comment_vec = vectorizer.transform([comment]) | |
| prediction = model.predict(comment_vec)[0] | |
| return prediction | |
| # Tampilan antarmuka Gradio | |
| iface = gr.Interface( | |
| fn=predict_sentiment, | |
| inputs="textbox", | |
| outputs="label", | |
| title="Instagram Comment Sentiment Analysis", | |
| description="Enter an Instagram comment to predict its sentiment (Positive or Negative)." | |
| ) | |
| iface.launch() |