Spaces:
Sleeping
Sleeping
File size: 1,800 Bytes
3ba5b62 | 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 | 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()
|