habulaj commited on
Commit
a66d267
·
1 Parent(s): d0d2c5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -1,25 +1,21 @@
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
  }
 
1
  from fastapi import FastAPI, Query
2
+ from forex_python.converter import CurrencyRates
3
 
4
  app = FastAPI()
5
 
6
+ currency_rates = CurrencyRates()
7
+
8
+ @app.get("/convert/")
9
+ def convert_currency(amount: float = Query(..., description="Quantia a ser convertida"),
10
+ from_currency: str = Query(..., description="Moeda de origem"),
11
+ to_currency: str = Query(..., description="Moeda de destino")):
12
  """
13
+ Converte uma quantia de uma moeda para outra.
14
  """
15
+ converted_amount = currency_rates.convert(from_currency, to_currency, amount)
 
 
 
 
 
 
 
 
 
16
  return {
17
+ "amount": amount,
18
+ "from_currency": from_currency,
19
+ "to_currency": to_currency,
20
+ "converted_amount": converted_amount
21
  }