|
|
|
""" |
|
Demo: API-Based Crossword Clue Generation |
|
Shows the completed multiple model comparison system working. |
|
""" |
|
|
|
import sys |
|
import os |
|
import time |
|
from pathlib import Path |
|
|
|
|
|
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") |
|
|
|
|
|
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_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") |
|
|
|
|
|
for model_key, clue in results.items(): |
|
if clue: |
|
quality, score = generator.evaluate_clue_quality(word, clue) |
|
|
|
|
|
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() |