File size: 1,516 Bytes
b36d0b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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 功能正常工作!")