Download test_sentiment.py from moiz9009/AI: direct link, hf CLI and curl.
- Browser
- Download file 984 Bytes
-
https://huggingface.co/spaces/moiz9009/AI/resolve/main/test_sentiment.py
- Command line
-
hf download hf://spaces/moiz9009/AI/test_sentiment.py
-
curl -L -o test_sentiment.py https://huggingface.co/spaces/moiz9009/AI/resolve/main/test_sentiment.py
984 Bytes
| import sys | |
| import os | |
| # Add current directory to path to import sentiment_app | |
| sys.path.append(os.getcwd()) | |
| try: | |
| from sentiment_app import SentimentAnalyzer | |
| except ImportError: | |
| # If running from a different directory, might need to adjust path | |
| print("Could not import sentiment_app. Make sure you are in the correct directory.") | |
| sys.exit(1) | |
| def test_model(): | |
| print("Testing SentimentAnalyzer...") | |
| analyzer = SentimentAnalyzer() | |
| if analyzer.classifier is None: | |
| print("FATAL: Classifier failed to load.") | |
| return | |
| print("Classifier loaded. Testing prediction...") | |
| text = "I love this library!" | |
| result = analyzer.analyze(text) | |
| print(f"Prediction result for '{text}':") | |
| print(result) | |
| if result['sentiment'] == 'Error': | |
| print("FATAL: Prediction returned Error.") | |
| else: | |
| print("SUCCESS: Prediction worked.") | |
| if __name__ == "__main__": | |
| test_model() | |