Diya-Roshan/code-mixed-text-sentiment-classification
0
1import streamlit as st2from simpletransformers.classification import MultiLabelClassificationModel3import torch4 5# Function to make predictions6def predict(model, text):7 raw_outputs, _ = model.predict([text])8 return raw_outputs9 10# Streamlit App11def main():12 st.title("Dravidian-English Code Mixed TextSentiment Prediction App")13 14 # Language model selection15 selected_language = st.selectbox("Select Language Model", ["Kannada", "Malayalam", "Tamil"])16 17 # Load the pre-trained model based on the selected language18 model_paths = {19 "Kannada": "Diya-Roshan/xlm-code-mixed-kannada-sentiment-classifier",20 "Malayalam": "Diya-Roshan/xlm-code-mixed-malayalam-sentiment-classifier", 21 "Tamil": "Diya-Roshan/xlm-code-mixed-tamil-sentiment-classifier", 22 }23 24 if selected_language in model_paths:25 model_path = model_paths[selected_language]26 model = MultiLabelClassificationModel('xlm', model_path, use_cuda=False)27 28 # User input for text29 text_input = st.text_area("Enter text for prediction", "")30 31 # Make predictions when the user clicks the button32 if st.button("Predict"):33 if text_input:34 predictions = predict(model, text_input)35 36 # Display the predictions37 if predictions == [[1, 0, 0]]:38 st.success('Positive Sentiment')39 elif predictions == [[0, 1, 0]]:40 st.error('Negative Sentiment')41 else:42 st.warning('Mixed Sentiment')43 44if __name__ == "__main__":45 main()46 