Spaces:
Sleeping
Sleeping
| import os | |
| import sys | |
| import requests | |
| import json | |
| IMAGE_FILENAME = "test_image.jpg" | |
| URL = "http://localhost:8000/generate-catalog" | |
| def main(): | |
| if not os.path.exists(IMAGE_FILENAME): | |
| print(f"β {IMAGE_FILENAME} not found.") | |
| sys.exit(1) | |
| print(f"Uploading {IMAGE_FILENAME} to {URL}...") | |
| try: | |
| with open(IMAGE_FILENAME, "rb") as f: | |
| files = {"file": (IMAGE_FILENAME, f, "image/jpeg")} | |
| response = requests.post(URL, files=files) | |
| if response.status_code == 200: | |
| print("\nβ Catalog Generated!") | |
| data = response.json() | |
| if "error" in data: | |
| print(f"β Error reported by API: {data['error']}") | |
| if "details" in data: | |
| print(f"Details: {data['details']}") | |
| else: | |
| print(json.dumps(data, indent=2)) | |
| else: | |
| print("\nβ HTTP Error:") | |
| print(f"Status: {response.status_code}") | |
| print(response.text) | |
| except Exception as e: | |
| print(f"\nβ Unexpected error: {e}") | |
| if __name__ == "__main__": | |
| main() | |