Project 3: Sentiment Analysis API with Fine-Tuned Transformer
Step 5: Run the API
Run the FastAPI server locally:
uvicorn app:app --reload
Test the API using curl
or a tool like Postman:
curl -X POST "http://127.0.0.1:8000/predict" \
-H "Content-Type: application/json" \
-d '{"text": "I absolutely loved this movie!"}'
This code shows how to test a sentiment analysis API using cURL. Let's break it down:
1. Components:
- curl -X POST: Specifies that we're making a POST request to the API
- http://127.0.0.1:8000/predict: The endpoint URL (localhost on port 8000)
- -H "Content-Type: application/json": Sets the header to indicate we're sending JSON data
- -d '{"text": "..."}': The actual data payload containing the text to analyze
2. Expected Response:
The API will return a JSON response containing:
- The original input text
- The sentiment classification (POSITIVE in this case)
- A confidence score (0.998, indicating high confidence)
This command can be used to test the API after starting the server with uvicorn, and you can use either cURL or alternative tools like Postman to make these requests.
Response:
{
"text": "I absolutely loved this movie!",
"sentiment": "POSITIVE",
"confidence": 0.998
}
This code shows a JSON response from a sentiment analysis API endpoint. Let's break down its components:
- Text field: "I absolutely loved this movie!" - This is the original input text that was sent to the API for analysis
- Sentiment field: "POSITIVE" - This indicates the model's classification of the sentiment expressed in the text
- Confidence field: 0.998 - This is a very high confidence score (on a scale of 0 to 1) indicating that the model is extremely certain about its positive sentiment classification
Step 5: Run the API
Run the FastAPI server locally:
uvicorn app:app --reload
Test the API using curl
or a tool like Postman:
curl -X POST "http://127.0.0.1:8000/predict" \
-H "Content-Type: application/json" \
-d '{"text": "I absolutely loved this movie!"}'
This code shows how to test a sentiment analysis API using cURL. Let's break it down:
1. Components:
- curl -X POST: Specifies that we're making a POST request to the API
- http://127.0.0.1:8000/predict: The endpoint URL (localhost on port 8000)
- -H "Content-Type: application/json": Sets the header to indicate we're sending JSON data
- -d '{"text": "..."}': The actual data payload containing the text to analyze
2. Expected Response:
The API will return a JSON response containing:
- The original input text
- The sentiment classification (POSITIVE in this case)
- A confidence score (0.998, indicating high confidence)
This command can be used to test the API after starting the server with uvicorn, and you can use either cURL or alternative tools like Postman to make these requests.
Response:
{
"text": "I absolutely loved this movie!",
"sentiment": "POSITIVE",
"confidence": 0.998
}
This code shows a JSON response from a sentiment analysis API endpoint. Let's break down its components:
- Text field: "I absolutely loved this movie!" - This is the original input text that was sent to the API for analysis
- Sentiment field: "POSITIVE" - This indicates the model's classification of the sentiment expressed in the text
- Confidence field: 0.998 - This is a very high confidence score (on a scale of 0 to 1) indicating that the model is extremely certain about its positive sentiment classification
Step 5: Run the API
Run the FastAPI server locally:
uvicorn app:app --reload
Test the API using curl
or a tool like Postman:
curl -X POST "http://127.0.0.1:8000/predict" \
-H "Content-Type: application/json" \
-d '{"text": "I absolutely loved this movie!"}'
This code shows how to test a sentiment analysis API using cURL. Let's break it down:
1. Components:
- curl -X POST: Specifies that we're making a POST request to the API
- http://127.0.0.1:8000/predict: The endpoint URL (localhost on port 8000)
- -H "Content-Type: application/json": Sets the header to indicate we're sending JSON data
- -d '{"text": "..."}': The actual data payload containing the text to analyze
2. Expected Response:
The API will return a JSON response containing:
- The original input text
- The sentiment classification (POSITIVE in this case)
- A confidence score (0.998, indicating high confidence)
This command can be used to test the API after starting the server with uvicorn, and you can use either cURL or alternative tools like Postman to make these requests.
Response:
{
"text": "I absolutely loved this movie!",
"sentiment": "POSITIVE",
"confidence": 0.998
}
This code shows a JSON response from a sentiment analysis API endpoint. Let's break down its components:
- Text field: "I absolutely loved this movie!" - This is the original input text that was sent to the API for analysis
- Sentiment field: "POSITIVE" - This indicates the model's classification of the sentiment expressed in the text
- Confidence field: 0.998 - This is a very high confidence score (on a scale of 0 to 1) indicating that the model is extremely certain about its positive sentiment classification
Step 5: Run the API
Run the FastAPI server locally:
uvicorn app:app --reload
Test the API using curl
or a tool like Postman:
curl -X POST "http://127.0.0.1:8000/predict" \
-H "Content-Type: application/json" \
-d '{"text": "I absolutely loved this movie!"}'
This code shows how to test a sentiment analysis API using cURL. Let's break it down:
1. Components:
- curl -X POST: Specifies that we're making a POST request to the API
- http://127.0.0.1:8000/predict: The endpoint URL (localhost on port 8000)
- -H "Content-Type: application/json": Sets the header to indicate we're sending JSON data
- -d '{"text": "..."}': The actual data payload containing the text to analyze
2. Expected Response:
The API will return a JSON response containing:
- The original input text
- The sentiment classification (POSITIVE in this case)
- A confidence score (0.998, indicating high confidence)
This command can be used to test the API after starting the server with uvicorn, and you can use either cURL or alternative tools like Postman to make these requests.
Response:
{
"text": "I absolutely loved this movie!",
"sentiment": "POSITIVE",
"confidence": 0.998
}
This code shows a JSON response from a sentiment analysis API endpoint. Let's break down its components:
- Text field: "I absolutely loved this movie!" - This is the original input text that was sent to the API for analysis
- Sentiment field: "POSITIVE" - This indicates the model's classification of the sentiment expressed in the text
- Confidence field: 0.998 - This is a very high confidence score (on a scale of 0 to 1) indicating that the model is extremely certain about its positive sentiment classification