File size: 3,264 Bytes
486eff6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Demo: API-Based Crossword Clue Generation
Shows the completed multiple model comparison system working.
"""

import sys
import os
import time
from pathlib import Path

# Add hack directory to path for imports
sys.path.insert(0, str(Path(__file__).parent))

from api_clue_generator import APIClueGenerator

def demo_api_models():
    """Demo the completed API-based clue generation system."""
    
    print("🎯 Demo: API-Based Crossword Clue Generation")
    print("=" * 60)
    print("Using Hugging Face Router API with working approach from clue_with_hf.py")
    
    # Initialize generator
    generator = APIClueGenerator()
    
    if not generator.hf_token:
        print("❌ Error: HF_TOKEN environment variable not set")
        return
    
    print(f"βœ… Token configured: {bool(generator.hf_token)}")
    print(f"πŸ€– Available models: {list(generator.models.keys())}")
    
    # Demo test cases
    demo_cases = [
        ("ELEPHANT", "animals"),
        ("GUITAR", "music"),
        ("BASKETBALL", "sports"),
        ("COMPUTER", "technology"),
    ]
    
    print(f"\nπŸ§ͺ Testing {len(demo_cases)} word-topic combinations")
    print("=" * 60)
    
    for i, (word, topic) in enumerate(demo_cases, 1):
        print(f"\nπŸ“ Demo {i}/{len(demo_cases)}: '{word}' + '{topic}'")
        print("-" * 40)
        
        try:
            start_time = time.time()
            results = generator.generate_clue(word, topic)
            elapsed = time.time() - start_time
            
            print(f"⏱️  Generated in {elapsed:.1f}s")
            
            # Show results with quality evaluation
            for model_key, clue in results.items():
                if clue:
                    quality, score = generator.evaluate_clue_quality(word, clue)
                    
                    # Simple quality indicators
                    if quality == "EXCELLENT":
                        icon = "πŸ†"
                    elif quality == "GOOD":
                        icon = "βœ…"
                    elif quality == "ACCEPTABLE":
                        icon = "πŸ”„"
                    else:
                        icon = "❌"
                    
                    print(f"  {icon} {model_key:15} | {quality:10} | {clue}")
                else:
                    print(f"  ❌ {model_key:15} | FAILED     | No response")
        
        except Exception as e:
            print(f"❌ Error: {e}")
    
    print(f"\n" + "=" * 60)
    print("βœ… DEMO COMPLETE")
    print("=" * 60)
    print("πŸŽ‰ Successfully implemented API-based crossword clue generation!")
    print("πŸ’‘ Key features:")
    print("   β€’ Uses HF Router API with chat completions format")
    print("   β€’ Tests multiple models (DeepSeek-V3, Llama-3.3-70B)")
    print("   β€’ Evaluates clue quality automatically")
    print("   β€’ No local model downloads required")
    print("\nπŸ“ Available tools:")
    print("   β€’ api_clue_generator.py - Core API generator")
    print("   β€’ test_multiple_models.py - Comprehensive model comparison")
    print("   β€’ interactive_clue_tester.py - Interactive testing (for manual use)")
    print("   β€’ This demo script")


if __name__ == "__main__":
    demo_api_models()