File size: 3,372 Bytes
d55975f
 
 
 
 
 
 
 
 
 
b555b7e
71a7b4c
b555b7e
71cc10e
b555b7e
71cc10e
b555b7e
71cc10e
b555b7e
 
 
 
 
71cc10e
b555b7e
71cc10e
b555b7e
71cc10e
b555b7e
 
 
71cc10e
b555b7e
71cc10e
b555b7e
71cc10e
b555b7e
 
 
 
 
 
 
 
 
 
 
 
71cc10e
 
b555b7e
 
 
 
 
 
 
71cc10e
b555b7e
71cc10e
b555b7e
 
71cc10e
b555b7e
 
 
 
 
 
 
 
 
 
 
71cc10e
b555b7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71cc10e
 
b555b7e
 
71cc10e
 
b555b7e
71cc10e
 
b555b7e
71cc10e
b555b7e
71cc10e
b555b7e
 
 
71cc10e
 
 
b555b7e
71cc10e
b555b7e
71cc10e
b555b7e
 
 
 
71cc10e
b555b7e
71cc10e
b555b7e
 
 
 
71cc10e
b555b7e
71cc10e
b555b7e
 
 
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
---

title: Pet Backend
emoji: 🐶
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
pinned: false
---


# Dog Breed Classification API

Bu Hugging Face Space, **Pavarissy/ConvNextV2-large-DogBreed** modelini kullanarak köpek ırkı sınıflandırması yapan bir FastAPI backend'idir.

## 🚀 Kurulum Adımları

### 1. Hugging Face Space Oluşturma

1. https://huggingface.co/spaces adresine gidin
2. "Create new Space" butonuna tıklayın
3. Space adını girin: `petbackend` (veya istediğiniz bir isim)
4. SDK olarak **"Docker"** veya **"Gradio"** yerine **"Docker"** seçin (FastAPI için)
5. Space'i oluşturun

### 2. Dosyaları Yükleme

Space oluşturulduktan sonra, bu klasördeki dosyaları Space'e yükleyin:

- `app.py` - Ana FastAPI uygulaması
- `requirements.txt` - Python bağımlılıkları
- `Dockerfile` - Docker yapılandırması (aşağıda)

### 3. Dockerfile Oluşturma

Space'inize bir `Dockerfile` eklemeniz gerekiyor:

```dockerfile

FROM python:3.9



WORKDIR /code



COPY ./requirements.txt /code/requirements.txt



RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt



COPY ./app.py /code/



CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]

```

### 4. Alternatif: Gradio SDK Kullanımı

Eğer Docker yerine Gradio SDK kullanmak isterseniz:

1. Space oluştururken SDK olarak "Gradio" seçin
2. Sadece `app.py` ve `requirements.txt` dosyalarını yükleyin
3. Hugging Face otomatik olarak FastAPI'yi çalıştıracaktır

## 📡 API Endpoints

### GET /
Ana endpoint - API durumunu gösterir

```bash

curl https://alpingo23-petbackend.hf.space/

```

### POST /predict_pet

Köpek ırkı tahmini yapar



```bash

curl -X POST https://alpingo23-petbackend.hf.space/predict_pet \
  -F "image=@dog_image.jpg"

```



**Response Format:**

```json

{

  "predicted_label": "n02085620-Chihuahua",
  "confidence": 0.95,
  "detection": {
    "box": {

      "x": 50.0,

      "y": 50.0,

      "width": 400.0,

      "height": 400.0

    }

  },

  "imageDimensions": {

    "width": 500,

    "height": 500

  }

}

```


### GET /health
Sağlık kontrolü endpoint'i

```bash

curl https://alpingo23-petbackend.hf.space/health

```

## 🔧 React Native Entegrasyonu

App.js dosyanızda zaten doğru endpoint'i kullanıyorsunuz:

```javascript

const res = await axios.post('https://alpingo23-petbackend.hf.space/predict_pet', formData, {

  headers: { 'Content-Type': 'multipart/form-data' },

});

```

## 🐛 Hata Ayıklama

Space çalışmıyorsa:

1. **Logs kontrolü**: Space sayfasında "Logs" sekmesini kontrol edin
2. **Build durumu**: "Building" durumunda mı kontrol edin
3. **Model yükleme**: İlk açılışta model indirilir, 2-3 dakika sürebilir
4. **API testi**: `/health` endpoint'ini test edin

## 📝 Notlar

- Model ilk yüklendiğinde indirme yapacağı için 2-3 dakika sürebilir
- CORS tüm kaynaklardan gelen isteklere açık (production'da düzeltilmeli)
- Detection box simülasyondur, gerçek nesne tespiti yapmaz
- Model 120+ köpek ırkını tanıyabilir

## 🔗 Bağlantılar

- Model: https://huggingface.co/Pavarissy/ConvNextV2-large-DogBreed
- Space URL: https://alpingo23-petbackend.hf.space
- Docs: https://alpingo23-petbackend.hf.space/docs (otomatik FastAPI docs)