Spaces:
Paused
Paused
| #!/usr/bin/env python3 | |
| """ | |
| AI 功能测试脚本 | |
| """ | |
| from transformers import pipeline | |
| import requests | |
| print("🤖 Loading AI model...") | |
| sentiment_analyzer = pipeline( | |
| "sentiment-analysis", | |
| model="distilbert-base-uncased-finetuned-sst-2-english", | |
| device=-1 # CPU | |
| ) | |
| print("✅ AI model loaded!\n") | |
| # 测试 1: 正面内容 | |
| print("=" * 50) | |
| print("测试 1: 正面内容") | |
| print("=" * 50) | |
| positive_text = "This is an amazing and wonderful product! I absolutely love it!" | |
| result = sentiment_analyzer(positive_text)[0] | |
| print(f"文本: {positive_text}") | |
| print(f"情感: {result['label']}") | |
| print(f"置信度: {result['score']:.2f}\n") | |
| # 测试 2: 负面内容 | |
| print("=" * 50) | |
| print("测试 2: 负面内容") | |
| print("=" * 50) | |
| negative_text = "This is terrible and disappointing. I hate it." | |
| result = sentiment_analyzer(negative_text)[0] | |
| print(f"文本: {negative_text}") | |
| print(f"情感: {result['label']}") | |
| print(f"置信度: {result['score']:.2f}\n") | |
| # 测试 3: 真实网页 | |
| print("=" * 50) | |
| print("测试 3: 真实网页 (example.com)") | |
| print("=" * 50) | |
| try: | |
| response = requests.get("https://example.com", timeout=10) | |
| text_sample = response.text[:512] | |
| result = sentiment_analyzer(text_sample)[0] | |
| print(f"网页: https://example.com") | |
| print(f"内容长度: {len(response.text)} 字节") | |
| print(f"AI 情感: {result['label']}") | |
| print(f"AI 置信度: {result['score']:.2f}") | |
| except Exception as e: | |
| print(f"错误: {e}") | |
| print("\n✅ 测试完成!AI 功能正常工作!") | |