Spaces:
Runtime error
Runtime error
Download test.py from AliXaidi/Emotion_Classifier: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/spaces/AliXaidi/Emotion_Classifier/resolve/main/test.py
- Command line
-
hf download hf://spaces/AliXaidi/Emotion_Classifier/test.py
-
curl -L -o test.py https://huggingface.co/spaces/AliXaidi/Emotion_Classifier/resolve/main/test.py
2.04 kB
| from fastapi.testclient import TestClient | |
| from main import app | |
| client = TestClient(app) | |
| def test_positive_sentiment(): | |
| response = client.post("/predict", json={"text": "I love this product! It's amazing."}) | |
| assert response.status_code == 200 | |
| assert response.json() == {"sentiment": "joy"} # Positive sentiment corresponds to joy | |
| def test_negative_sentiment(): | |
| response = client.post("/predict", json={"text": "This product is terrible. I regret buying it."}) | |
| assert response.status_code == 200 | |
| assert response.json() == {"sentiment": "anger"} # Negative sentiment corresponds to anger | |
| def test_neutral_sentiment(): | |
| response = client.post("/predict", json={"text": "This product is okay. It meets my expectations."}) | |
| assert response.status_code == 200 | |
| assert response.json() == {"sentiment": "neutral"} # Neutral sentiment remains unchanged | |
| def test_anger_sentiment(): | |
| response = client.post("/predict", json={"text": "This product makes me furious!"}) | |
| assert response.status_code == 200 | |
| assert response.json() == {"sentiment": "anger"} # Emotion of anger | |
| def test_disgust_sentiment(): | |
| response = client.post("/predict", json={"text": "I find this product revolting."}) | |
| assert response.status_code == 200 | |
| assert response.json() == {"sentiment": "disgust"} # Emotion of disgust | |
| def test_fear_sentiment(): | |
| response = client.post("/predict", json={"text": "This product scares me."}) | |
| assert response.status_code == 200 | |
| assert response.json() == {"sentiment": "fear"} # Emotion of fear | |
| def test_sadness_sentiment(): | |
| response = client.post("/predict", json={"text": "This product makes me really sad."}) | |
| assert response.status_code == 200 | |
| assert response.json() == {"sentiment": "sadness"} # Emotion of sadness | |
| def test_surprise_sentiment(): | |
| response = client.post("/predict", json={"text": "I'm amazed by this product!"}) | |
| assert response.status_code == 200 | |
| assert response.json() == {"sentiment": "surprise"} # Emotion of surprise | |