Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -142,26 +142,26 @@ def main():
|
|
| 142 |
with st.spinner('Analisando sentimentos...'):
|
| 143 |
debug_print("Iniciando análise de sentimentos...")
|
| 144 |
|
| 145 |
-
#
|
| 146 |
sentiment_pipeline = pipeline(
|
| 147 |
"sentiment-analysis",
|
| 148 |
-
model="
|
| 149 |
-
tokenizer="pierreguillou/bert-base-cased-gs-sentiment-pt"
|
| 150 |
)
|
| 151 |
|
| 152 |
sentiments = []
|
| 153 |
for tweet in tweets.data:
|
| 154 |
if hasattr(tweet, 'lang') and tweet.lang == 'pt':
|
| 155 |
result = sentiment_pipeline(tweet.text)
|
| 156 |
-
#
|
| 157 |
-
|
| 158 |
-
|
|
|
|
| 159 |
sentiments.append('positive')
|
| 160 |
-
elif
|
| 161 |
sentiments.append('negative')
|
| 162 |
else:
|
| 163 |
sentiments.append('neutral')
|
| 164 |
-
debug_print(f"Sentimento analisado: {
|
| 165 |
|
| 166 |
time.sleep(1)
|
| 167 |
|
|
|
|
| 142 |
with st.spinner('Analisando sentimentos...'):
|
| 143 |
debug_print("Iniciando análise de sentimentos...")
|
| 144 |
|
| 145 |
+
# Usando modelo multilingual que suporta português
|
| 146 |
sentiment_pipeline = pipeline(
|
| 147 |
"sentiment-analysis",
|
| 148 |
+
model="nlptown/bert-base-multilingual-uncased-sentiment"
|
|
|
|
| 149 |
)
|
| 150 |
|
| 151 |
sentiments = []
|
| 152 |
for tweet in tweets.data:
|
| 153 |
if hasattr(tweet, 'lang') and tweet.lang == 'pt':
|
| 154 |
result = sentiment_pipeline(tweet.text)
|
| 155 |
+
# Este modelo retorna ratings de 1 a 5 estrelas
|
| 156 |
+
# Vamos mapear para nossos sentimentos
|
| 157 |
+
rating = int(result[0]['label'].split()[0])
|
| 158 |
+
if rating >= 4:
|
| 159 |
sentiments.append('positive')
|
| 160 |
+
elif rating <= 2:
|
| 161 |
sentiments.append('negative')
|
| 162 |
else:
|
| 163 |
sentiments.append('neutral')
|
| 164 |
+
debug_print(f"Sentimento analisado: {rating} estrelas")
|
| 165 |
|
| 166 |
time.sleep(1)
|
| 167 |
|