Spaces:
Sleeping
Sleeping
| """ | |
| Deployed HF Space API Test Scripti | |
| """ | |
| import requests | |
| # ⚠️ BURAYA KENDI SPACE URL'INI YAZ! | |
| # Ornek: https://alpip-dog-breed-api.hf.space | |
| SPACE_URL = "https://KULLANICI-ADIN-dog-breed-api.hf.space" | |
| API_ENDPOINT = f"{SPACE_URL}/predict_pet" | |
| # Test fotografi | |
| image_path = r"C:\Users\alpip\OneDrive - Istanbul Bilgi Universitesi\Masaüstü\WhatsApp Image 2025-10-24 at 17.57.47.jpeg" | |
| print("=" * 80) | |
| print("DEPLOYED API TEST") | |
| print("=" * 80) | |
| print() | |
| print(f"API Endpoint: {API_ENDPOINT}") | |
| print(f"Test Image: {image_path}") | |
| print() | |
| try: | |
| # Health check once | |
| print("1. Health check yapiliyor...") | |
| response = requests.get(SPACE_URL) | |
| if response.status_code == 200: | |
| print(" ✓ Backend calisiyor!") | |
| else: | |
| print(f" ✗ Backend cevap vermiyor: {response.status_code}") | |
| exit(1) | |
| print() | |
| print("2. Fotograf gonderiliyor...") | |
| # Fotografi gonder | |
| with open(image_path, 'rb') as f: | |
| files = {'image': ('dog.jpg', f, 'image/jpeg')} | |
| response = requests.post(API_ENDPOINT, files=files) | |
| print(f" HTTP Status: {response.status_code}") | |
| print() | |
| if response.status_code == 200: | |
| result = response.json() | |
| print("=" * 80) | |
| print("BASARILI! TAHMINLER:") | |
| print("=" * 80) | |
| for i, pred in enumerate(result['top_5'], 1): | |
| breed = pred['breed'] | |
| confidence = pred['confidence'] * 100 | |
| bar = '#' * int(confidence / 2) | |
| print(f"{i}. {breed:40s} {confidence:6.2f}% {bar}") | |
| print("=" * 80) | |
| print(f"EN IYI TAHMIN: {result['breed']} ({result['confidence']*100:.2f}%)") | |
| print(f"Model: {result['model']}") | |
| print(f"Accuracy: {result['accuracy']}") | |
| print("=" * 80) | |
| print() | |
| print("API HAZIR! Kullanmaya baslayabilirsin!") | |
| print() | |
| print("Frontend'den kullanim:") | |
| print(f" POST {API_ENDPOINT}") | |
| print(" Body: form-data") | |
| print(" Key: 'image' (file)") | |
| else: | |
| print(f"HATA: {response.status_code}") | |
| print(response.text) | |
| except FileNotFoundError: | |
| print(f"Fotograf bulunamadi: {image_path}") | |
| except requests.exceptions.ConnectionError: | |
| print("Backend'e baglanilamadi!") | |
| print("Space'in 'Running' durumunda oldugundan emin ol") | |
| except Exception as e: | |
| print(f"Hata: {str(e)}") | |