rachman commited on
Commit
7c2b804
·
verified ·
1 Parent(s): b779185

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +69 -0
  3. model.keras +3 -0
  4. requirements.txt +4 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import re
4
+ import tensorflow as tf
5
+ from nltk.corpus import stopwords
6
+ from nltk.tokenize import word_tokenize
7
+ from tensorflow.keras.preprocessing.text import Tokenizer
8
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
9
+ from tensorflow.keras.models import load_model
10
+
11
+ # Load the trained model
12
+ model = load_model('model.keras')
13
+
14
+ # Load stopwords
15
+ stpwds_id = list(set(stopwords.words('english')))
16
+
17
+ # Text preprocessing function
18
+ def text_preprocessing(text):
19
+ # Case folding
20
+ text = text.lower()
21
+
22
+ # Mention removal
23
+ text = re.sub("@[A-Za-z0-9_]+", " ", text)
24
+
25
+ # Hashtags removal
26
+ text = re.sub("#[A-Za-z0-9_]+", " ", text)
27
+
28
+ # Newline removal (\n)
29
+ text = re.sub(r"\\n", " ",text)
30
+
31
+ # Whitespace removal
32
+ text = text.strip()
33
+
34
+ # URL removal
35
+ text = re.sub(r"http\S+", " ", text)
36
+ text = re.sub(r"www.\S+", " ", text)
37
+
38
+ # Non-letter removal (such as emoticons, symbols, etc.)
39
+ text = re.sub("[^A-Za-z\s']", " ", text)
40
+
41
+ # Tokenization
42
+ tokens = word_tokenize(text)
43
+
44
+ # Stopwords removal
45
+ tokens = [word for word in tokens if word not in stpwds_id]
46
+
47
+ # Combining Tokens
48
+ text = ' '.join(tokens)
49
+
50
+ return text
51
+
52
+ # Define the Streamlit interface
53
+ st.title('Sentiment Analysis App')
54
+
55
+ # Get user input
56
+ user_input = st.text_area("Enter the text for sentiment analysis:")
57
+
58
+ if st.button('Analyze'):
59
+ if user_input:
60
+ # Preprocess the input text
61
+ processed_text = text_preprocessing(user_input)
62
+ prediction = model.predict([[processed_text]])
63
+ sentiment = "Positive" if prediction[0] > 0.5 else "Negative"
64
+
65
+ # Display the result
66
+ st.write(f"Sentiment: {sentiment}")
67
+ else:
68
+ st.write("Please enter some text.")
69
+
model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2b1dea5dd297c98e8d9303fd7fa13086a42ff26943d2050b6514d7a816b6cf67
3
+ size 4137733
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit==1.17.0
2
+ pandas==2.1.0
3
+ tensorflow==2.14.0
4
+ nltk==3.8.1