Spaces:
Sleeping
Sleeping
Initial commit
Browse files- XceptionFarmInsectClassifier.h5 +3 -0
- app.py +77 -0
- requirements.txt +4 -0
XceptionFarmInsectClassifier.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4dbf4f32167d4943fc80a867875382c4bf5c8f9e601867ff515bccb61b6857bf
|
| 3 |
+
size 92213432
|
app.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Sınıf isimleri - sizin veri setinize göre
|
| 7 |
+
CLASS_NAMES = [
|
| 8 |
+
"Africanized Honey Bees (Killer Bees)",
|
| 9 |
+
"Aphids",
|
| 10 |
+
"Armyworms",
|
| 11 |
+
"Brown Marmorated Stink Bugs",
|
| 12 |
+
"Cabbage Loopers",
|
| 13 |
+
"Citrus Canker",
|
| 14 |
+
"Colorado Potato Beetles",
|
| 15 |
+
"Corn Borers",
|
| 16 |
+
"Corn Earworms",
|
| 17 |
+
"Fall Armyworms",
|
| 18 |
+
"Fruit Flies",
|
| 19 |
+
"Spider Mites",
|
| 20 |
+
"Thrips",
|
| 21 |
+
"Tomato Hornworms",
|
| 22 |
+
"Western Corn Rootworms"
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
# Model yükleme
|
| 26 |
+
model = tf.keras.models.load_model("XceptionFarmInsectClassifier.h5")
|
| 27 |
+
|
| 28 |
+
def predict_insect(image):
|
| 29 |
+
"""
|
| 30 |
+
Yüklenen görüntüyü işler ve böcek sınıfını tahmin eder.
|
| 31 |
+
|
| 32 |
+
Args:
|
| 33 |
+
image: PIL Image veya numpy array
|
| 34 |
+
|
| 35 |
+
Returns:
|
| 36 |
+
dict: Sınıf olasılıkları
|
| 37 |
+
"""
|
| 38 |
+
# Görüntüyü işle
|
| 39 |
+
if isinstance(image, np.ndarray):
|
| 40 |
+
img = Image.fromarray(image.astype('uint8'))
|
| 41 |
+
else:
|
| 42 |
+
img = image
|
| 43 |
+
|
| 44 |
+
# Boyutlandır
|
| 45 |
+
img = img.resize((224, 224))
|
| 46 |
+
img_array = np.array(img)
|
| 47 |
+
|
| 48 |
+
# Normalize et
|
| 49 |
+
img_array = img_array / 255.0
|
| 50 |
+
|
| 51 |
+
# Batch dimension ekle
|
| 52 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 53 |
+
|
| 54 |
+
# Tahmin yap
|
| 55 |
+
predictions = model.predict(img_array, verbose=0)
|
| 56 |
+
|
| 57 |
+
# Sonuçları dictionary'e çevir
|
| 58 |
+
results = {CLASS_NAMES[i]: float(predictions[0][i]) for i in range(len(CLASS_NAMES))}
|
| 59 |
+
|
| 60 |
+
return results
|
| 61 |
+
|
| 62 |
+
# Gradio arayüzü oluştur
|
| 63 |
+
iface = gr.Interface(
|
| 64 |
+
fn=predict_insect,
|
| 65 |
+
inputs=gr.Image(type="pil", label="Böcek Fotoğrafı Yükleyin"),
|
| 66 |
+
outputs=gr.Label(num_top_classes=5, label="Tahmin Sonuçları"),
|
| 67 |
+
title="🐛 Farm Insect Classifier API",
|
| 68 |
+
description="Zararlı böcekleri tespit eden AI modeli. Bir böcek fotoğrafı yükleyin.",
|
| 69 |
+
examples=[
|
| 70 |
+
# Örnek görüntü yolları ekleyebilirsiniz
|
| 71 |
+
],
|
| 72 |
+
allow_flagging="never"
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
# API olarak çalıştır
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
iface.launch(share=False, server_name="0.0.0.0", server_port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.10.0
|
| 2 |
+
tensorflow==2.15.0
|
| 3 |
+
pillow==10.1.0
|
| 4 |
+
numpy==1.24.3
|