File size: 2,497 Bytes
71cc10e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""

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)}")