Diya-Roshan commited on
Commit
7167deb
·
verified ·
1 Parent(s): 343ba57

added app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from simpletransformers.classification import MultiLabelClassificationModel
3
+ import torch
4
+
5
+ # Function to make predictions
6
+ def predict(model, text):
7
+ raw_outputs, _ = model.predict([text])
8
+ return raw_outputs
9
+
10
+ # Streamlit App
11
+ def main():
12
+ st.title("Dravidian-English Code Mixed TextSentiment Prediction App")
13
+
14
+ # Language model selection
15
+ selected_language = st.selectbox("Select Language Model", ["Kannada", "Malayalam", "Tamil"])
16
+
17
+ # Load the pre-trained model based on the selected language
18
+ model_paths = {
19
+ "Kannada": "KanModel1",
20
+ "Malayalam": "MalModel1",
21
+ "Tamil": "TamModel1",
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 text
29
+ text_input = st.text_area("Enter text for prediction", "")
30
+
31
+ # Make predictions when the user clicks the button
32
+ if st.button("Predict"):
33
+ if text_input:
34
+ predictions = predict(model, text_input)
35
+
36
+ # Display the predictions
37
+ 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
+
44
+ if __name__ == "__main__":
45
+ main()