Spaces:
Sleeping
Sleeping
| import os | |
| import sys | |
| from dotenv import load_dotenv | |
| # Load variables from .env file | |
| load_dotenv() | |
| # Import the describe_change function | |
| from describe import describe_change | |
| def main(): | |
| # Allow specifying filenames as command line arguments or use defaults | |
| img1 = sys.argv[1] if len(sys.argv) > 1 else "../uploads/img1.jpg" | |
| img2 = sys.argv[2] if len(sys.argv) > 2 else "../uploads/img2.jpg" | |
| print(f"Testing describe_change with:") | |
| print(f" Before image: {img1}") | |
| print(f" After image: {img2}") | |
| # Check if files exist | |
| if not os.path.exists(img1): | |
| print(f"Error: Before image '{img1}' does not exist.") | |
| print("Please place test images or pass paths: python test_describe.py path/to/before.jpg path/to/after.jpg") | |
| return | |
| if not os.path.exists(img2): | |
| print(f"Error: After image '{img2}' does not exist.") | |
| print("Please place test images or pass paths: python test_describe.py path/to/before.jpg path/to/after.jpg") | |
| return | |
| # Check for API key or local setup | |
| groq_api_key = os.environ.get("GROQ_API_KEY") | |
| if groq_api_key: | |
| print(f"Using Groq API for generation (Key starts with: {groq_api_key[:10]}...)") | |
| else: | |
| print("Using local Ollama fallback (GROQ_API_KEY not set).") | |
| # Sample metrics detector hint | |
| metrics = { | |
| "added": 1, | |
| "removed": 0 | |
| } | |
| print("\nGenerating description...") | |
| try: | |
| desc = describe_change(img1, img2, metrics) | |
| print("\n--- Result ---") | |
| if desc: | |
| print(desc) | |
| else: | |
| print("Failed to generate description (returned None).") | |
| print("--------------") | |
| except Exception as e: | |
| print(f"Error running description: {e}") | |
| if __name__ == "__main__": | |
| main() | |