Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,25 @@
|
|
1 |
from fastapi import FastAPI, Query
|
2 |
-
from
|
3 |
|
4 |
app = FastAPI()
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
@app.get("/translate/")
|
9 |
-
def translate_text(text: str = Query(..., description="Texto a ser traduzido"),
|
10 |
-
target_lang: str = Query(..., description="Idioma de destino")):
|
11 |
"""
|
12 |
-
|
13 |
"""
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
return {
|
16 |
-
"
|
17 |
-
"
|
18 |
-
"
|
19 |
}
|
|
|
1 |
from fastapi import FastAPI, Query
|
2 |
+
from textblob import TextBlob
|
3 |
|
4 |
app = FastAPI()
|
5 |
|
6 |
+
@app.get("/sentiment/")
|
7 |
+
def analyze_sentiment(text: str = Query(..., description="Texto a ser analisado")):
|
|
|
|
|
|
|
8 |
"""
|
9 |
+
Analisa o sentimento de um texto e retorna se é positivo, negativo ou neutro.
|
10 |
"""
|
11 |
+
blob = TextBlob(text)
|
12 |
+
sentiment = blob.sentiment.polarity
|
13 |
+
|
14 |
+
if sentiment > 0:
|
15 |
+
sentiment_label = "positivo"
|
16 |
+
elif sentiment < 0:
|
17 |
+
sentiment_label = "negativo"
|
18 |
+
else:
|
19 |
+
sentiment_label = "neutro"
|
20 |
+
|
21 |
return {
|
22 |
+
"text": text,
|
23 |
+
"sentiment": sentiment_label,
|
24 |
+
"polarity": sentiment
|
25 |
}
|