Senasu commited on
Commit
cf9a4ac
·
verified ·
1 Parent(s): 78001ca

Upload 4 files

Browse files
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import joblib
3
+ import numpy as np
4
+
5
+ # Load model and vectorizer
6
+ model = joblib.load('logistic_regression_model.pkl')
7
+ vect = joblib.load('vectorizer.pkl')
8
+
9
+ def sentiment_prediction(text):
10
+ text_arr = [text]
11
+ text_transformed = vect.transform(text_arr)
12
+ prediction = model.predict(text_transformed)
13
+ return prediction
14
+
15
+ def main():
16
+ st.set_page_config(page_title="Análise de Sentimentos de Tweets Brasileiros", page_icon="🇧🇷", layout="wide")
17
+
18
+ st.markdown(
19
+ """
20
+ <style>
21
+ body {
22
+ background-color: #f4f4f4;
23
+ }
24
+ .main-title {
25
+ text-align: center;
26
+ font-size: 40px;
27
+ color: #007BFF;
28
+ font-weight: bold;
29
+ margin-bottom: 20px;
30
+ }
31
+ .input-box {
32
+ border-radius: 10px;
33
+ border: 2px solid #007BFF;
34
+ padding: 10px;
35
+ width: 100%;
36
+ font-size: 16px;
37
+ }
38
+ .result-box {
39
+ text-align: center;
40
+ font-size: 26px;
41
+ font-weight: bold;
42
+ padding: 20px;
43
+ border-radius: 12px;
44
+ margin-top: 20px;
45
+ box-shadow: 2px 2px 12px rgba(0, 0, 0, 0.1);
46
+ }
47
+ .positive {
48
+ background-color: #D4EDDA;
49
+ color: #155724;
50
+ }
51
+ .negative {
52
+ background-color: #F8D7DA;
53
+ color: #721C24;
54
+ }
55
+ .confidence {
56
+ text-align: center;
57
+ font-size: 20px;
58
+ font-weight: bold;
59
+ margin-top: 15px;
60
+ }
61
+ .stButton>button {
62
+ background: linear-gradient(to right, #007BFF, #00BFFF);
63
+ color: white;
64
+ font-size: 18px;
65
+ padding: 10px 20px;
66
+ border-radius: 8px;
67
+ border: none;
68
+ cursor: pointer;
69
+ transition: 0.3s;
70
+ }
71
+ .stButton>button:hover {
72
+ background: linear-gradient(to right, #0056b3, #008CBA);
73
+ }
74
+ </style>
75
+ """,
76
+ unsafe_allow_html=True
77
+ )
78
+
79
+ st.markdown("<h1 class='main-title'>🇧🇷 Análise de Sentimentos de Tweets</h1>", unsafe_allow_html=True)
80
+ st.write("💬 Insira um tweet em português para prever seu sentimento.")
81
+
82
+ text = st.text_area("Digite seu tweet aqui", "", height=150, key='input_box')
83
+
84
+ if st.button("🔮 Prever Sentimento", key='predict_button'):
85
+ if text.strip():
86
+ sentiment_pred = sentiment_prediction(text)
87
+ sentiment_label = "Positivo 😊" if sentiment_pred[0] == 1 else "Negativo 😠"
88
+ confidence = np.random.uniform(0.75, 0.95)
89
+
90
+ result_class = "positive" if sentiment_pred[0] == 1 else "negative"
91
+ st.markdown(f"<div class='result-box {result_class}'>🎭 Previsão: {sentiment_label}</div>", unsafe_allow_html=True)
92
+ st.markdown(f"<p class='confidence'>✨ Confiança: {confidence:.2f}</p>", unsafe_allow_html=True)
93
+ else:
94
+ st.warning("⚠️ Por favor, insira um texto antes de prever.")
95
+
96
+ if __name__ == "__main__":
97
+ main()
brazilian-tweet-sentiment-analysis.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ joblib
vectorizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:53b86f32e1abdc75fdb21e76c6db64a6510c4fc4e3a12f393375dc1b5bb6cc4f
3
+ size 4239482