Spaces:
Running
Running
File size: 5,868 Bytes
fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b fdc8d37 ac5bf8b a74c089 ac5bf8b |
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
"""
Test script for Event Tags Generator API
"""
import requests
import json
# API endpoint
BASE_URL = "http://localhost:8001"
def test_generate_tags():
"""Test single event tag generation"""
print("=" * 60)
print("Testing Event Tags Generator")
print("=" * 60)
# Test data
event_data = {
"event_name": "Vietnam Music Festival 2025",
"category": "Âm nhạc",
"short_description": "Lễ hội âm nhạc quốc tế lớn nhất Việt Nam năm 2025",
"detailed_description": """
Vietnam Music Festival 2025 là sự kiện âm nhạc đỉnh cao quy tụ các nghệ sĩ
nổi tiếng trong nước và quốc tế. Sự kiện diễn ra trong 3 ngày với hơn 50
nghệ sĩ tham gia, từ nhạc pop, rock, EDM đến acoustic. Đặc biệt có sự góp
mặt của các DJ hàng đầu thế giới. Không gian festival rộng 10,000m2 tại
trung tâm Hà Nội với hệ thống âm thanh ánh sáng hiện đại. Dự kiến thu hút
hơn 30,000 khán giả mỗi ngày.
""",
"max_tags": 12,
"language": "vi"
}
print("\n📤 REQUEST:")
print(json.dumps(event_data, indent=2, ensure_ascii=False))
try:
# Call API
response = requests.post(
f"{BASE_URL}/generate-tags",
json=event_data,
headers={"Content-Type": "application/json"}
)
if response.status_code == 200:
result = response.json()
print("\n✅ SUCCESS!")
print("\n📥 RESPONSE:")
print(json.dumps(result, indent=2, ensure_ascii=False))
print("\n" + "=" * 60)
print("GENERATED METADATA:")
print("=" * 60)
print(f"\n🏷️ TAGS ({len(result['generated_tags'])} tags):")
for tag in result['generated_tags']:
print(f" • {tag}")
print(f"\n📁 PRIMARY CATEGORY: {result['primary_category']}")
if result['secondary_categories']:
print(f"\n📂 SECONDARY CATEGORIES:")
for cat in result['secondary_categories']:
print(f" • {cat}")
if result['keywords']:
print(f"\n🔍 SEO KEYWORDS:")
for kw in result['keywords']:
print(f" • {kw}")
if result['hashtags']:
print(f"\n#️⃣ HASHTAGS:")
for ht in result['hashtags']:
print(f" • {ht}")
if result['target_audience']:
print(f"\n👥 TARGET AUDIENCE:")
for aud in result['target_audience']:
print(f" • {aud}")
print(f"\n😊 SENTIMENT: {result['sentiment']}")
print(f"💯 CONFIDENCE: {result['confidence_score']}")
print(f"⏱️ GENERATION TIME: {result['generation_time']}")
print(f"🤖 MODEL USED: {result['model_used']}")
else:
print(f"\n❌ ERROR: {response.status_code}")
print(response.text)
except requests.exceptions.ConnectionError:
print("\n❌ ERROR: Cannot connect to API")
print("Make sure the server is running: python event_tags_generator.py")
except Exception as e:
print(f"\n❌ ERROR: {str(e)}")
def test_batch_generation():
"""Test batch event tag generation"""
print("\n\n" + "=" * 60)
print("Testing Batch Tag Generation")
print("=" * 60)
events = [
{
"event_name": "Tech Summit Vietnam 2025",
"category": "Công nghệ",
"short_description": "Hội nghị công nghệ lớn nhất Đông Nam Á",
"detailed_description": "Sự kiện quy tụ các chuyên gia AI, Blockchain, Cloud Computing từ Google, Microsoft, Amazon...",
"max_tags": 10,
"language": "vi"
},
{
"event_name": "Food Festival Saigon",
"category": "Ẩm thực",
"short_description": "Lễ hội ẩm thực đường phố Sài Gòn",
"detailed_description": "Khám phá hơn 100 món ăn đường phố đặc trưng của Sài Gòn với các đầu bếp nổi tiếng...",
"max_tags": 8,
"language": "vi"
}
]
print(f"\n📤 Generating tags for {len(events)} events...")
try:
response = requests.post(
f"{BASE_URL}/generate-tags/batch",
json=events,
headers={"Content-Type": "application/json"}
)
if response.status_code == 200:
result = response.json()
print(f"\n✅ Batch completed!")
print(f" Total: {result['total']}")
print(f" Successful: {result['successful']}")
print(f" Failed: {result['failed']}")
for item in result['results']:
if item['success']:
print(f"\n✓ {item['event_name']}")
print(f" Tags: {', '.join(item['data']['generated_tags'][:5])}...")
else:
print(f"\n✗ {item['event_name']}")
print(f" Error: {item['error']}")
else:
print(f"\n❌ ERROR: {response.status_code}")
print(response.text)
except Exception as e:
print(f"\n❌ ERROR: {str(e)}")
if __name__ == "__main__":
import os
uvicorn.run(
"main:app",
host="0.0.0.0",
port=int(os.environ.get("PORT", 7860)),
reload=False,
log_level="info"
) |