Spaces:
No application file
No application file
Commit ·
ec38040
1
Parent(s): 1cc66b6
Análise de sentimentos
Browse files- .gitignore +4 -0
- sentiment_analysis.py +35 -0
- sentiment_multiple_users.py +28 -0
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# EddyGiusepe
|
| 2 |
+
venv_sentiment/
|
| 3 |
+
.env
|
| 4 |
+
__pycache__
|
sentiment_analysis.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Data Scientist.: Dr.Eddy Giusepe Chirinos Isidro
|
| 3 |
+
|
| 4 |
+
Objetivo: Neste script vamos analisar o sentimento que contém
|
| 5 |
+
uma frase digitada pelo usuário 🤗.
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
import os
|
| 9 |
+
import openai
|
| 10 |
+
from dotenv import find_dotenv, load_dotenv
|
| 11 |
+
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 12 |
+
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def get_sentiment(text, model="gpt-3.5-turbo"):
|
| 16 |
+
"""Esta função usa a API da OpenAI para analisar o SENTIMENTO da frase."""
|
| 17 |
+
prompt = f"""Forneça, apenas em uma palavra, o sentimento do seguinte texto: ```{text}```"""
|
| 18 |
+
messages = [{"role": "user", "content": prompt}]
|
| 19 |
+
|
| 20 |
+
response = openai.ChatCompletion.create(
|
| 21 |
+
model=model,
|
| 22 |
+
messages=messages,
|
| 23 |
+
temperature=0,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
sentiment = response.choices[0].message["content"]
|
| 27 |
+
return sentiment
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
text = input("Digite o texto a ser analisado: ")
|
| 33 |
+
sentiment = get_sentiment(text)
|
| 34 |
+
|
| 35 |
+
print(f"\033[033mO sentimento do texto é\033[m: {sentiment}")
|
sentiment_multiple_users.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Data Scientist.: Dr.Eddy Giusepe Chirinos Isidro
|
| 3 |
+
|
| 4 |
+
Objetivo: Neste script vamos a realizar as queries de
|
| 5 |
+
forma iterativa 🤗.
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
from sentiment_analysis import get_sentiment
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def analyze_sentiments():
|
| 12 |
+
try:
|
| 13 |
+
while True:
|
| 14 |
+
text = input("\nDigite o texto para analisar (digite 'quit' para sair): ")
|
| 15 |
+
if text.lower() == "quit":
|
| 16 |
+
print("Saindo do programa...")
|
| 17 |
+
break
|
| 18 |
+
sentiment = get_sentiment(text)
|
| 19 |
+
print(f"\033[033mO sentimento do texto é\033[m: {sentiment}")
|
| 20 |
+
except Exception as e:
|
| 21 |
+
print(f"Error: {str(e)}")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# Instanciamos a Função para fazer as nossas Queries:
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
analyze_sentiments()
|
| 28 |
+
|