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() |