Spaces:
Sleeping
Sleeping
File size: 1,515 Bytes
f61c84d |
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 46 47 |
import streamlit as st
import joblib
from sklearn.feature_extraction.text import TfidfVectorizer
def model2():
# Load the saved model
model_filename = "emotion_model.joblib"
loaded_model = joblib.load(model_filename)
# Load the TfidfVectorizer (assuming you used TfidfVectorizer during training)
vectorizer_filename = "count_vectorizer.joblib" # Update this to the correct filename
vectorizer = joblib.load(vectorizer_filename)
# Streamlit App
st.title("Emotion Prediction App")
# Input text from the user
user_input = st.text_area("Enter your text:")
# Analyze button
if st.button("Analyze"):
# Make predictions with new data
if user_input:
new_data = [user_input]
new_features = vectorizer.transform(new_data)
new_predictions = loaded_model.predict_proba(new_features)
# Display predictions using a progress bar
st.subheader("Emotion Scores:")
# Assuming there are three classes (Fear, Anger, Joy)
progress_bar_fear = st.progress(new_predictions[0][0])
st.write("Fear:", round(new_predictions[0][0], 2))
progress_bar_anger = st.progress(new_predictions[0][1])
st.write("Anger:", round(new_predictions[0][1], 2))
progress_bar_joy = st.progress(new_predictions[0][2])
st.write("Joy:", round(new_predictions[0][2], 2))
# Call the function to run the app
if __name__ == "__main__":
model2()
|