BugZoid commited on
Commit
bdcfb66
·
verified ·
1 Parent(s): f3b1ac7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
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
- # Inicializando o pipeline com modelo em português
146
  sentiment_pipeline = pipeline(
147
  "sentiment-analysis",
148
- model="pierreguillou/bert-base-cased-gs-sentiment-pt",
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
- # Mapeando os resultados para positive/negative/neutral
157
- label = result[0]['label']
158
- if label == 'POSITIVE':
 
159
  sentiments.append('positive')
160
- elif label == 'NEGATIVE':
161
  sentiments.append('negative')
162
  else:
163
  sentiments.append('neutral')
164
- debug_print(f"Sentimento analisado: {label}")
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